Tried to fix gcc/clang problem like how to pass argument pack to lambda function
[libcds.git] / cds / container / michael_set_rcu.h
index 95ee8fd8157fb682a263c6c5f45fa0efdeb01a63..86da400d4dc38c05bf7b4ca3018c712b1c269697 100644 (file)
@@ -1,7 +1,7 @@
 //$$CDS-header$$
 
-#ifndef __CDS_CONTAINER_MICHAEL_SET_RCU_H
-#define __CDS_CONTAINER_MICHAEL_SET_RCU_H
+#ifndef CDSLIB_CONTAINER_MICHAEL_SET_RCU_H
+#define CDSLIB_CONTAINER_MICHAEL_SET_RCU_H
 
 #include <cds/container/details/michael_set_base.h>
 #include <cds/details/allocator.h>
@@ -22,7 +22,7 @@ namespace cds { namespace container {
 
         Template parameters are:
         - \p RCU - one of \ref cds_urcu_gc "RCU type"
-        - \p OrderedList - ordered list implementation used as the bucket for hash set, for example, 
+        - \p OrderedList - ordered list implementation used as the bucket for hash set, for example,
             \ref cds_nonintrusive_MichaelList_rcu "MichaelList".
             The ordered list implementation specifies the type \p T stored in the hash-set,
             the comparison functor for the type \p T and other features specific for
@@ -201,7 +201,7 @@ namespace cds { namespace container {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -213,7 +213,7 @@ namespace cds { namespace container {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
@@ -449,8 +449,8 @@ namespace cds { namespace container {
         /// Extracts an item from the set
         /** \anchor cds_nonintrusive_MichaelHashSet_rcu_extract
             The function searches an item with key equal to \p key in the set,
-            unlinks it from the set, places item pointer into \p dest argument, and returns \p true.
-            If the item with the key equal to \p key is not found the function return \p false.
+            unlinks it from the set, and returns \ref cds::urcu::exempt_ptr "exempt_ptr" pointer to the item found.
+            If the item with the key equal to \p key is not found the function return an empty \p exempt_ptr.
 
             @note The function does NOT call RCU read-side lock or synchronization,
             and does NOT dispose the item found. It just excludes the item from the set
@@ -477,7 +477,8 @@ namespace cds { namespace container {
 
                 // Now, you can apply extract function
                 // Note that you must not delete the item found inside the RCU lock
-                if ( theSet.extract( p, 10 )) {
+                p = theSet.extract( 10 );
+                if ( p ) {
                     // do something with p
                     ...
                 }
@@ -489,30 +490,27 @@ namespace cds { namespace container {
             \endcode
         */
         template <typename Q>
-        bool extract( exempt_ptr& dest, Q const& key )
+        exempt_ptr extract( Q const& key )
         {
-            if ( bucket( key ).extract( dest, key )) {
+            exempt_ptr p = bucket( key ).extract( key );
+            if ( p )
                 --m_ItemCounter;
-                return true;
-            }
-            return false;
+            return p;
         }
 
         /// Extracts an item from the set using \p pred predicate for searching
         /**
-            The function is an analog of \ref cds_nonintrusive_MichaelHashSet_rcu_extract "extract(exempt_ptr&, Q const&)"
-            but \p pred is used for key comparing.
+            The function is an analog of \p extract(Q const&) but \p pred is used for key comparing.
             \p Less functor has the interface like \p std::less.
             \p pred must imply the same element order as the comparator used for building the set.
         */
         template <typename Q, typename Less>
-        bool extract_with( exempt_ptr& dest, Q const& key, Less pred )
+        exempt_ptr extract_with( Q const& key, Less pred )
         {
-            if ( bucket( key ).extract_with( dest, key, pred )) {
+            exempt_ptr p = bucket( key ).extract_with( key, pred );
+            if ( p )
                 --m_ItemCounter;
-                return true;
-            }
-            return false;
+            return p;
         }
 
         /// Finds the key \p key
@@ -547,6 +545,13 @@ namespace cds { namespace container {
         {
             return bucket( key ).find( key, f );
         }
+        //@cond
+        template <typename Q, typename Func>
+        bool find( Q const& key, Func f ) const
+        {
+            return bucket( key ).find( key, f );
+        }
+        //@endcond
 
         /// Finds the key \p key using \p pred predicate for searching
         /**
@@ -560,6 +565,13 @@ namespace cds { namespace container {
         {
             return bucket( key ).find_with( key, pred, f );
         }
+        //@cond
+        template <typename Q, typename Less, typename Func>
+        bool find_with( Q const& key, Less pred, Func f ) const
+        {
+            return bucket( key ).find_with( key, pred, f );
+        }
+        //@endcond
 
         /// Finds the key \p key
         /** \anchor cds_nonintrusive_MichealSet_rcu_find_val
@@ -675,4 +687,4 @@ namespace cds { namespace container {
 
 }} // namespace cds::container
 
-#endif // ifndef __CDS_CONTAINER_MICHAEL_SET_RCU_H
+#endif // ifndef CDSLIB_CONTAINER_MICHAEL_SET_RCU_H