From: khizmax Date: Sat, 16 Apr 2016 16:00:17 +0000 (+0300) Subject: Fixed emplace(), added static_assert( key_type must be default constructible ) X-Git-Tag: v2.2.0~273 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=commitdiff_plain;h=a6d1f283698c7e5f56728c26222ba05f27070cd6 Fixed emplace(), added static_assert( key_type must be default constructible ) --- diff --git a/cds/container/ellen_bintree_map_rcu.h b/cds/container/ellen_bintree_map_rcu.h index e1e7c70c..b38ca200 100644 --- a/cds/container/ellen_bintree_map_rcu.h +++ b/cds/container/ellen_bintree_map_rcu.h @@ -103,6 +103,8 @@ namespace cds { namespace container { typedef std::pair< key_type const, mapped_type > value_type; ///< Key-value pair stored in leaf node of the mp typedef Traits traits; ///< Traits template parameter + static_assert( std::is_default_constructible::value, "Key should be default constructible type" ); + # ifdef CDS_DOXYGEN_INVOKED typedef implementation_defined key_comparator ; ///< key compare functor based on \p Traits::compare and \p Traits::less # else @@ -241,7 +243,7 @@ namespace cds { namespace container { template bool emplace( K&& key, Args&&... args ) { - scoped_node_ptr pNode( cxx_leaf_node_allocator().New( std::forward(key), std::forward(args)... )); + scoped_node_ptr pNode( cxx_leaf_node_allocator().MoveNew( key_type( std::forward(key)), mapped_type( std::forward(args)... ))); if ( base_class::insert( *pNode )) { pNode.release(); return true; diff --git a/cds/container/impl/ellen_bintree_map.h b/cds/container/impl/ellen_bintree_map.h index d2931f71..1abde902 100644 --- a/cds/container/impl/ellen_bintree_map.h +++ b/cds/container/impl/ellen_bintree_map.h @@ -69,7 +69,7 @@ namespace cds { namespace container { Template arguments : - \p GC - safe memory reclamation (i.e. light-weight garbage collector) type, like \p cds::gc::HP, \p cds::gc::DHP - - \p Key - key type + - \p Key - key type. Should be default-constructible - \p T - value type to be stored in tree's leaf nodes. - \p Traits - map traits, default is \p ellen_bintree::traits It is possible to declare option-based tree with \p ellen_bintree::make_map_traits metafunction @@ -110,6 +110,8 @@ namespace cds { namespace container { typedef std::pair< key_type const, mapped_type > value_type ; ///< Key-value pair stored in leaf node of the mp typedef Traits traits; ///< Map traits + static_assert( std::is_default_constructible::value, "Key should be default constructible type"); + # ifdef CDS_DOXYGEN_INVOKED typedef implementation_defined key_comparator; ///< key compare functor based on \p Traits::compare and \p Traits::less # else @@ -234,7 +236,7 @@ namespace cds { namespace container { template bool emplace( K&& key, Args&&... args ) { - scoped_node_ptr pNode( cxx_leaf_node_allocator().New( std::forward(key), std::forward(args)... )); + scoped_node_ptr pNode( cxx_leaf_node_allocator().MoveNew( key_type( std::forward(key)), mapped_type( std::forward(args)... ))); if ( base_class::insert( *pNode )) { pNode.release(); return true;