c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -
this code:
std::vector<int>(boost::assign::list_of<int>(1)(2)(3));
gives error:
main.cpp: in member function 'void <unnamed>::requesthandler::processrequest(foo&, bar, unsigned int, unsigned int*, const char*, boost::shared_ptr<baz::ioutput>&)': main.cpp:450: error: call of overloaded 'vector(boost::assign_detail::generic_list<int>&)' ambiguous /4.4.2/bits/stl_vector.h:241: note: candidates are: std::vector<_tp, _alloc>::vector(const std::vector<_tp, _alloc>&) [with _tp = int, _alloc = std::allocator<int>] /4.4.2/bits/stl_vector.h:227: note: std::vector<_tp, _alloc>::vector(size_t, const _tp&, const _alloc&) [with _tp = int, _alloc = std::allocator<int>] /4.4.2/bits/stl_vector.h:215: note: std::vector<_tp, _alloc>::vector(const _alloc&) [with _tp = int, _alloc = std::allocator<int>]
when compiled gcc 4.4.2.
how can revolve issue? i'm trying compile following:
using namespace std; using namespace boost::assign; typedef boost::variant<vector<bool>, vector<int>, vector<string> > container; vector<pair<string, container > > v = list_of(pair<string, container >("scotland",container(vector<int>(list_of<int>(1)(2)(3))))) (pair<string, container >("sweden",container()));
this fails same reason.
my application involves setting data structures purposes of unit testing. want initialization clear rather having lots of push_backs etc.
update:
here fix:
std::vector<std::pair<std::string, container > > v = boost::assign::list_of(std::pair<std::string, container >("scotland",container(boost::assign::list_of(1)(2)(3).convert_to_container<std::vector<int> >()))) (std::pair<std::string, container >("sweden",container()));
this ugly. might make clearer. unit tests written in header files don't use using namespace
.
this dupe of ambiguous call list_of in vs2010. boost.assign written targeting c++03 standard library. things changed in c++11 , boost.assign hasn't been updated. bug report here.