This code:
std::vector<int>(boost::assign::list_of<int>(1)(2)(3));
gives an 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>&)' is 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 compiling for gcc 4.4.2.
How can I solve this problem? Ultimately, I try to compile the 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 happens for the same reason.
My application includes creating data structures for unit testing. I want the initialization to be clear, but to do a lot of push_back, etc.
UPDATE:
Here is the 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 is so ugly. What can I do to make it clearer. My unit tests are written only in the header files, so I do not use using namespace .