2012-10-29 4 views
3

std::set을 포함하는 std::map의 C++ 11 초기화를 에뮬레이트하기 위해 boost::assign을 사용하려고합니다. boost::assign::list_of 작품을 사용 std::setstd :: map 내에서 중첩 된 std :: set으로 boost :: assign을 사용합니다.

#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)); 

초기화는 그 자체로 사용하는 경우 예상하지만 위의 코드를하려고 할 때 할당은 std::set의 생성자가 호출되는 시점에서 모호 같이

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>] 

어떻게이 모호성 오류를 해결할 수 있습니까?

+0

전혀'LIST_OF (10U) (20U) (30U)'도움이됩니까된다? – aschepler

답변

2

이 경우 boost::assign::map_list_of은 두 번째 템플릿 인수 - <uint32_t, std::set< uint32_t> >에 대한 힌트가 필요합니다. 따라서 라인

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

the_map_t data = boost::assign::map_list_of<uint32_t, std::set< uint32_t> >(...); 
+1

작동하는 환호하지만 나는 boost :: assign' 내에 버그를 발견했다고 믿고 있습니다. http://boost.2283326.n4.nabble.com/Typedef-rejected-when-disambiguating-a-call-to-boost -assign-td4637775.html. – mark