Typedef rejected when disambiguating a call to boost::assign

I am trying to initialise a std::map of std::set using boost::assign, as follows: typedef std::set< uint32_t > the_set_t; typedef std::map< uint32_t, the_set_t > the_map_t; the_map_t data = boost::assign::map_list_of< uint32_t, the_set_t > > // bad line ( 1, boost::assign::list_of(10)(20)(30) ) Unfortunately this is rejected by GCC 4.4.6, and results in a large amount of errors, (attached below). The problem is caused by the use of the typedef the_set_t. If the typedef is replaced with std::set<uint32_t> the code compiles and works correctly. the_map_t data = boost::assign::map_list_of< uint32_t, std::set< uint32_t > > The error produced is as follows: map-assign.cpp:19: error: conversion from ‘bool’ to non-scalar type ‘the_map_t’ requested In file included from /opt/boost_1_51_0/boost/assign/list_of.hpp:397, from map-assign.cpp:7: /opt/boost_1_51_0/boost/preprocessor/iteration/detail/local.hpp: In member function ‘boost::assign_detail::generic_list<T>& boost::assign_detail::generic_list<T>::operator() (const U&, const U0&) [with U = int, U0 = boost::assign_detail::generic_list<int>, T = int]’: map-assign.cpp:17: instantiated from here /opt/boost_1_51_0/boost/preprocessor/iteration/detail/local.hpp:37: error: functional cast expression list treated as compound expression In file included from /opt/boost_1_51_0/boost/iterator/iterator_categories.hpp:15, from /opt/boost_1_51_0/boost/iterator/detail/facade_iterator_category.hpp:7, from /opt/boost_1_51_0/boost/iterator/iterator_facade.hpp:14, from /opt/boost_1_51_0/boost/range/iterator_range_core.hpp:23, from /opt/boost_1_51_0/boost/range/iterator_range.hpp:13, from /opt/boost_1_51_0/boost/assign/list_of.hpp:20, from map-assign.cpp:7: /opt/boost_1_51_0/boost/mpl/eval_if.hpp: At global scope: /opt/boost_1_51_0/boost/mpl/eval_if.hpp: In instantiation of ‘boost::mpl::eval_if_c<false, boost::range_const_iterator< boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)>, boost::range_mutable_iterator< boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)> >’: /opt/boost_1_51_0/boost/range/iterator.hpp:63: instantiated from ‘boost::range_iterator< boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)>’ /opt/boost_1_51_0/boost/range/iterator_range_core.hpp:72: instantiated from ‘bool boost::iterator_range_detail::less_than(const Left&, const Right&) [with Left = boost::assign_detail::converter< boost::assign_detail::generic_list<int>, std::_Deque_iterator<int, int&, int*> >, Right = boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)]’ /opt/boost_1_51_0/boost/assign/list_of.hpp:274: instantiated from ‘bool boost::assign_detail::operator<(const boost::assign_detail::converter<T, I>&, const Range&) [with T = boost::assign_detail::generic_list<int>, I = std::_Deque_iterator<int, int&, int*>, Range = boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)]’ /opt/boost_1_51_0/boost/assign/list_of.hpp:292: instantiated from ‘bool boost::assign_detail::operator>(const Range&, const boost::assign_detail::converter<T, I>&) [with T = boost::assign_detail::generic_list<int>, I = std::_Deque_iterator<int, int&, int*>, Range = boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)]’ map-assign.cpp:19: instantiated from here /opt/boost_1_51_0/boost/mpl/eval_if.hpp:60: error: no type named ‘type’ in ‘struct boost::range_mutable_iterator< boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)>’ In file included from /opt/boost_1_51_0/boost/range/iterator_range.hpp:13, from /opt/boost_1_51_0/boost/assign/list_of.hpp:20, from map-assign.cpp:7: /opt/boost_1_51_0/boost/range/iterator_range_core.hpp: In function ‘bool boost::iterator_range_detail::less_than(const Left&, const Right&) [with Left = boost::assign_detail::converter<boost::assign_detail::generic_list<int>, std::_Deque_iterator<int, int&, int*> >, Right = boost::assign_detail::generic_list<std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)]’: /opt/boost_1_51_0/boost/assign/list_of.hpp:274: instantiated from ‘bool boost::assign_detail::operator<(const boost::assign_detail::converter<T, I>&, const Range&) [with T = boost::assign_detail::generic_list<int>, I = std::_Deque_iterator<int, int&, int*>, Range = boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)]’ /opt/boost_1_51_0/boost/assign/list_of.hpp:292: instantiated from ‘bool boost::assign_detail::operator>(const Range&, const boost::assign_detail::converter<T, I>&) [with T = boost::assign_detail::generic_list<int>, I = std::_Deque_iterator<int, int&, int*>, Range = boost::assign_detail::generic_list<std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&)]’ map-assign.cpp:19: instantiated from here /opt/boost_1_51_0/boost/range/iterator_range_core.hpp:72: error: no matching function for call to ‘begin(boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (&) (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&))’ /opt/boost_1_51_0/boost/range/iterator_range_core.hpp:72: error: no matching function for call to ‘end(boost::assign_detail::generic_list< std::pair<unsigned int, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > (&) (const unsigned int&, const std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >&))’ In file included from map-assign.cpp:7: /opt/boost_1_51_0/boost/assign/list_of.hpp: In member function ‘Container boost::assign_detail::converter<DerivedTAssign, Iterator>::convert( const Container*, boost::assign_detail::default_type_tag) const [with Container = int, DerivedTAssign = boost::assign_detail::generic_list<int>, Iterator = std::_Deque_iterator<int, int&, int*>]’: /opt/boost_1_51_0/boost/assign/list_of.hpp:142: instantiated from ‘Container boost::assign_detail::converter<DerivedTAssign, Iterator>::convert_to_container() const [with Container = int, DerivedTAssign = boost::assign_detail::generic_list<int>, Iterator = std::_Deque_iterator<int, int&, int*>]’ /opt/boost_1_51_0/boost/assign/list_of.hpp:436: instantiated from ‘boost::assign_detail::generic_list<T>::operator Container() const [with Container = int, T = int]’ /opt/boost_1_51_0/boost/preprocessor/iteration/detail/local.hpp:37: instantiated from ‘boost::assign_detail::generic_list<T>& boost::assign_detail::generic_list<T>::operator()(const U&, const U0&) [with U = int, U1 = boost::assign_detail::generic_list<int>, T = int]’ map-assign.cpp:17: instantiated from here /opt/boost_1_51_0/boost/assign/list_of.hpp:163: error: functional cast expression list treated as compound expression /opt/boost_1_51_0/boost/assign/list_of.hpp:163: error: invalid cast from type ‘std::_Deque_iterator<int, int&, int*>’ to type ‘int’ What is wrong with using a typedef or is this a known limitation of `boost::assign`? -- View this message in context: http://boost.2283326.n4.nabble.com/Typedef-rejected-when-disambiguating-a-ca... Sent from the Boost - Users mailing list archive at Nabble.com.

On 30-10-2012 09:38, mark pashley wrote:
I am trying to initialise a std::map of std::set using boost::assign, as follows:
typedef std::set< uint32_t > the_set_t; typedef std::map< uint32_t, the_set_t > the_map_t;
the_map_t data = boost::assign::map_list_of< uint32_t, the_set_t > > // bad line ( 1, boost::assign::list_of(10)(20)(30) )
Unfortunately this is rejected by GCC 4.4.6, and results in a large amount of errors, (attached below).
The problem is caused by the use of the typedef the_set_t. If the typedef is replaced with std::set<uint32_t> the code compiles and works correctly.
I don't see how a typedef can change the code. Very wierd. Does it happen with other compilers? -Thorsten

Not had a chance to try it on any other compilers yet ( I haven't got anything else available at work). Here is the entire example if anyone is interested in trying it on another compiler... #include <set> #include <map> #include <algorithm> #include <iterator> #include <boost/assign/list_of.hpp> typedef std::set< unsigned > the_set_t; typedef std::map< unsigned, the_set_t > the_map_t; // switch these lines to get the example to compile..... the_map_t data = boost::assign::map_list_of< uint32_t, the_set_t > > // the_map_t data = boost::assign::map_list_of< unsigned, std::set< unsigned
( 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) ) ;
int main( int, char** ) { the_map_t::const_iterator iter = data.begin(); the_map_t::const_iterator fin = data.end(); for (; iter != fin; ++iter ) { std::cout << "Index: " << iter->first << " { "; std::copy( iter->second.begin(), iter->second.end(), std::ostream_iterator<unsigned>( std::cout, " " ) ); std::cout << "}\n"; } return 0; } -- View this message in context: http://boost.2283326.n4.nabble.com/Typedef-rejected-when-disambiguating-a-ca... Sent from the Boost - Users mailing list archive at Nabble.com.

On 30-10-2012 11:20, mark pashley wrote:
Not had a chance to try it on any other compilers yet ( I haven't got anything else available at work).
Here is the entire example if anyone is interested in trying it on another compiler...
you store unsigned int in your container, but use signed int in list_of. Could that interfere? Could you try to use u suffix on the literals? (or the first literal in each list_of expression, because this is where the type is deduced) -Thorsten

Hi, I don't think the signed / unsignedness of the values is the problem, tried changing the_map_t data = boost::assign::map_list_of< uint32_t, the_set_t > > // bad line ( 1, boost::assign::list_of(10)(20)(30) ) to the_map_t data = boost::assign::map_list_of< uint32_t, the_set_t > > // bad line ( 1, boost::assign::list_of(10U)(20U)(30U) ) but it makes no difference. Regards Mark -- View this message in context: http://boost.2283326.n4.nabble.com/Typedef-rejected-when-disambiguating-a-ca... Sent from the Boost - Users mailing list archive at Nabble.com.

I could compile this with vc 2008 -Thorsten void test() { typedef std::set< unsigned > the_set_t; typedef std::map< unsigned, the_set_t > the_map_t; the_map_t data = boost::assign::map_list_of< unsigned, the_set_t > ( 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) ) ; the_map_t::const_iterator iter = data.begin(); the_map_t::const_iterator fin = data.end(); for (; iter != fin; ++iter ) { std::cout << "Index: " << iter->first << " { "; std::copy( iter->second.begin(), iter->second.end(), std::ostream_iterator<unsigned>( std::cout, " " ) ); std::cout << "}\n"; } return; }
participants (2)
-
mark pashley
-
Thorsten Ottosen