@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
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
@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
@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
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
@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
@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
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 )
protected:
//@cond
- bool insert_node( value_type * pData )
+ bool insert_node( value_type* pData )
{
return insert_node_at( head(), pData );
}
}
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();
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 )