/ /ネストされたboost :: assign:list_ofがVisual Studio 2012で壊れている-オーバーロードされた関数のあいまいな呼び出し-c ++、boost、visual-studio-2012

入れ子になったboost :: assign:Visual Studio 2012で壊れたlist_of - オーバーロードされた関数へのあいまいな呼び出し - C ++、boost、visual-studio-2012

これはVisual Studio 2010で機能しますが、2012 Update 2(Boost 1.5.3を使用)では機能しません。

vector<vector<BYTE>> data = assign::list_of (assign::list_of (0x06)(0x02));

コンパイラーによって提供されたエラー(更新済み):

C:Program Files (x86)Microsoft Visual Studio 11.0VCincludexmemory0(617): error C2668: "std::vector<_Ty>::vector" : ambiguous call to overloaded function
with
[
_Ty=BYTE
]
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludevector(786): could be "std::vector<_Ty>::vector(std::vector<_Ty> &&)"
with
[
_Ty=BYTE
]
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludevector(693): or       "std::vector<_Ty>::vector(unsigned __int64)"
with
[
_Ty=BYTE
]
while trying to match the argument list "(boost::assign_detail::generic_list<T>)"
with
[
T=int
]
... (dozens of more lines)

このエラーを回避する方法はありますか?

回答:

回答№1は1

問題は埋め込みによるものではなく、list_ofを使用した一時的な値の作成によるものだと思います。それはうまくいくはずです:

vector<BYTE> temp = assign::list_of (0x06)(0x02);
vector<vector<Byte> > data = assign::list_of(temp);

回答№2の場合は0

私はVC11を持っていないので、単なる推測です...おそらくVC11はあなたの整数を BYTE そして、move-constructorが使用されるか、 size_t など std::vector(size_t) コンストラクターが使用されます。

に変換してみてください BYTE 暗黙的な変換を避けるために自分で:

vector<vector<BYTE>> data = assign::list_of (assign::list_of (static_cast<BYTE>(0x06))(static_cast<BYTE>(0x02)));

回答№3の場合は0

テンプレートパラメータを少しブースト:: assign :: list_ofする必要があります。

// C2668:
std::vector<std::vector<int>> foo1 =
boost::assign::list_of(boost::assign::list_of(0)(1));

// no C2668:
std::vector<std::vector<int>> foo2 =
boost::assign::list_of<std::vector<int>>(boost::assign::list_of(0)(1));