Fixed -Wshadow warnings
[libcds.git] / cds / container / michael_list_nogc.h
index c6bd1fd1d74252bc11b2df78951210d9b10d432a..747d58db6c06e9ea67b6328f043c5b423546f4db 100644 (file)
@@ -1,11 +1,11 @@
 /*
     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/
-    
+
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are met:
 
@@ -25,7 +25,7 @@
     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #ifndef CDSLIB_CONTAINER_MICHAEL_LIST_NOGC_H
@@ -98,6 +98,23 @@ namespace cds { namespace container {
         typedef typename base_class::item_counter item_counter;   ///< Item counting policy used
         typedef typename maker::key_comparator    key_comparator; ///< key comparison functor
         typedef typename base_class::memory_model memory_model;   ///< Memory ordering. See cds::opt::memory_model option
+        typedef typename base_class::stat         stat;           ///< Internal statistics
+
+        //@cond
+        // Rebind traits (split-list support)
+        template <typename... Options>
+        struct rebind_traits {
+            typedef MichaelList<
+                gc
+                , value_type
+                , typename cds::opt::make_options< traits, Options...>::type
+            > type;
+        };
+
+        // Stat selector
+        template <typename Stat>
+        using select_stat_wrapper = typename base_class::template select_stat_wrapper< Stat >;
+        //@endcond
 
     protected:
         //@cond
@@ -107,30 +124,6 @@ namespace cds { namespace container {
         typedef typename maker::intrusive_traits::compare  intrusive_key_comparator;
 
         typedef typename base_class::atomic_node_ptr head_type;
-        //@endcond
-
-    protected:
-        //@cond
-        static node_type * alloc_node()
-        {
-            return cxx_allocator().New();
-        }
-
-        static node_type * alloc_node( value_type const& v )
-        {
-            return cxx_allocator().New( v );
-        }
-
-        template <typename... Args>
-        static node_type * alloc_node( Args&&... args )
-        {
-            return cxx_allocator().MoveNew( std::forward<Args>(args)... );
-        }
-
-        static void free_node( node_type * pNode )
-        {
-            cxx_allocator().Delete( pNode );
-        }
 
         struct node_disposer {
             void operator()( node_type * pNode )
@@ -138,17 +131,8 @@ namespace cds { namespace container {
                 free_node( pNode );
             }
         };
-        typedef std::unique_ptr< node_type, node_disposer >     scoped_node_ptr;
 
-        head_type& head()
-        {
-            return base_class::m_pHead;
-        }
-
-        head_type const& head() const
-        {
-            return base_class::m_pHead;
-        }
+        typedef std::unique_ptr< node_type, node_disposer >     scoped_node_ptr;
         //@endcond
 
     protected:
@@ -242,7 +226,7 @@ namespace cds { namespace container {
         */
         iterator begin()
         {
-            return iterator( head() );
+            return iterator( head());
         }
 
         /// Returns an iterator that addresses the location succeeding the last element in a list
@@ -261,13 +245,13 @@ namespace cds { namespace container {
         /// Returns a forward const iterator addressing the first element in a list
         const_iterator begin() const
         {
-            return const_iterator( head() );
+            return const_iterator( head());
         }
 
         /// Returns a forward const iterator addressing the first element in a list
         const_iterator cbegin() const
         {
-            return const_iterator( head() );
+            return const_iterator( head());
         }
 
         /// Returns an const iterator that addresses the location succeeding the last element in a list
@@ -283,16 +267,6 @@ namespace cds { namespace container {
         }
     //@}
 
-    protected:
-        //@cond
-        iterator node_to_iterator( node_type * pNode )
-        {
-            if ( pNode )
-                return iterator( *pNode );
-            return end();
-        }
-        //@endcond
-
     public:
         /// Default constructor
         /**
@@ -301,7 +275,14 @@ namespace cds { namespace container {
         MichaelList()
         {}
 
-        /// List desctructor
+        //@cond
+        template <typename Stat, typename = std::enable_if<std::is_same<stat, michael_list::wrapped_stat<Stat>>::value >>
+        explicit MichaelList( Stat& st )
+            : base_class( st )
+        {}
+        //@endcond
+
+        /// List destructor
         /**
             Clears the list
         */
@@ -318,9 +299,9 @@ namespace cds { namespace container {
             Return an iterator pointing to inserted item if success \ref end() otherwise
         */
         template <typename Q>
-        iterator insert( const Q& val )
+        iterator insert( Q&& val )
         {
-            return node_to_iterator( insert_at( head(), val ) );
+            return node_to_iterator( insert_at( head(), std::forward<Q>( val )));
         }
 
         /// Updates the item
@@ -334,9 +315,9 @@ namespace cds { namespace container {
             already is in the list.
         */
         template <typename Q>
-        std::pair<iterator, bool> update( const Q& key, bool bAllowInsert = true )
+        std::pair<iterator, bool> update( Q&& key, bool bAllowInsert = true )
         {
-            std::pair< node_type *, bool > ret = update_at( head(), key, bAllowInsert );
+            std::pair< node_type *, bool > ret = update_at( head(), std::forward<Q>( key ), bAllowInsert );
             return std::make_pair( node_to_iterator( ret.first ), ret.second );
         }
         //@cond
@@ -367,7 +348,7 @@ namespace cds { namespace container {
         template <typename Q>
         iterator contains( Q const& key )
         {
-            return node_to_iterator( find_at( head(), key, intrusive_key_comparator() ));
+            return node_to_iterator( find_at( head(), key, intrusive_key_comparator()));
         }
         //@cond
         template <typename Q>
@@ -388,7 +369,7 @@ namespace cds { namespace container {
         iterator contains( Q const& key, Less pred )
         {
             CDS_UNUSED( pred );
-            return node_to_iterator( find_at( head(), key, typename maker::template less_wrapper<Less>::type() ) );
+            return node_to_iterator( find_at( head(), key, typename maker::template less_wrapper<Less>::type()));
         }
         //@cond
         template <typename Q, typename Less>
@@ -418,6 +399,12 @@ namespace cds { namespace container {
             return base_class::size();
         }
 
+        /// Returns const reference to internal statistics
+        stat const& statistics() const
+        {
+            return base_class::statistics();
+        }
+
         /// Clears the list
         void clear()
         {
@@ -426,6 +413,54 @@ namespace cds { namespace container {
 
     protected:
         //@cond
+        static value_type& node_to_value( node_type& n )
+        {
+            return n.m_Value;
+        }
+
+        static node_type * alloc_node()
+        {
+            return cxx_allocator().New();
+        }
+
+        static node_type * alloc_node( value_type const& v )
+        {
+            return cxx_allocator().New( v );
+        }
+
+        template <typename... Args>
+        static node_type * alloc_node( Args&&... args )
+        {
+            return cxx_allocator().MoveNew( std::forward<Args>( args )... );
+        }
+
+        static void free_node( node_type * pNode )
+        {
+            cxx_allocator().Delete( pNode );
+        }
+
+        head_type& head()
+        {
+            return base_class::m_pHead;
+        }
+
+        head_type const& head() const
+        {
+            return base_class::m_pHead;
+        }
+
+        iterator node_to_iterator( node_type * pNode )
+        {
+            if ( pNode )
+                return iterator( *pNode );
+            return end();
+        }
+
+        iterator insert_node( node_type * pNode )
+        {
+            return node_to_iterator( insert_node_at( head(), pNode ));
+        }
+
         node_type * insert_node_at( head_type& refHead, node_type * pNode )
         {
             assert( pNode != nullptr );
@@ -437,15 +472,15 @@ namespace cds { namespace container {
         }
 
         template <typename Q>
-        node_type * insert_at( head_type& refHead, const Q& val )
+        node_type * insert_at( head_type& refHead, Q&& val )
         {
-            return insert_node_at( refHead, alloc_node( val ));
+            return insert_node_at( refHead, alloc_node( std::forward<Q>( val )));
         }
 
         template <typename Q>
-        std::pair< node_type *, bool > update_at( head_type& refHead, const Q& val, bool bAllowInsert )
+        std::pair< node_type *, bool > update_at( head_type& refHead, Q&& val, bool bAllowInsert )
         {
-            scoped_node_ptr pNode( alloc_node( val ));
+            scoped_node_ptr pNode( alloc_node( std::forward<Q>( val )));
             node_type * pItemFound = nullptr;
 
             std::pair<bool, bool> ret = base_class::update_at( refHead, *pNode,
@@ -468,7 +503,6 @@ namespace cds { namespace container {
         {
             return base_class::find_at( refHead, key, cmp );
         }
-
         //@endcond
     };
 }} // namespace cds::container