与VS2010中的list_of进行模糊调用

tt2*_*293 2 c++ boost compiler-errors visual-c++

我正在尝试将一个projet从VS2008转换为2010但由于添加了移动构造函数(并且可能存在嵌套的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);
}
Run Code Online (Sandbox Code Playgroud)

这导致

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 ]
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题,同时仍然使用boost :: list_of?或者我是否必须切换到另一个初始化机制?

Eri*_*ler 7

这看起来像是Boost.Assign中的一个错误.返回类型list_of具有通用的转换类型,T而不会尝试约束T.因此,无论是std::vector构造函数 - 采用a std::vector &&还是采用a的构造函数 - 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>()))
Run Code Online (Sandbox Code Playgroud)