movable guarded_ptr: SkipList
[libcds.git] / cds / container / impl / skip_list_set.h
index 9f699af9569448fda658c83c718fdd2a1c734364..3f42454415748f855f601d43c4bb10c1854eb941 100644 (file)
@@ -134,7 +134,7 @@ namespace cds { namespace container {
 
     public:
         /// Guarded pointer
 
     public:
         /// Guarded pointer
-        typedef cds::gc::guarded_ptr< gc, node_type, value_type, details::guarded_ptr_cast_set<node_type, value_type> > guarded_ptr;
+        typedef typename gc::template guarded_ptr< node_type, value_type, details::guarded_ptr_cast_set<node_type, value_type> > guarded_ptr;
 
     protected:
         //@cond
 
     protected:
         //@cond
@@ -375,13 +375,13 @@ namespace cds { namespace container {
         /// Extracts the item from the set with specified \p key
         /** \anchor cds_nonintrusive_SkipListSet_hp_extract
             The function searches an item with key equal to \p key in the set,
         /// Extracts the item from the set with specified \p key
         /** \anchor cds_nonintrusive_SkipListSet_hp_extract
             The function searches an item with key equal to \p key in the set,
-            unlinks it from the set, and returns it in \p result parameter.
-            If the item with key equal to \p key is not found the function returns \p false.
+            unlinks it from the set, and returns it as \p guarded_ptr.
+            If \p key is not found the function returns an empty guarded pointer.
 
             Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type.
 
             The item extracted is freed automatically by garbage collector \p GC
 
             Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type.
 
             The item extracted is freed automatically by garbage collector \p GC
-            when returned \ref guarded_ptr object will be destroyed or released.
+            when returned \p guarded_ptr object will be destroyed or released.
             @note Each \p guarded_ptr object uses the GC's guard that can be limited resource.
 
             Usage:
             @note Each \p guarded_ptr object uses the GC's guard that can be limited resource.
 
             Usage:
@@ -390,8 +390,8 @@ namespace cds { namespace container {
             skip_list theList;
             // ...
             {
             skip_list theList;
             // ...
             {
-                skip_list::guarded_ptr gp;
-                if ( theList.extract( gp, 5 ) ) {
+                skip_list::guarded_ptr gp(theList.extract( 5 ))
+                if (  gp ) {
                     // Deal with gp
                     // ...
                 }
                     // Deal with gp
                     // ...
                 }
@@ -400,9 +400,11 @@ namespace cds { namespace container {
             \endcode
         */
         template <typename Q>
             \endcode
         */
         template <typename Q>
-        bool extract( guarded_ptr& result, Q const& key )
+        guarded_ptr extract( Q const& key )
         {
         {
-            return base_class::extract_( result.guard(), key, typename base_class::key_comparator() );
+            guarded_ptr gp;
+            base_class::extract_( gp.guard(), key, typename base_class::key_comparator() );
+            return gp;
         }
 
         /// Extracts the item from the set with comparing functor \p pred
         }
 
         /// Extracts the item from the set with comparing functor \p pred
@@ -415,20 +417,22 @@ namespace cds { namespace container {
             \p pred must imply the same element order as the comparator used for building the set.
         */
         template <typename Q, typename 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( guarded_ptr& ptr, Q const& key, Less pred )
+        guarded_ptr extract_with( Q const& key, Less pred )
         {
             CDS_UNUSED( pred );
             typedef cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >  wrapped_less;
         {
             CDS_UNUSED( pred );
             typedef cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >  wrapped_less;
-            return base_class::extract_( ptr.guard(), key, cds::opt::details::make_comparator_from_less<wrapped_less>() );
+            guarded_ptr gp;
+            base_class::extract_( gp.guard(), key, cds::opt::details::make_comparator_from_less<wrapped_less>() );
+            return gp;
         }
 
         /// Extracts an item with minimal key from the set
         /**
         }
 
         /// Extracts an item with minimal key from the set
         /**
-            The function searches an item with minimal key, unlinks it, and returns the item found in \p result parameter.
-            If the skip-list is empty the function returns \p false.
+            The function searches an item with minimal key, unlinks it, and returns pointer to the item found as \p guarded_ptr.
+            If the skip-list is empty the function returns an empty guarded pointer.
 
             The item extracted is freed automatically by garbage collector \p GC
 
             The item extracted is freed automatically by garbage collector \p GC
-            when returned \ref guarded_ptr object will be destroyed or released.
+            when returned \p guarded_ptr object will be destroyed or released.
             @note Each \p guarded_ptr object uses the GC's guard that can be limited resource.
 
             Usage:
             @note Each \p guarded_ptr object uses the GC's guard that can be limited resource.
 
             Usage:
@@ -437,8 +441,8 @@ namespace cds { namespace container {
             skip_list theList;
             // ...
             {
             skip_list theList;
             // ...
             {
-                skip_list::guarded_ptr gp;
-                if ( theList.extract_min( gp )) {
+                skip_list::guarded_ptr gp( theList.extract_min());
+                if ( gp ) {
                     // Deal with gp
                     //...
                 }
                     // Deal with gp
                     //...
                 }
@@ -446,18 +450,20 @@ namespace cds { namespace container {
             }
             \endcode
         */
             }
             \endcode
         */
-        bool extract_min( guarded_ptr& result)
+        guarded_ptr extract_min()
         {
         {
-            return base_class::extract_min_( result.guard() );
+            guarded_ptr gp;
+            base_class::extract_min_( gp.guard() );
+            return gp;
         }
 
         /// Extracts an item with maximal key from the set
         /**
         }
 
         /// Extracts an item with maximal key from the set
         /**
-            The function searches an item with maximal key, unlinks it, and returns the pointer to item found in \p result parameter.
-            If the skip-list is empty the function returns \p false.
+            The function searches an item with maximal key, unlinks it, and returns the pointer to item found as \p guarded_ptr.
+            If the skip-list is empty the function returns an empty guarded pointer.
 
             The item found is freed by garbage collector \p GC automatically
 
             The item found is freed by garbage collector \p GC automatically
-            when returned \ref guarded_ptr object will be destroyed or released.
+            when returned \p guarded_ptr object will be destroyed or released.
             @note Each \p guarded_ptr object uses the GC's guard that can be limited resource.
 
             Usage:
             @note Each \p guarded_ptr object uses the GC's guard that can be limited resource.
 
             Usage:
@@ -466,8 +472,8 @@ namespace cds { namespace container {
             skip_list theList;
             // ...
             {
             skip_list theList;
             // ...
             {
-                skip_list::guarded_ptr gp;
-                if ( theList.extract_max( gp )) {
+                skip_list::guarded_ptr gp( theList.extract_max());
+                if ( gp ) {
                     // Deal with gp
                     //...
                 }
                     // Deal with gp
                     //...
                 }
@@ -475,9 +481,11 @@ namespace cds { namespace container {
             }
             \endcode
         */
             }
             \endcode
         */
-        bool extract_max( guarded_ptr& result )
+        guarded_ptr extract_max()
         {
         {
-            return base_class::extract_max_( result.guard() );
+            guarded_ptr gp;
+            base_class::extract_max_( gp.guard() );
+            return gp;
         }
 
         /// Find the \p key
         }
 
         /// Find the \p key
@@ -571,9 +579,8 @@ namespace cds { namespace container {
         /// Finds \p key and return the item found
         /** \anchor cds_nonintrusive_SkipListSet_hp_get
             The function searches the item with key equal to \p key
         /// Finds \p key and return the item found
         /** \anchor cds_nonintrusive_SkipListSet_hp_get
             The function searches the item with key equal to \p key
-            and assigns the item found to guarded pointer \p result.
-            The function returns \p true if \p key is found, and \p false otherwise.
-            If \p key is not found the \p result parameter is left unchanged.
+            and returns a guarded pointer to the item found.
+            If \p key is not found the function returns an empty guarded pointer.
 
             It is safe when a concurrent thread erases the item returned in \p result guarded pointer.
             In this case the item will be freed later by garbage collector \p GC automatically
 
             It is safe when a concurrent thread erases the item returned in \p result guarded pointer.
             In this case the item will be freed later by garbage collector \p GC automatically
@@ -586,8 +593,8 @@ namespace cds { namespace container {
             skip_list theList;
             // ...
             {
             skip_list theList;
             // ...
             {
-                skip_list::guarded_ptr gp;
-                if ( theList.get( gp, 5 ) ) {
+                skip_list::guarded_ptr gp( theList.get( 5 ));
+                if ( theList.get( 5 )) {
                     // Deal with gp
                     //...
                 }
                     // Deal with gp
                     //...
                 }
@@ -599,14 +606,16 @@ namespace cds { namespace container {
             should accept a parameter of type \p Q that can be not the same as \p value_type.
         */
         template <typename Q>
             should accept a parameter of type \p Q that can be not the same as \p value_type.
         */
         template <typename Q>
-        bool get( guarded_ptr& result, Q const& key )
+        guarded_ptr get( Q const& key )
         {
         {
-            return base_class::get_with_( result.guard(), key, typename base_class::key_comparator() );
+            guarded_ptr gp;
+            base_class::get_with_( gp.guard(), key, typename base_class::key_comparator() );
+            return gp;
         }
 
         /// Finds \p key and return the item found
         /**
         }
 
         /// Finds \p key and return the item found
         /**
-            The function is an analog of \ref cds_nonintrusive_SkipListSet_hp_get "get( guarded_ptr&, Q const&)"
+            The function is an analog of \ref cds_nonintrusive_SkipListSet_hp_get "get(Q const&)"
             but \p pred is used for comparing the keys.
 
             \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q
             but \p pred is used for comparing the keys.
 
             \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q
@@ -614,11 +623,13 @@ namespace cds { namespace container {
             \p pred must imply the same element order as the comparator used for building the set.
         */
         template <typename Q, typename Less>
             \p pred must imply the same element order as the comparator used for building the set.
         */
         template <typename Q, typename Less>
-        bool get_with( guarded_ptr& result, Q const& key, Less pred )
+        guarded_ptr get_with( Q const& key, Less pred )
         {
             CDS_UNUSED( pred );
             typedef cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >  wrapped_less;
         {
             CDS_UNUSED( pred );
             typedef cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >  wrapped_less;
-            return base_class::get_with_( result.guard(), key, cds::opt::details::make_comparator_from_less< wrapped_less >());
+            guarded_ptr gp;
+            base_class::get_with_( gp.guard(), key, cds::opt::details::make_comparator_from_less< wrapped_less >());
+            return gp;
         }
 
         /// Clears the set (not atomic).
         }
 
         /// Clears the set (not atomic).