Ambiguous call with list_of in VS2010

I am trying to convert a project from VS2008 to 2010, but the delete problem is due to the added move constructors (and probably the fact that there is a nested list here). The following code fragment shows an error (in the actual code, these constructs are used to initialize some static):

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); } 

that leads to

 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 ] 

Is there a way to solve this problem when using boost :: list_of? Or do I need to switch to a different initialization mechanism?

+2
source share
1 answer

This seems like a bug in Boost.Assign. The return type list_of has a generic type conversion T , without trying to limit T at all. Therefore, the std::vector constructor is one that accepts a std::vector && and one that accepts unsigned int is equally good, which leads to ambiguity.

The work for you will be to use convert_to_container , as shown below:

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

Source: https://habr.com/ru/post/943611/


All Articles