Replace cds::ref/boost::ref with std::ref, remove cds::unref and cds/ref.h header
[libcds.git] / cds / container / michael_kvlist_nogc.h
index e814a3b76f89f4f9344aaa023a503df5797362e8..b098279a52b79dfaacc1e425fda82884fb7831e6 100644 (file)
@@ -3,11 +3,11 @@
 #ifndef __CDS_CONTAINER_MICHAEL_KVLIST_NOGC_H
 #define __CDS_CONTAINER_MICHAEL_KVLIST_NOGC_H
 
-#include <cds/container/michael_list_base.h>
+#include <memory>
+#include <cds/container/details/michael_list_base.h>
 #include <cds/intrusive/michael_list_nogc.h>
 #include <cds/container/details/make_michael_kvlist.h>
 #include <cds/details/functor_wrapper.h>
-#include <cds/details/std/memory.h>
 
 namespace cds { namespace container {
 
@@ -93,41 +93,6 @@ namespace cds { namespace container {
         typedef typename base_class::atomic_node_ptr head_type;
         //@endcond
 
-    private:
-        //@cond
-#   ifndef CDS_CXX11_LAMBDA_SUPPORT
-        struct ensure_functor
-        {
-            node_type * m_pItemFound;
-
-            ensure_functor()
-                : m_pItemFound( null_ptr<node_type *>() )
-            {}
-
-            void operator ()(bool, node_type& item, node_type& )
-            {
-                m_pItemFound = &item;
-            }
-        };
-
-        template <typename Func>
-        class find_functor: protected cds::details::functor_wrapper<Func>
-        {
-            typedef cds::details::functor_wrapper<Func> base_class;
-        public:
-            find_functor( Func f )
-                : base_class(f)
-            {}
-
-            template <typename Q>
-            void operator ()( node_type& node, Q&  )
-            {
-                base_class::get()( node.m_Data );
-            }
-        };
-#   endif
-        //@endcond
-
     protected:
         //@cond
         template <typename K>
@@ -142,13 +107,11 @@ namespace cds { namespace container {
             return cxx_allocator().New( key, val );
         }
 
-#ifdef CDS_EMPLACE_SUPPORT
         template <typename K, typename... Args>
         static node_type * alloc_node( K&& key, Args&&... args )
         {
             return cxx_allocator().MoveNew( std::forward<K>(key), std::forward<Args>(args)... );
         }
-#endif
 
         static void free_node( node_type * pNode )
         {
@@ -214,21 +177,21 @@ namespace cds { namespace container {
             key_type const& key() const
             {
                 typename iterator_base::value_ptr p = iterator_base::operator ->();
-                assert( p != null_ptr<typename iterator_base::value_ptr>() );
+                assert( p != nullptr );
                 return p->m_Data.first;
             }
 
             value_ref val() const
             {
                 typename iterator_base::value_ptr p = iterator_base::operator ->();
-                assert( p != null_ptr<typename iterator_base::value_ptr>() );
+                assert( p != nullptr );
                 return p->m_Data.second;
             }
 
             pair_ptr operator ->() const
             {
                 typename iterator_base::value_ptr p = iterator_base::operator ->();
-                return p ? &(p->m_Data) : null_ptr<pair_ptr>();
+                return p ? &(p->m_Data) : nullptr;
             }
 
             pair_ref operator *() const
@@ -296,7 +259,7 @@ namespace cds { namespace container {
         /// Returns an iterator that addresses the location succeeding the last element in a list
         /**
             Do not use the value returned by <tt>end</tt> function to access any item.
-            Internally, <tt>end</tt> returning value equals to <tt>NULL</tt>.
+            Internally, <tt>end</tt> returning value equals to \p nullptr.
 
             The returned value can be used only to control reaching the end of the list.
             For empty list \code begin() == end() \endcode
@@ -407,7 +370,7 @@ namespace cds { namespace container {
             to the list's item inserted. <tt>item.second</tt> is a reference to item's value that may be changed.
             User-defined functor \p func should guarantee that during changing item's value no any other changes
             could be made on this list's item by concurrent threads.
-            The user-defined functor can be passed by reference using <tt>boost::ref</tt>
+            The user-defined functor can be passed by reference using \p std::ref
             and it is called only if the inserting is successful.
 
             The key_type should be constructible from value of type \p K.
@@ -444,20 +407,15 @@ namespace cds { namespace container {
             return std::make_pair( node_to_iterator( ret.first ), ret.second );
         }
 
-#   ifdef CDS_EMPLACE_SUPPORT
         /// Inserts data of type \ref mapped_type constructed with <tt>std::forward<Args>(args)...</tt>
         /**
             Returns an iterator pointed to inserted value, or \p end() if inserting is failed
-
-            This function is available only for compiler that supports
-            variadic template and move semantics
         */
         template <typename K, typename... Args>
         iterator emplace( K&& key, Args&&... args )
         {
             return node_to_iterator( emplace_at( head(), std::forward<K>(key), std::forward<Args>(args)... ));
         }
-#   endif
 
         /// Find the key \p key
         /** \anchor cds_nonintrusive_MichaelKVList_nogc_find
@@ -517,11 +475,11 @@ namespace cds { namespace container {
         //@cond
         node_type * insert_node_at( head_type& refHead, node_type * pNode )
         {
-            assert( pNode != null_ptr<node_type *>() );
+            assert( pNode != nullptr );
             scoped_node_ptr p( pNode );
             if ( base_class::insert_at( refHead, *pNode ))
                 return p.release();
-            return null_ptr<node_type *>();
+            return nullptr;
         }
 
         template <typename K>
@@ -542,39 +500,31 @@ namespace cds { namespace container {
             scoped_node_ptr pNode( alloc_node( key ));
 
             if ( base_class::insert_at( refHead, *pNode )) {
-                cds::unref(f)( pNode->m_Data );
+                f( pNode->m_Data );
                 return pNode.release();
             }
-            return null_ptr<node_type *>();
+            return nullptr;
         }
 
         template <typename K>
         std::pair< node_type *, bool > ensure_at( head_type& refHead, const K& key )
         {
             scoped_node_ptr pNode( alloc_node( key ));
-            node_type * pItemFound = null_ptr<node_type *>();
+            node_type * pItemFound = nullptr;
 
-#       ifdef CDS_CXX11_LAMBDA_SUPPORT
             std::pair<bool, bool> ret = base_class::ensure_at( refHead, *pNode, [&pItemFound](bool, node_type& item, node_type&){ pItemFound = &item; });
-#       else
-            ensure_functor func;
-            std::pair<bool, bool> ret = base_class::ensure_at( refHead, *pNode, boost::ref(func) );
-            pItemFound = func.m_pItemFound;
-#       endif
-            assert( pItemFound != null_ptr<node_type *>() );
+            assert( pItemFound != nullptr );
 
             if ( ret.first && ret.second )
                 pNode.release();
             return std::make_pair( pItemFound, ret.second );
         }
 
-#   ifdef CDS_EMPLACE_SUPPORT
         template <typename K, typename... Args>
         node_type * emplace_at( head_type& refHead, K&& key, Args&&... args )
         {
             return insert_node_at( refHead, alloc_node( std::forward<K>(key), std::forward<Args>(args)... ));
         }
-#endif
 
         template <typename K, typename Compare>
         node_type * find_at( head_type& refHead, K const& key, Compare cmp )
@@ -586,12 +536,7 @@ namespace cds { namespace container {
         template <typename K, typename Compare typename Func>
         bool find_at( head_type& refHead, K& key, Compare cmp, Func f )
         {
-#       ifdef CDS_CXX11_LAMBDA_SUPPORT
-            return base_class::find_at( refHead, key, cmp, [&f]( node_type& node, K const& ){ cds::unref(f)( node.m_Data ); });
-#       else
-            find_functor<Func>  wrapper( f );
-            return base_class::find_at( refHead, key, cmp, cds::ref(wrapper) );
-#       endif
+            return base_class::find_at( refHead, key, cmp, [&f]( node_type& node, K const& ){ f( node.m_Data ); });
         }
         */
         //@endcond