/*
This file is a part of libcds - Concurrent Data Structures library
- (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+ (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
Source code repo: http://github.com/khizmax/libcds/
Download: http://sourceforge.net/projects/libcds/files/
Returns \p true if \p val is inserted into the set, \p false otherwise.
*/
template <typename Q>
- bool insert( Q const& val )
+ bool insert( Q&& val )
{
- return insert_node( alloc_node( val ));
+ return insert_node( alloc_node( std::forward<Q>( val )));
}
/// Inserts new node
synchronization.
*/
template <typename Q, typename Func>
- bool insert( Q const& val, Func f )
+ bool insert( Q&& val, Func f )
{
- scoped_node_ptr pNode( alloc_node( val ));
+ scoped_node_ptr pNode( alloc_node( std::forward<Q>( val )));
if ( base_class::insert( *pNode, [&f](node_type& node) { f( node.m_Value ) ; } )) {
pNode.release();
#endif
upsert( Q&& val, bool bAllowInsert = true )
{
- scoped_node_ptr pNode( alloc_node( val ) );
+ scoped_node_ptr pNode( alloc_node( std::forward<Q>( val )));
auto bRet = base_class::upsert( *pNode, bAllowInsert );
std::pair<bool, bool>
>::type
#endif
- update( Q const& val, Func func, bool bAllowInsert = true )
+ update( Q&& val, Func func, bool bAllowInsert = true )
{
- scoped_node_ptr pNode( alloc_node( val ));
+ scoped_node_ptr pNode( alloc_node( std::forward<Q>( val )));
auto bRet = base_class::update( *pNode,
[&func, &val]( bool bNew, node_type& item, node_type const& /*val*/ ) {
std::is_same<Q, Q>::value && is_iterable_list<ordered_list>::value,
std::pair<bool, bool>
>::type
- update( Q const& val, Func func, bool bAllowInsert = true )
+ update( Q&& val, Func func, bool bAllowInsert = true )
{
- scoped_node_ptr pNode( alloc_node( val ) );
+ scoped_node_ptr pNode( alloc_node( std::forward<Q>( val )));
auto bRet = base_class::update( *pNode,
[&func]( node_type& item, node_type* old ) {
[&f](node_type& node) { f( node.m_Value ); } );
}
+ /// Deletes the item pointed by iterator \p iter (only for \p IterableList based set)
+ /**
+ Returns \p true if the operation is successful, \p false otherwise.
+ The function can return \p false if the node the iterator points to has already been deleted
+ by other thread.
+
+ The function does not invalidate the iterator, it remains valid and can be used for further traversing.
+
+ @note \p %erase_at() is supported only for \p %SplitListSet based on \p IterableList.
+ */
+#ifdef CDS_DOXYGEN_INVOKED
+ bool erase_at( iterator const& iter )
+#else
+ template <typename Iterator>
+ typename std::enable_if< std::is_same<Iterator, iterator>::value && is_iterable_list< ordered_list >::value, bool >::type
+ erase_at( Iterator const& iter )
+#endif
+ {
+ return base_class::erase_at( static_cast<iterator::iterator_base_class const&>( iter ));
+ }
+
+
/// Extracts the item with specified \p key
/** \anchor cds_nonintrusive_SplitListSet_hp_extract
The function searches an item with key equal to \p key,
using base_class::extract_;
using base_class::get_;
- template <typename Q>
- static node_type * alloc_node( Q const& v )
- {
- return cxx_node_allocator().New( v );
- }
-
template <typename... Args>
static node_type * alloc_node( Args&&... args )
{
typename std::enable_if< std::is_same<Q,Q>::value && is_iterable_list< ordered_list >::value, iterator>::type
find_iterator_( Q& val )
{
- return iterator( base_class::find( val ) );
+ return iterator( base_class::find( val ));
}
template <typename Q, typename Less, typename Func>
find_iterator_with_( Q& val, Less pred )
{
CDS_UNUSED( pred );
- return iterator( base_class::find_with( val, typename maker::template predicate_wrapper<Less>::type() ));
+ return iterator( base_class::find_with( val, typename maker::template predicate_wrapper<Less>::type()));
}
struct node_disposer {
assert( pNode != nullptr );
scoped_node_ptr p( pNode );
- if ( base_class::insert( *pNode ) ) {
+ if ( base_class::insert( *pNode )) {
p.release();
return true;
}