From: khizmax Date: Wed, 3 Aug 2016 10:38:15 +0000 (+0300) Subject: Replaced const-reference with rvalue in insert/update functions X-Git-Tag: v2.2.0~152 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=commitdiff_plain;h=457cfb559036dba2d0ae0110e6b6dff2358e4167 Replaced const-reference with rvalue in insert/update functions --- diff --git a/cds/container/impl/iterable_kvlist.h b/cds/container/impl/iterable_kvlist.h index aaad301e..a9f830fc 100644 --- a/cds/container/impl/iterable_kvlist.h +++ b/cds/container/impl/iterable_kvlist.h @@ -249,9 +249,9 @@ namespace cds { namespace container { @note The function is supported only if \ref mapped_type is default constructible */ template - bool insert( K const& key ) + bool insert( K&& key ) { - return base_class::emplace( key, mapped_type()); + return base_class::emplace( std::forward( 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 - 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( key ), std::forward( 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 - 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( 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 - std::pair update( K const& key, Func f, bool bAllowInsert = true ) + std::pair 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( key )), mapped_type()), f, bAllowInsert ); } /// Insert or update diff --git a/cds/container/impl/iterable_list.h b/cds/container/impl/iterable_list.h index e51234ce..cac200e4 100644 --- a/cds/container/impl/iterable_list.h +++ b/cds/container/impl/iterable_list.h @@ -348,9 +348,9 @@ namespace cds { namespace container { Returns \p true if inserting successful, \p false otherwise. */ template - bool insert( Q const& val ) + bool insert( Q&& val ) { - return insert_at( head(), val ); + return insert_at( head(), std::forward( val )); } /// Inserts new node @@ -380,9 +380,9 @@ namespace cds { namespace container { @warning See \ref cds_intrusive_item_creating "insert item troubleshooting" */ template - 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( 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 - std::pair update( Q const& key, Func func, bool bAllowInsert = true ) + std::pair update( Q&& key, Func func, bool bAllowInsert = true ) { - return update_at( head(), key, func, bAllowInsert ); + return update_at( head(), std::forward( key ), func, bAllowInsert ); } /// Insert or update @@ -750,11 +750,11 @@ namespace cds { namespace container { protected: //@cond - template - static value_type* alloc_data( Q const& v ) - { - return cxx_data_allocator().New( v ); - } + //template + //static value_type* alloc_data( Q const& v ) + //{ + // return cxx_data_allocator().New( v ); + //} template 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 - 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( val ))); } template - 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( key ))); if ( base_class::insert_at( refHead, *pNode, f )) { pNode.release(); @@ -820,13 +820,13 @@ namespace cds { namespace container { template bool emplace_at( head_type& refHead, Args&&... args ) { - return insert_node_at( refHead, alloc_data( std::forward(args) ... )); + return insert_node_at( refHead, alloc_data( std::forward(args)... )); } template - std::pair update_at( head_type& refHead, Q const& key, Func f, bool bAllowInsert ) + std::pair 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( key ))); std::pair ret = base_class::update_at( refHead, *pData, f, bAllowInsert ); if ( ret.first )