Using Boost, I am trying to emplace()
a key/value pair into a boost::container::map
. The value needs multiple arguments for the constructor. From what I've been able to find, I need to use piecewise_construct
and pass the constructor args in tuples
. This works with std::map<K,V>
, but I can't get it to work using boost::container::map<K,V>
The closest Boost doc I can find shows boost::unordered_multimap<K,V>
, but not a plain map<K,V>
.
#include <map>
#include <boost/tuple/tuple.hpp>
#include <boost/container/map.hpp>
#include <boost/unordered_set.hpp>
class A {
public:
/**/ A( int ) { }
bool operator<( const A & ) const { return false; }
} ;
class B {
public:
/**/ B( int, const char * ) { }
} ;
int
main( int, char ** )
{
A a( 100 );
B b( 200, "foo" );
std::map<A,B> mgood;
mgood.emplace( std::piecewise_construct,
std::make_tuple( 100 ),
std::make_tuple( 200, "Hello" ) );
#if 1
boost::container::map<A,B> mbad;
mbad.emplace( boost::unordered::piecewise_construct,
boost::make_tuple( 300 ),
boost::make_tuple( 400, "World" ) );
#endif
}
The g++-4.9.2 error messages are impenetrable (to me, anyway):
make -k tst g++ -DBOOST_LOG_DYN_LINK -g -std=c++11 -c -o tst.o tst.cc In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp: In instantiation of âstatic void boost::container::allocator_traits::priv_construct(boost::move_detail::false_type, Allocator&, T*, Args&& ...) [with T = boost::container::container_detail::pair; Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Allocator = boost::container::new_allocator, void*, (boost::container::tree_type_enum)0u, true> >; boost::move_detail::false_type = boost::move_detail::integral_constant]â: /usr/local/include/boost/container/allocator_traits.hpp:353:86:
required from âstatic void boost::container::allocator_traits::construct(Allocator&, T*, Args&& ...) [with T = boost::container::container_detail::pair; Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Allocator = boost::container::new_allocator, void*, (boost::container::tree_type_enum)0u, true> >]â /usr/local/include/boost/container/detail/node_alloc_holder.hpp:167:81: required from âboost::container::container_detail::node_alloc_holder::NodePtr boost::container::container_detail::node_alloc_holder::create_node(Args&& ...) [with Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Allocator = boost::container::new_allocator >; ICont = boost::intrusive::rbtree_impl, void*, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, void, boost::container::value_to_node_compare, void*, (boost::container::tree_type_enum)0u, true>, boost::intrusive::tree_value_compare, std::less, boost::container::container_detail::select1st >, long unsigned int, true, void>; boost::container::container_detail::node_alloc_holder::NodePtr = boost::container::container_detail::tree_node, void*, (boost::container::tree_type_enum)0u, true>]â /usr/local/include/boost/container/detail/tree.hpp:922:94: required from âstd::pair, Options:: tree_type, Options:: optimize_size>::type::iterator, false>, bool> boost::container::container_detail::tree::emplace_unique(Args&& ...) [with Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Key = A; T = std::pair; KeyOfValue = boost::container::container_detail::select1st >; Compare = std::less; Allocator = boost::container::new_allocator >; Options = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; typename boost::container::container_detail::intrusive_tree_type, Options:: tree_type, Options:: optimize_size>::type::iterator = boost::intrusive::tree_iterator, void*, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>]â /usr/local/include/boost/container/map.hpp:665:72:
required from âstd::pair, boost::container::container_detail::select1st >, Compare, Allocator, MapOptions>::iterator, bool> boost::container::map::emplace(Args&& ...) [with Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Key = A; T = B; Compare = std::less; Allocator = boost::container::new_allocator >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; typename boost::container::container_detail::tree, boost::container::container_detail::select1st >, Compare, Allocator, MapOptions>::iterator = boost::container::container_detail::iterator_from_iiterator, void*, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>]â tst.cc:90:53: required from here /usr/local/include/boost/container/allocator_traits.hpp:408:10: error: no matching function for call to âboost::container::container_detail::pair::pair(const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple)â { ::new((void)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: candidates are: In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:146:4: note: template boost::container::container_detail::pair::pair(std::pair<_U1, _U2>&&) pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) ^ /usr/local/include/boost/container/detail/pair.hpp:146:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: types âstd::pair<_T1, _T2>â and âconst boost::unordered::piecewise_construct_tâ have incompatible cv-qualifiers { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:141:4: note: boost::container::container_detail::pair::pair(std::pair<_T1, _T2>&&) [with T1 = A; T2 = B] pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) ^ /usr/local/include/boost/container/detail/pair.hpp:141:4: note: candidate expects 1 argument, 3 provided /usr/local/include/boost/container/detail/pair.hpp:137:4: note: template boost::container::container_detail::pair::pair(const std::pair<_U1, _U2>&) pair(const std::pair& p) ^ /usr/local/include/boost/container/detail/pair.hpp:137:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: âconst boost::unordered::piecewise_construct_tâ is not derived from âconst std::pair<_T1, _T2>â { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:132:4: note: boost::container::container_detail::pair::pair(const std::pair<_T1, _T2>&) [with T1 = A; T2 = B] pair(const std::pair& x) ^ /usr/local/include/boost/container/detail/pair.hpp:132:4: note: candidate expects 1 argument, 3 provided /usr/local/include/boost/container/detail/pair.hpp:126:4: note: template boost::container::container_detail::pair::pair(U&&, V&&) pair(BOOST_FWD_REF(U) u, BOOST_FWD_REF(V) v) ^ /usr/local/include/boost/container/detail/pair.hpp:126:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: candidate expects 2 arguments, 3 provided { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:120:4: note: boost::container::container_detail::pair::pair(const T1&, const T2&) [with T1 = A; T2 = B] pair(const T1 &t1, const T2 &t2) ^ /usr/local/include/boost/container/detail/pair.hpp:120:4: note: candidate expects 2 arguments, 3 provided /usr/local/include/boost/container/detail/pair.hpp:115:4: note: template boost::container::container_detail::pair::pair(boost::container::container_detail::pair&&) pair(BOOST_RV_REF_BEG pair BOOST_RV_REF_END p) ^ /usr/local/include/boost/container/detail/pair.hpp:115:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: types âboost::container::container_detail::pairâ and âconst boost::unordered::piecewise_construct_tâ have incompatible cv-qualifiers { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:110:4: note: template boost::container::container_detail::pair::pair(const boost::container::container_detail::pair&) pair(const pair &p) ^ /usr/local/include/boost/container/detail/pair.hpp:110:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: âconst boost::unordered::piecewise_construct_tâ is not derived from âconst boost::container::container_detail::pairâ { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:105:4: note: boost::container::container_detail::pair::pair(boost::container::container_detail::pair&&) [with T1 = A; T2 = B] pair(BOOST_RV_REF(pair) p) ^ /usr/local/include/boost/container/detail/pair.hpp:105:4: note: candidate expects 1 argument, 3 provided /usr/local/include/boost/container/detail/pair.hpp:100:4: note: boost::container::container_detail::pair::pair(const boost::container::container_detail::pair&) [with T1 = A; T2 = B] pair(const pair& x) ^ /usr/local/include/boost/container/detail/pair.hpp:100:4: note: candidate expects 1 argument, 3 provided /usr/local/include/boost/container/detail/pair.hpp:95:4: note: boost::container::container_detail::pair::pair() [with T1 = A; T2 = B] pair() ^ /usr/local/include/boost/container/detail/pair.hpp:95:4: note: candidate expects 0 arguments, 3 provided : recipe for target 'tst.o' failed make: *** [tst.o] Error 1 make: Target 'tst' not remade because of errors.Compilation exited abnormally with code 2 at Sat Apr 2 17:11:28
Can you point me in a useful direction? (I'd prefer not to mix boost
and std
containers; it should be possible to emplace
into a boost::container::map
, right?)
Aucun commentaire:
Enregistrer un commentaire