Remove CDS_CXX11_LAMBDA_SUPPORT macro and a lot of emulating code
[libcds.git] / cds / container / michael_list_rcu.h
index 9a46b0003c127234742c27dddcf917cd6cffec3b..e3b579757fd8660b5b50658b426ddca801a2c9c1 100644 (file)
@@ -131,9 +131,6 @@ namespace cds { namespace container {
         typedef typename options::type_traits::compare  intrusive_key_comparator;
 
         typedef typename base_class::atomic_node_ptr      head_type;
-#   ifndef CDS_CXX11_LAMBDA_SUPPORT
-        typedef typename base_class::empty_erase_functor    empty_erase_functor;
-#   endif
         //@endcond
 
     public:
@@ -149,78 +146,6 @@ namespace cds { namespace container {
         {
             return n.m_Value;
         }
-
-#   ifndef CDS_CXX11_LAMBDA_SUPPORT
-        template <typename Func>
-        struct insert_functor
-        {
-            Func        m_func;
-
-            insert_functor ( Func f )
-                : m_func(f)
-            {}
-
-            void operator()( node_type& node )
-            {
-                cds::unref(m_func)( node_to_value(node) );
-            }
-        };
-
-        template <typename Q, typename Func>
-        struct ensure_functor
-        {
-            Func        m_func;
-            Q const&    m_arg;
-
-            ensure_functor( Q const& arg, Func f )
-                : m_func(f)
-                , m_arg( arg )
-            {}
-
-            void operator ()( bool bNew, node_type& node, node_type& )
-            {
-                cds::unref(m_func)( bNew, node_to_value(node), m_arg );
-            }
-        };
-
-        template <typename Func>
-        struct find_functor
-        {
-            Func    m_func;
-
-            find_functor( Func f )
-                : m_func(f)
-            {}
-
-            template <typename Q>
-            void operator ()( node_type& node, Q& val )
-            {
-                cds::unref(m_func)( node_to_value(node), val );
-            }
-        };
-
-        struct empty_find_functor
-        {
-            template <typename Q>
-            void operator ()( node_type& node, Q& val ) const
-            {}
-        };
-
-        template <typename Func>
-        struct erase_functor
-        {
-            Func        m_func;
-
-            erase_functor( Func f )
-                : m_func(f)
-            {}
-
-            void operator()( node_type const& node )
-            {
-                cds::unref(m_func)( node_to_value(node) );
-            }
-        };
-#endif  // ifndef CDS_CXX11_LAMBDA_SUPPORT
         //@endcond
 
     protected:
@@ -231,13 +156,11 @@ namespace cds { namespace container {
             return cxx_allocator().New( v );
         }
 
-#   ifdef CDS_EMPLACE_SUPPORT
         template <typename... Args>
         static node_type * alloc_node( Args&&... args )
         {
             return cxx_allocator().MoveNew( std::forward<Args>(args)... );
         }
-#   endif
 
         static void free_node( node_type * pNode )
         {
@@ -290,7 +213,7 @@ namespace cds { namespace container {
             value_ptr operator ->() const
             {
                 typename iterator_base::value_ptr p = iterator_base::operator ->();
-                return p ? &(p->m_Value) : reinterpret_cast<value_ptr>(NULL);
+                return p ? &(p->m_Value) : nullptr;
             }
 
             value_ref operator *() const
@@ -337,7 +260,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
@@ -477,22 +400,17 @@ namespace cds { namespace container {
             return ensure_at( head(), key, f );
         }
 
-#   ifdef CDS_EMPLACE_SUPPORT
         /// Inserts data of type \ref value_type constructed with <tt>std::forward<Args>(args)...</tt>
         /**
             Returns \p true if inserting successful, \p false otherwise.
 
             The function makes RCU lock internally.
-
-            @note This function is available only for compiler that supports
-            variadic template and move semantics.
         */
         template <typename... Args>
         bool emplace( Args&&... args )
         {
             return emplace_at( head(), std::forward<Args>(args)... );
         }
-#   endif
 
         /// Deletes \p key from the list
         /** \anchor cds_nonintrusive_MichealList_rcu_erase_val
@@ -508,11 +426,7 @@ namespace cds { namespace container {
         template <typename Q>
         bool erase( Q const& key )
         {
-#       ifdef CDS_CXX11_LAMBDA_SUPPORT
             return erase_at( head(), key, intrusive_key_comparator(),  [](value_type const&){} );
-#       else
-            return erase_at( head(), key, intrusive_key_comparator(), empty_erase_functor() );
-#       endif
         }
 
         /// Deletes the item from the list using \p pred predicate for searching
@@ -525,11 +439,7 @@ namespace cds { namespace container {
         template <typename Q, typename Less>
         bool erase_with( Q const& key, Less pred )
         {
-#       ifdef CDS_CXX11_LAMBDA_SUPPORT
             return erase_at( head(), key, typename options::template less_wrapper<Less>::type(), [](value_type const&){} );
-#       else
-            return erase_at( head(), key, typename options::template less_wrapper<Less>::type(), empty_erase_functor() );
-#       endif
         }
 
         /// Deletes \p key from the list
@@ -748,7 +658,7 @@ namespace cds { namespace container {
         /// Finds the key \p val and return the item found
         /** \anchor cds_nonintrusive_MichaelList_rcu_get
             The function searches the item with key equal to \p val and returns the pointer to item found.
-            If \p val is not found it returns \p NULL.
+            If \p val is not found it returns \p nullptr.
 
             Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type.
 
@@ -825,7 +735,7 @@ namespace cds { namespace container {
         //@cond
         bool insert_node_at( head_type& refHead, node_type * pNode )
         {
-            assert( pNode != NULL );
+            assert( pNode );
             scoped_node_ptr p(pNode);
             if ( base_class::insert_at( refHead, *pNode )) {
                 p.release();
@@ -846,50 +756,23 @@ namespace cds { namespace container {
         {
             scoped_node_ptr pNode( alloc_node( key ));
 
-#   ifdef CDS_CXX11_LAMBDA_SUPPORT
-#       ifdef CDS_BUG_STATIC_MEMBER_IN_LAMBDA
-            // GCC 4.5,4.6,4.7: node_to_value is unaccessible from lambda,
-            // like as MichaelList::node_to_value that requires to capture *this* despite on node_to_value is static function
-            value_type& (* n2v)( node_type& ) = node_to_value;
-            if ( base_class::insert_at( refHead, *pNode, [&f, n2v]( node_type& node ) { cds::unref(f)( n2v(node) ); } ))
-#       else
-            if ( base_class::insert_at( refHead, *pNode, [&f]( node_type& node ) { cds::unref(f)( node_to_value(node) ); } ))
-#       endif
-#   else
-            insert_functor<Func>  wrapper( f );
-            if ( base_class::insert_at( refHead, *pNode, cds::ref(wrapper) ))
-#   endif
-            {
+            if ( base_class::insert_at( refHead, *pNode, [&f]( node_type& node ) { cds::unref(f)( node_to_value(node) ); } )) {
                 pNode.release();
                 return true;
             }
             return false;
         }
 
-#   ifdef CDS_EMPLACE_SUPPORT
         template <typename... Args>
         bool emplace_at( head_type& refHead, Args&&... args )
         {
             return insert_node_at( refHead, alloc_node( std::forward<Args>(args) ... ));
         }
-#   endif
 
         template <typename Q, typename Compare, typename Func>
         bool erase_at( head_type& refHead, Q const& key, Compare cmp, Func f )
         {
-#   ifdef CDS_CXX11_LAMBDA_SUPPORT
-#       ifdef CDS_BUG_STATIC_MEMBER_IN_LAMBDA
-            // GCC 4.5-4.7: node_to_value is unaccessible from lambda,
-            // like as MichaelList::node_to_value that requires to capture *this* despite on node_to_value is static function
-            value_type const& (* n2v)( node_type const& ) = node_to_value;
-            return base_class::erase_at( refHead, key, cmp, [&f,n2v](node_type const& node){ cds::unref(f)( n2v(node) ); } );
-#       else
             return base_class::erase_at( refHead, key, cmp, [&f](node_type const& node){ cds::unref(f)( node_to_value(node) ); } );
-#       endif
-#   else
-            erase_functor<Func> wrapper( f );
-            return base_class::erase_at( refHead, key, cmp, cds::ref(wrapper) );
-#   endif
         }
 
         template <typename Q, typename Func>
@@ -897,21 +780,8 @@ namespace cds { namespace container {
         {
             scoped_node_ptr pNode( alloc_node( key ));
 
-#   ifdef CDS_CXX11_LAMBDA_SUPPORT
-#       ifdef CDS_BUG_STATIC_MEMBER_IN_LAMBDA
-            // GCC 4.5-4.7: node_to_value is unaccessible from lambda,
-            // like as MichaelList::node_to_value that requires to capture *this* despite on node_to_value is static function
-            value_type& (* n2v)( node_type& ) = node_to_value;
-            std::pair<bool, bool> ret = base_class::ensure_at( refHead, *pNode,
-                [&f, &key, n2v](bool bNew, node_type& node, node_type&){ cds::unref(f)( bNew, n2v(node), key ); });
-#       else
             std::pair<bool, bool> ret = base_class::ensure_at( refHead, *pNode,
                 [&f, &key](bool bNew, node_type& node, node_type&){ cds::unref(f)( bNew, node_to_value(node), key ); });
-#       endif
-#   else
-            ensure_functor<Q, Func> wrapper( key, f );
-            std::pair<bool, bool> ret = base_class::ensure_at( refHead, *pNode, cds::ref(wrapper));
-#   endif
             if ( ret.first && ret.second )
                 pNode.release();
 
@@ -927,29 +797,13 @@ namespace cds { namespace container {
         template <typename Q, typename Compare>
         bool find_at( head_type& refHead, Q const& key, Compare cmp ) const
         {
-#       ifdef CDS_CXX11_LAMBDA_SUPPORT
             return base_class::find_at( refHead, key, cmp, [](node_type&, Q const &) {} );
-#       else
-            return base_class::find_at( refHead, key, cmp, empty_find_functor() );
-#       endif
         }
 
         template <typename Q, typename Compare, typename Func>
         bool find_at( head_type& refHead, Q& val, Compare cmp, Func f ) const
         {
-#   ifdef CDS_CXX11_LAMBDA_SUPPORT
-#       ifdef CDS_BUG_STATIC_MEMBER_IN_LAMBDA
-            // GCC 4.5-4.7: node_to_value is unaccessible from lambda,
-            // like as MichaelList::node_to_value that requires to capture *this* despite on node_to_value is static function
-            value_type& (* n2v)( node_type& ) = node_to_value;
-            return base_class::find_at( refHead, val, cmp, [&f, n2v](node_type& node, Q& v){ cds::unref(f)( n2v(node), v ); });
-#       else
             return base_class::find_at( refHead, val, cmp, [&f](node_type& node, Q& v){ cds::unref(f)( node_to_value(node), v ); });
-#       endif
-#   else
-            find_functor<Func>  wrapper( f );
-            return base_class::find_at( refHead, val, cmp, cds::ref(wrapper) );
-#   endif
         }
 
         template <typename Q, typename Compare>