Fixed -Wshadow warnings
[libcds.git] / cds / container / split_list_set.h
index 5f301ed5b6cfe55f3e7f6cbf53b0a0505501cccf..47d48865ea46408e8960f8e389d7e81768950ada 100644 (file)
@@ -1,7 +1,7 @@
 /*
     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/
@@ -389,9 +389,9 @@ namespace cds { namespace container {
             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
@@ -414,9 +414,9 @@ namespace cds { namespace container {
             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();
@@ -450,14 +450,14 @@ namespace cds { namespace container {
 #ifdef CDS_DOXYGEN_INVOKED
         std::pair<bool, bool>
 #else
-        typename std::enable_if< 
+        typename std::enable_if<
             std::is_same< Q, Q>::value && is_iterable_list< ordered_list >::value,
             std::pair<bool, bool>
         >::type
 #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 );
 
@@ -509,14 +509,14 @@ namespace cds { namespace container {
 #ifdef CDS_DOXYGEN_INVOKED
         std::pair<bool, bool>
 #else
-        typename std::enable_if< 
+        typename std::enable_if<
             std::is_same<Q, Q>::value && !is_iterable_list<ordered_list>::value,
             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*/ ) {
@@ -533,9 +533,9 @@ namespace cds { namespace container {
             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 ) {
@@ -626,6 +626,28 @@ namespace cds { namespace container {
                 [&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<typename 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,
@@ -889,17 +911,17 @@ namespace cds { namespace container {
             return base_class::statistics();
         }
 
+        /// Returns internal statistics for \p ordered_list
+        typename ordered_list::stat const& list_statistics() const
+        {
+            return base_class::list_statistics();
+        }
+
     protected:
         //@cond
         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 )
         {
@@ -914,14 +936,14 @@ namespace cds { namespace container {
         template <typename Q, typename Func>
         bool find_( Q& val, Func f )
         {
-            return base_class::find( val, [&f]( node_type& item, Q& val ) { f( item.m_Value, val ); } );
+            return base_class::find( val, [&f]( node_type& item, Q& v ) { f( item.m_Value, v ); } );
         }
 
         template <typename Q>
         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>
@@ -929,7 +951,7 @@ namespace cds { namespace container {
         {
             CDS_UNUSED( pred );
             return base_class::find_with( val, typename maker::template predicate_wrapper<Less>::type(),
-                [&f]( node_type& item, Q& val ) { f( item.m_Value, val ); } );
+                [&f]( node_type& item, Q& v ) { f( item.m_Value, v ); } );
         }
 
         template <typename Q, typename Less>
@@ -937,7 +959,7 @@ namespace cds { namespace container {
         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 {
@@ -953,7 +975,7 @@ namespace cds { namespace container {
             assert( pNode != nullptr );
             scoped_node_ptr p( pNode );
 
-            if ( base_class::insert( *pNode ) ) {
+            if ( base_class::insert( *pNode )) {
                 p.release();
                 return true;
             }