2012-09-10 34 views
2

我试图将VS2008中的一个projet转换为2010,但由于添加了移动构造函数(可能存在嵌套list_of在这里的事实),因此遇到了问题。下面的代码片段显示错误(在实际的代码,这些结构用于初始化一些静态):在VS2010中使用list_of模糊呼叫

enum some_enum {R, G, B}; 

typedef std::pair<some_enum, some_enum> Enum_Pair; 
typedef std::vector<some_enum> Enum_list; 
typedef std::pair<Enum_Pair, Enum_list> Some_Struct; 
typedef std::list<Some_Struct> Full_Struct; 

#define MAKEFULLSTRUCT(First_, Second_, some_enums)\ 
    (Some_Struct(Enum_Pair(First_, Second_), list_of (some_enums))) 

int main() 
{ 
    int i = G; 
    Full_Struct test_struct = list_of 
     MAKEFULLSTRUCT(R, R, R).to_container(test_struct); 
} 

导致

error C2668: 'std::vector<_Ty>::vector' : ambiguous call to overloaded function 
with [_Ty=some_enum] 
vector(593): could be 'std::vector<_Ty>::vector(std::vector<_Ty> &&)' 
with [ _Ty=some_enum] 
vector(515): or  'std::vector<_Ty>::vector(unsigned int)' 
with [ _Ty=some_enum] 
while trying to match the argument list '(boost::assign_detail::generic_list<T>)' 
with [ T=some_enum ] 

是否有某种方式来解决这个同时仍然使用升压::列表?或者我必须切换到另一个初始化机制?

+0

你用什么版本的提升呢? –

+0

这是使用boost 1.45。 – tt293

回答

7

这看起来像是Boost.Assign中的一个错误。 list_of的返回类型有一个类似T的类型转换,根本不会限制T。因此,std::vector的构造函数 - 需要std::vector &&的构造函数和采用unsigned int的构造函数 - 同样好,导致含糊不清。

为您的工作周围是使用convert_to_container,如下:

#define MAKEFULLSTRUCT(First_, Second_, some_enums)\ 
    (Some_Struct(Enum_Pair(First_, Second_), \ 
     list_of(some_enums).convert_to_container<Enum_list>())) 
+1

P.S.我向你提供这个[这里](https://svn.boost.org/trac/boost/ticket/7364)。 –

+0

谢谢埃里克。您的解决方法非常完美! – tt293