2

プロジェクトを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);
}

これは

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 ]

boost :: list_ofを使用しながらこれを解決する方法はありますか?または、別の初期化メカニズムに切り替える必要がありますか?

4

1 に答える 1

7

これは Boost.Assign のバグのようです。の戻り値の型には、まったく制約を試みることなくlist_of、型への一般的な変換があります。したがって、どちらのコンストラクター (a を受け取るコンストラクターと a を受け取るコンストラクター) も同じように適切であり、あいまいさが生じます。TTstd::vectorstd::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>()))
于 2012-09-11T03:57:14.813 に答える