Replaced const-reference with rvalue in insert/update functions
authorkhizmax <khizmax@gmail.com>
Wed, 3 Aug 2016 10:38:15 +0000 (13:38 +0300)
committerkhizmax <khizmax@gmail.com>
Wed, 3 Aug 2016 10:38:15 +0000 (13:38 +0300)
cds/container/impl/iterable_kvlist.h
cds/container/impl/iterable_list.h

index aaad301e17d8d31f4452f6e109f05252b5878d10..a9f830fcce74fcb37e30dfd04e7e1b9ce98a97e2 100644 (file)
@@ -249,9 +249,9 @@ namespace cds { namespace container {
             @note The function is supported only if \ref mapped_type is default constructible
         */
         template <typename K>
-        bool insert( K const& key )
+        bool insert( K&& key )
         {
-            return base_class::emplace( key, mapped_type());
+            return base_class::emplace( std::forward<K>( key ), mapped_type());
         }
 
         /// Inserts new node with a key and a value
@@ -265,9 +265,9 @@ namespace cds { namespace container {
             Returns \p true if inserting successful, \p false otherwise.
         */
         template <typename K, typename V>
-        bool insert( K const& key, V const& val )
+        bool insert( K&& key, V&& val )
         {
-            return base_class::emplace( key, val );
+            return base_class::emplace( std::forward<K>( key ), std::forward<V>( val ));
         }
 
         /// Inserts new node and initialize it by a functor
@@ -301,9 +301,9 @@ namespace cds { namespace container {
             @note The function is supported only if \ref mapped_type is default constructible
         */
         template <typename K, typename Func>
-        bool insert_with( K const& key, Func func )
+        bool insert_with( K&& key, Func func )
         {
-            return base_class::insert( value_type( key_type( key ), mapped_type()), func );
+            return base_class::insert( value_type( key_type( std::forward<K>( key )), mapped_type()), func );
         }
 
         /// Updates data by \p key
@@ -335,9 +335,9 @@ namespace cds { namespace container {
             @note The function is supported only if \ref mapped_type is default constructible
         */
         template <typename K, typename Func>
-        std::pair<bool, bool> update( K const& key, Func f, bool bAllowInsert = true )
+        std::pair<bool, bool> update( K&& key, Func f, bool bAllowInsert = true )
         {
-            return base_class::update( value_type( key_type( key ), mapped_type()), f, bAllowInsert );
+            return base_class::update( value_type( key_type( std::forward<K>( key )), mapped_type()), f, bAllowInsert );
         }
 
         /// Insert or update
index e51234ceeccaa97f5a5f91fa502203e84daa446c..cac200e407e200ee17d5bcc9b849acbbf9ba9f24 100644 (file)
@@ -348,9 +348,9 @@ namespace cds { namespace container {
             Returns \p true if inserting successful, \p false otherwise.
         */
         template <typename Q>
-        bool insert( Q const& val )
+        bool insert( Q&& val )
         {
-            return insert_at( head(), val );
+            return insert_at( head(), std::forward<Q>( val ));
         }
 
         /// Inserts new node
@@ -380,9 +380,9 @@ namespace cds { namespace container {
             @warning See \ref cds_intrusive_item_creating "insert item troubleshooting"
         */
         template <typename Q, typename Func>
-        bool insert( Q const& key, Func func )
+        bool insert( Q&& key, Func func )
         {
-            return insert_at( head(), key, func );
+            return insert_at( head(), std::forward<Q>( key ), func );
         }
 
         /// Updates data by \p key
@@ -411,9 +411,9 @@ namespace cds { namespace container {
             @warning See \ref cds_intrusive_item_creating "insert item troubleshooting"
         */
         template <typename Q, typename Func>
-        std::pair<bool, bool> update( Q const& key, Func func, bool bAllowInsert = true )
+        std::pair<bool, bool> update( Q&& key, Func func, bool bAllowInsert = true )
         {
-            return update_at( head(), key, func, bAllowInsert );
+            return update_at( head(), std::forward<Q>( key ), func, bAllowInsert );
         }
 
         /// Insert or update
@@ -750,11 +750,11 @@ namespace cds { namespace container {
 
     protected:
         //@cond
-        template <typename Q>
-        static value_type* alloc_data( Q const& v )
-        {
-            return cxx_data_allocator().New( v );
-        }
+        //template <typename Q>
+        //static value_type* alloc_data( Q const& v )
+        //{
+        //    return cxx_data_allocator().New( v );
+        //}
 
         template <typename... Args>
         static value_type* alloc_data( Args&&... args )
@@ -782,7 +782,7 @@ namespace cds { namespace container {
 
     protected:
         //@cond
-        bool insert_node( value_type * pData )
+        bool insert_node( value_type* pData )
         {
             return insert_node_at( head(), pData );
         }
@@ -800,15 +800,15 @@ namespace cds { namespace container {
         }
 
         template <typename Q>
-        bool insert_at( head_type& refHead, Q const& val )
+        bool insert_at( head_type& refHead, Q&& val )
         {
-            return insert_node_at( refHead, alloc_data( val ));
+            return insert_node_at( refHead, alloc_data( std::forward<Q>( val )));
         }
 
         template <typename Q, typename Func>
-        bool insert_at( head_type& refHead, Q const& key, Func f )
+        bool insert_at( head_type& refHead, Q&& key, Func f )
         {
-            scoped_data_ptr pNode( alloc_data( key ));
+            scoped_data_ptr pNode( alloc_data( std::forward<Q>( key )));
 
             if ( base_class::insert_at( refHead, *pNode, f )) {
                 pNode.release();
@@ -820,13 +820,13 @@ namespace cds { namespace container {
         template <typename... Args>
         bool emplace_at( head_type& refHead, Args&&... args )
         {
-            return insert_node_at( refHead, alloc_data( std::forward<Args>(args) ... ));
+            return insert_node_at( refHead, alloc_data( std::forward<Args>(args)... ));
         }
 
         template <typename Q, typename Func>
-        std::pair<bool, bool> update_at( head_type& refHead, Q const& key, Func f, bool bAllowInsert )
+        std::pair<bool, bool> update_at( head_type& refHead, Q&& key, Func f, bool bAllowInsert )
         {
-            scoped_data_ptr pData( alloc_data( key ) );
+            scoped_data_ptr pData( alloc_data( std::forward<Q>( key )));
 
             std::pair<bool, bool> ret = base_class::update_at( refHead, *pData, f, bAllowInsert );
             if ( ret.first )