4

I am trying to use boost::assign to emulate C++11 initialization of a std::map containing a std::set.

#include <set>
#include <map>
#include <stdint.h>

#include <boost/assign/list_of.hpp>

typedef std::map< uint32_t, std::set< uint32_t> > the_map_t;

the_map_t data = boost::assign::map_list_of( 1, boost::assign::list_of(10)(20)(30) )
                                           ( 2, boost::assign::list_of(12)(22)(32) )
                                           ( 3, boost::assign::list_of(13)(23)(33) )
                                           ( 4, boost::assign::list_of(14)(24)(34) );

Initialisation of std::set using boost::assign::list_of works as expected when used on its own, but when I try the above code the assignment is ambiguous at the point where the std::set's constructor is called:

map-assign.cpp:16:   instantiated from here
include/c++/4.4.6/bits/stl_pair.h:101: error: call of overloaded set(const   boost::assign_detail::generic_list<int>&) is ambiguous
include/c++/4.4.6/bits/stl_set.h:188: note: candidates are: 
    std::set<_Key, _Compare, _Alloc>::set(
        const std::set<_Key, _Compare, _Alloc>&) 
        [with _Key = unsigned int, _Compare = std::less<unsigned int>, _Alloc = std::allocator<unsigned int>]

include/c++/4.4.6/bits/stl_set.h:145: note:                 
    std::set<_Key, _Compare, _Alloc>::set(
        const _Compare&, const _Alloc&) 
        [with _Key = unsigned int, _Compare = std::less<unsigned int>, _Alloc = std::allocator<unsigned int>]

How can I resolve this ambiguity error?

1
  • Does list_of(10U)(20U)(30U) help at all? Commented Oct 29, 2012 at 17:55

1 Answer 1

3

In this case boost::assign::map_list_of needs a hint for second template argument - <uint32_t, std::set< uint32_t> >. Therefore line

the_map_t data = boost::assign::map_list_of(...);

becomes

the_map_t data = boost::assign::map_list_of<uint32_t, std::set< uint32_t> >(...);
Sign up to request clarification or add additional context in comments.

1 Comment

cheers that works but I believe have uncovered a bug within boost::assign, see: boost.2283326.n4.nabble.com/….

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.