Fixed emplace(), added static_assert( key_type must be default constructible )
authorkhizmax <libcds.dev@gmail.com>
Sat, 16 Apr 2016 16:00:17 +0000 (19:00 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sat, 16 Apr 2016 16:00:17 +0000 (19:00 +0300)
cds/container/ellen_bintree_map_rcu.h
cds/container/impl/ellen_bintree_map.h

index e1e7c70ce8cd4de4b7ba0dba6db127817e791460..b38ca200799218afa88ef400a4ec9c8e2bbcfe8c 100644 (file)
@@ -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<key_type>::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 <typename K, typename... Args>
         bool emplace( K&& key, Args&&... args )
         {
-            scoped_node_ptr pNode( cxx_leaf_node_allocator().New( std::forward<K>(key), std::forward<Args>(args)... ));
+            scoped_node_ptr pNode( cxx_leaf_node_allocator().MoveNew( key_type( std::forward<K>(key)), mapped_type( std::forward<Args>(args)... )));
             if ( base_class::insert( *pNode )) {
                 pNode.release();
                 return true;
index d2931f71184c33b44f5662b7bd86ddc943605ef8..1abde90205085a628245ee1d3c2e62d3fd4a9a3c 100644 (file)
@@ -69,7 +69,7 @@ namespace cds { namespace container {
 
         <b>Template arguments</b> :
         - \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<key_type>::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 <typename K, typename... Args>
         bool emplace( K&& key, Args&&... args )
         {
-            scoped_node_ptr pNode( cxx_leaf_node_allocator().New( std::forward<K>(key), std::forward<Args>(args)... ));
+            scoped_node_ptr pNode( cxx_leaf_node_allocator().MoveNew( key_type( std::forward<K>(key)), mapped_type( std::forward<Args>(args)... )));
             if ( base_class::insert( *pNode )) {
                 pNode.release();
                 return true;