From f07a234c4c0a654f3a62d185a9d58f4d095d27b4 Mon Sep 17 00:00:00 2001 From: khizmax Date: Tue, 18 Nov 2014 20:27:19 +0300 Subject: [PATCH] movable quarded_ptr: SplitList --- cds/container/split_list_map.h | 55 ++++++++++-------- cds/container/split_list_set.h | 59 ++++++++++--------- cds/gc/impl/dhp_decl.h | 4 +- cds/gc/impl/hp_decl.h | 4 +- cds/intrusive/split_list.h | 78 ++++++++++++++------------ tests/test-hdr/map/hdr_map.h | 24 ++++---- tests/test-hdr/set/hdr_intrusive_set.h | 28 +++++---- tests/test-hdr/set/hdr_set.h | 24 ++++---- 8 files changed, 154 insertions(+), 122 deletions(-) diff --git a/cds/container/split_list_map.h b/cds/container/split_list_map.h index d9af00eb..de219d16 100644 --- a/cds/container/split_list_map.h +++ b/cds/container/split_list_map.h @@ -145,7 +145,7 @@ namespace cds { namespace container { public: /// Guarded pointer - typedef cds::gc::guarded_ptr< gc, node_type, value_type, details::guarded_ptr_cast_set > guarded_ptr; + typedef typename gc::template guarded_ptr< node_type, value_type, details::guarded_ptr_cast_set > guarded_ptr; public: /// Forward iterator (see \p SplitListSet::iterator) @@ -412,12 +412,12 @@ namespace cds { namespace container { /// Extracts the item with specified \p key /** \anchor cds_nonintrusive_SplitListMap_hp_extract The function searches an item with key equal to \p key, - unlinks it from the map, and returns it in \p dest parameter. - If the item with key equal to \p key is not found the function returns \p false. + unlinks it from the map, 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 K that may be not the same as \p value_type. - The extracted item is freed automatically when returned \ref guarded_ptr object will be destroyed or released. + The extracted item is freed automatically 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: @@ -426,24 +426,26 @@ namespace cds { namespace container { splitlist_map theMap; // ... { - splitlist_map::guarded_ptr gp; - theMap.extract( gp, 5 ); - // Deal with gp - // ... - + splitlist_map::guarded_ptr gp(theMap.extract( 5 )); + if ( gp ) { + // Deal with gp + // ... + } // Destructor of gp releases internal HP guard } \endcode */ template - bool extract( guarded_ptr& dest, K const& key ) + guarded_ptr extract( K const& key ) { - return base_class::extract_( dest.guard(), key ); + guarded_ptr gp; + base_class::extract_( gp.guard(), key ); + return gp; } /// Extracts the item using compare functor \p pred /** - The function is an analog of \ref cds_nonintrusive_SplitListMap_hp_extract "extract(guarded_ptr&, K const&)" + The function is an analog of \ref cds_nonintrusive_SplitListMap_hp_extract "extract(K const&)" but \p pred predicate is used for key comparing. \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p K @@ -451,10 +453,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the map. */ template - bool extract_with( guarded_ptr& dest, K const& key, Less pred ) + guarded_ptr extract_with( K const& key, Less pred ) { CDS_UNUSED( pred ); - return base_class::extract_with_( dest.guard(), key, cds::details::predicate_wrapper() ); + guarded_ptr gp; + base_class::extract_with_( gp.guard(), key, cds::details::predicate_wrapper() ); + return gp; } /// Finds the key \p key @@ -527,9 +531,8 @@ namespace cds { namespace container { /// Finds \p key and return the item found /** \anchor cds_nonintrusive_SplitListMap_hp_get The function searches the item with key equal to \p key - and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p key is found, and \p false otherwise. - If \p key is not found the \p ptr parameter is not changed. + and returns the item found as a guarded pointer. + If \p key is not found the function returns an empty guarded pointer. @note Each \p guarded_ptr object uses one GC's guard which can be limited resource. @@ -539,8 +542,8 @@ namespace cds { namespace container { splitlist_map theMap; // ... { - splitlist_map::guarded_ptr gp; - if ( theMap.get( gp, 5 )) { + splitlist_map::guarded_ptr gp(theMap.get( 5 )); + if ( gp ) { // Deal with gp //... } @@ -552,14 +555,16 @@ namespace cds { namespace container { should accept a parameter of type \p K that can be not the same as \p value_type. */ template - bool get( guarded_ptr& ptr, K const& key ) + guarded_ptr get( K const& key ) { - return base_class::get_( ptr.guard(), key ); + guarded_ptr gp; + base_class::get_( gp.guard(), key ); + return gp; } /// Finds \p key and return the item found /** - The function is an analog of \ref cds_nonintrusive_SplitListMap_hp_get "get( guarded_ptr&, K const&)" + The function is an analog of \ref cds_nonintrusive_SplitListMap_hp_get "get( K 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 K @@ -567,10 +572,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the map. */ template - bool get_with( guarded_ptr& ptr, K const& key, Less pred ) + guarded_ptr get_with( K const& key, Less pred ) { CDS_UNUSED( pred ); - return base_class::get_with_( ptr.guard(), key, cds::details::predicate_wrapper() ); + guarded_ptr gp; + base_class::get_with_( gp.guard(), key, cds::details::predicate_wrapper() ); + return gp; } /// Clears the map (not atomic) diff --git a/cds/container/split_list_set.h b/cds/container/split_list_set.h index 0f79c3a5..ba83b95c 100644 --- a/cds/container/split_list_set.h +++ b/cds/container/split_list_set.h @@ -160,7 +160,7 @@ namespace cds { namespace container { public: /// Guarded pointer - typedef cds::gc::guarded_ptr< gc, node_type, value_type, details::guarded_ptr_cast_set > guarded_ptr; + typedef typename gc::template guarded_ptr< node_type, value_type, details::guarded_ptr_cast_set > guarded_ptr; protected: //@cond @@ -549,12 +549,12 @@ namespace cds { namespace container { /// Extracts the item with specified \p key /** \anchor cds_nonintrusive_SplitListSet_hp_extract The function searches an item with key equal to \p key, - unlinks it from the set, and returns it in \p dest 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 may be not the same as \p value_type. - The extracted item is freed automatically when returned \ref guarded_ptr object will be destroyed or released. + The extracted item is freed automatically 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: @@ -563,24 +563,26 @@ namespace cds { namespace container { splitlist_set theSet; // ... { - splitlist_set::guarded_ptr gp; - theSet.extract( gp, 5 ); - // Deal with gp - // ... - + splitlist_set::guarded_ptr gp(theSet.extract( 5 )); + if ( gp ) { + // Deal with gp + // ... + } // Destructor of gp releases internal HP guard } \endcode */ template - bool extract( guarded_ptr& dest, Q const& key ) + guarded_ptr extract( Q const& key ) { - return extract_( dest.guard(), key ); + guarded_ptr gp; + extract_( gp.guard(), key ); + return gp; } /// Extracts the item using compare functor \p pred /** - The function is an analog of \ref cds_nonintrusive_SplitListSet_hp_extract "extract(guarded_ptr&, Q const&)" + The function is an analog of \ref cds_nonintrusive_SplitListSet_hp_extract "extract(Q const&)" but \p pred predicate is used for key comparing. \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q @@ -588,9 +590,11 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the set. */ template - bool extract_with( guarded_ptr& dest, Q const& key, Less pred ) + guarded_ptr extract_with( Q const& key, Less pred ) { - return extract_with_( dest.guard(), key, pred ); + guarded_ptr gp; + extract_with_( gp.guard(), key, pred ); + return gp; } /// Finds the key \p key @@ -683,9 +687,8 @@ namespace cds { namespace container { /// Finds the key \p key and return the item found /** \anchor cds_nonintrusive_SplitListSet_hp_get The function searches the item with key equal to \p key - and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p key is found, and \p false otherwise. - If \p key is not found the \p ptr parameter is not changed. + and returns the item found as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. @note Each \p guarded_ptr object uses one GC's guard which can be limited resource. @@ -695,8 +698,8 @@ namespace cds { namespace container { splitlist_set theSet; // ... { - splitlist_set::guarded_ptr gp; - if ( theSet.get( gp, 5 )) { + splitlist_set::guarded_ptr gp(theSet.get( 5 )); + if ( gp ) { // Deal with gp //... } @@ -708,14 +711,16 @@ namespace cds { namespace container { should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool get( guarded_ptr& ptr, Q const& key ) + guarded_ptr get( Q const& key ) { - return get_( ptr.guard(), key ); + guarded_ptr gp; + get_( gp.guard(), key ); + return gp; } /// Finds \p key and return the item found /** - The function is an analog of \ref cds_nonintrusive_SplitListSet_hp_get "get( guarded_ptr&, Q const&)" + The function is an analog of \ref cds_nonintrusive_SplitListSet_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 @@ -723,9 +728,11 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the set. */ template - bool get_with( guarded_ptr& ptr, Q const& key, Less pred ) + guarded_ptr get_with( Q const& key, Less pred ) { - return get_with_( ptr.guard(), key, pred ); + guarded_ptr gp; + get_with_( gp.guard(), key, pred ); + return gp; } /// Clears the set (not atomic) @@ -762,14 +769,14 @@ namespace cds { namespace container { using base_class::get_; template - bool extract_with_( typename gc::Guard& guard, Q const& key, Less pred ) + bool extract_with_( typename guarded_ptr::native_guard& guard, Q const& key, Less pred ) { CDS_UNUSED( pred ); return base_class::extract_with_( guard, key, typename maker::template predicate_wrapper::type() ); } template - bool get_with_( typename gc::Guard& guard, Q const& key, Less pred ) + bool get_with_( typename guarded_ptr::native_guard& guard, Q const& key, Less pred ) { CDS_UNUSED( pred ); return base_class::get_with_( guard, key, typename maker::template predicate_wrapper::type() ); diff --git a/cds/gc/impl/dhp_decl.h b/cds/gc/impl/dhp_decl.h index a0e4d4af..333c6d79 100644 --- a/cds/gc/impl/dhp_decl.h +++ b/cds/gc/impl/dhp_decl.h @@ -450,13 +450,13 @@ namespace cds { namespace gc { //@cond /// Initializes guarded pointer with \p p - guarded_ptr( guarded_type * p ) CDS_NOEXCEPT + explicit guarded_ptr( guarded_type * p ) CDS_NOEXCEPT { alloc_guard(); assert( m_guard.is_initialized() ); m_guard.set( p ); } - guarded_ptr( std::nullptr_t ) CDS_NOEXCEPT + explicit guarded_ptr( std::nullptr_t ) CDS_NOEXCEPT {} //@endcond diff --git a/cds/gc/impl/hp_decl.h b/cds/gc/impl/hp_decl.h index 72de7d0e..56c1db6f 100644 --- a/cds/gc/impl/hp_decl.h +++ b/cds/gc/impl/hp_decl.h @@ -444,13 +444,13 @@ namespace cds { namespace gc { //@cond /// Initializes guarded pointer with \p p - guarded_ptr( guarded_type * p ) CDS_NOEXCEPT + explicit guarded_ptr( guarded_type * p ) CDS_NOEXCEPT { alloc_guard(); assert( m_pGuard ); m_pGuard->set(p); } - guarded_ptr( std::nullptr_t ) CDS_NOEXCEPT + explicit guarded_ptr( std::nullptr_t ) CDS_NOEXCEPT : m_pGuard( nullptr ) {} //@endcond diff --git a/cds/intrusive/split_list.h b/cds/intrusive/split_list.h index 119e10dd..4f7125fc 100644 --- a/cds/intrusive/split_list.h +++ b/cds/intrusive/split_list.h @@ -298,7 +298,7 @@ namespace cds { namespace intrusive { } template - bool extract_at( dummy_node_type * pHead, typename gc::Guard& guard, split_list::details::search_value_type const& val, Compare cmp ) + bool extract_at( dummy_node_type * pHead, typename guarded_ptr::native_guard& guard, split_list::details::search_value_type const& val, Compare cmp ) { assert( pHead != nullptr ); bucket_head_type h(pHead); @@ -322,7 +322,7 @@ namespace cds { namespace intrusive { } template - bool get_at( dummy_node_type * pHead, typename gc::Guard& guard, split_list::details::search_value_type const& val, Compare cmp ) + bool get_at( dummy_node_type * pHead, typename guarded_ptr::native_guard& guard, split_list::details::search_value_type const& val, Compare cmp ) { assert( pHead != nullptr ); bucket_head_type h(pHead); @@ -489,7 +489,7 @@ namespace cds { namespace intrusive { } template - bool get_( typename gc::Guard& guard, Q const& val, Compare cmp ) + bool get_( typename guarded_ptr::native_guard& guard, Q const& val, Compare cmp ) { size_t nHash = hash_value( val ); split_list::details::search_value_type sv( val, split_list::regular_hash( nHash )); @@ -500,13 +500,13 @@ namespace cds { namespace intrusive { } template - bool get_( typename gc::Guard& guard, Q const& key) + bool get_( typename guarded_ptr::native_guard& guard, Q const& key ) { return get_( guard, key, key_comparator()); } template - bool get_with_( typename gc::Guard& guard, Q const& key, Less ) + bool get_with_( typename guarded_ptr::native_guard& guard, Q const& key, Less ) { return get_( guard, key, typename wrapped_ordered_list::template make_compare_from_less()); } @@ -546,10 +546,10 @@ namespace cds { namespace intrusive { } template - bool extract_( typename gc::Guard& guard, Q const& val, Compare cmp ) + bool extract_( typename guarded_ptr::native_guard& guard, Q const& val, Compare cmp ) { size_t nHash = hash_value( val ); - split_list::details::search_value_type sv( val, split_list::regular_hash( nHash )); + split_list::details::search_value_type sv( val, split_list::regular_hash( nHash )); dummy_node_type * pHead = get_bucket( nHash ); assert( pHead != nullptr ); @@ -563,17 +563,16 @@ namespace cds { namespace intrusive { } template - bool extract_( typename gc::Guard& guard, Q const& key) + bool extract_( typename guarded_ptr::native_guard& guard, Q const& key ) { return extract_( guard, key, key_comparator()); } template - bool extract_with_( typename gc::Guard& guard, Q const& key, Less ) + bool extract_with_( typename guarded_ptr::native_guard& guard, Q const& key, Less ) { return extract_( guard, key, typename wrapped_ordered_list::template make_compare_from_less() ); } - //@endcond public: @@ -811,13 +810,13 @@ namespace cds { namespace intrusive { /// Extracts the item with specified \p key /** \anchor cds_intrusive_SplitListSet_hp_extract The function searches an item with key equal to \p key, - unlinks it from the set, and returns it in \p dest 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 may be not the same as \p value_type. - The \ref disposer specified in \p OrderedList class' template parameter is called automatically - by garbage collector \p GC when returned \ref guarded_ptr object will be destroyed or released. + The \p disposer specified in \p OrderedList class' template parameter is called automatically + by garbage collector \p GC 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: @@ -826,24 +825,26 @@ namespace cds { namespace intrusive { splitlist_set theSet; // ... { - splitlist_set::guarded_ptr gp; - theSet.extract( gp, 5 ); - // Deal with gp - // ... - + splitlist_set::guarded_ptr gp( theSet.extract( 5 )); + if ( gp) { + // Deal with gp + // ... + } // Destructor of gp releases internal HP guard } \endcode */ template - bool extract( guarded_ptr& dest, Q const& key ) + guarded_ptr extract( Q const& key ) { - return extract_( dest.guard(), key ); + guarded_ptr gp; + extract_( gp.guard(), key ); + return gp; } /// Extracts the item using compare functor \p pred /** - The function is an analog of \ref cds_intrusive_SplitListSet_hp_extract "extract(guarded_ptr&, Q const&)" + The function is an analog of \ref cds_intrusive_SplitListSet_hp_extract "extract(Q const&)" but \p pred predicate is used for key comparing. \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q @@ -851,9 +852,11 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - bool extract_with( guarded_ptr& dest, Q const& key, Less pred ) + guarded_ptr extract_with( Q const& key, Less pred ) { - return extract_with_( dest.guard(), key, pred ); + guarded_ptr gp; + extract_with_( gp.guard(), key, pred ); + return gp; } /// Finds the key \p key @@ -944,12 +947,11 @@ namespace cds { namespace intrusive { /// Finds the key \p key and return the item found /** \anchor cds_intrusive_SplitListSet_hp_get The function searches the item with key equal to \p key - and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p key is found, and \p false otherwise. - If \p key is not found the \p ptr parameter is not changed. + and returns the item found as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. - The \ref disposer specified in \p OrderedList class' template parameter is called - by garbage collector \p GC automatically when returned \ref guarded_ptr object + The \p disposer specified in \p OrderedList class' template parameter is called + by garbage collector \p GC automatically when returned \p guarded_ptr object will be destroyed or released. @note Each \p guarded_ptr object uses one GC's guard which can be limited resource. @@ -959,8 +961,8 @@ namespace cds { namespace intrusive { splitlist_set theSet; // ... { - splitlist_set::guarded_ptr gp; - if ( theSet.get( gp, 5 )) { + splitlist_set::guarded_ptr gp = theSet.get( 5 ); + if ( gp ) { // Deal with gp //... } @@ -972,14 +974,16 @@ namespace cds { namespace intrusive { should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool get( guarded_ptr& ptr, Q const& key ) + guarded_ptr get( Q const& key ) { - return get_( ptr.guard(), key ); + guarded_ptr gp; + get_( gp.guard(), key ); + return gp; } /// Finds the key \p key and return the item found /** - The function is an analog of \ref cds_intrusive_SplitListSet_hp_get "get( guarded_ptr& ptr, Q const&)" + The function is an analog of \ref cds_intrusive_SplitListSet_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 @@ -987,9 +991,11 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - bool get_with( guarded_ptr& ptr, Q const& key, Less pred ) + guarded_ptr get_with( Q const& key, Less pred ) { - return get_with_( ptr.guard(), key, pred ); + guarded_ptr gp; + get_with_( gp.guard(), key, pred ); + return gp; } /// Returns item count in the set diff --git a/tests/test-hdr/map/hdr_map.h b/tests/test-hdr/map/hdr_map.h index 7cdfb1a4..81462dd4 100644 --- a/tests/test-hdr/map/hdr_map.h +++ b/tests/test-hdr/map/hdr_map.h @@ -209,19 +209,21 @@ namespace map { for ( int i = 0; i < nLimit; ++i ) { int nKey = arrRandom[i]; - CPPUNIT_ASSERT( m.get(gp, nKey )); + gp = m.get( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey ); - CPPUNIT_ASSERT( m.extract(gp, nKey)); + gp = m.extract( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey ); - CPPUNIT_CHECK( !m.get(gp, nKey)); - gp.release(); + gp = m.get( nKey ); + CPPUNIT_CHECK( !gp ); - CPPUNIT_CHECK( !m.extract(gp, nKey)); + CPPUNIT_CHECK( !m.extract(nKey)); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( m.empty() ); @@ -231,19 +233,21 @@ namespace map { for ( int i = 0; i < nLimit; ++i ) { int nKey = arrRandom[i]; - CPPUNIT_ASSERT( m.get_with(gp, other_item(nKey), other_less() )); + gp = m.get_with( other_item( nKey ), other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey ); - CPPUNIT_ASSERT( m.extract_with(gp, other_item(nKey), other_less() )); + gp = m.extract_with( other_item( nKey ), other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey ); - CPPUNIT_CHECK( !m.get_with(gp, other_item(nKey), other_less() )); - gp.release(); + gp = m.get_with( other_item( nKey ), other_less() ); + CPPUNIT_CHECK( !gp ); - CPPUNIT_CHECK( !m.extract_with(gp, other_item(nKey), other_less() )); + CPPUNIT_CHECK( !m.extract_with(other_item(nKey), other_less() )); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( m.empty() ); diff --git a/tests/test-hdr/set/hdr_intrusive_set.h b/tests/test-hdr/set/hdr_intrusive_set.h index fa06ddbb..5c69aff2 100644 --- a/tests/test-hdr/set/hdr_intrusive_set.h +++ b/tests/test-hdr/set/hdr_intrusive_set.h @@ -503,43 +503,47 @@ namespace set { guarded_ptr gp; for ( size_t i = 0; i < nLimit; i += 2 ) { int nKey = arr[i]; - CPPUNIT_ASSERT( s.get( gp, nKey )); + gp = s.get( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey * 2 ); - CPPUNIT_ASSERT( s.extract( gp, nKey )); + gp = s.extract( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty() ); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey * 2 ); - gp.release(); - CPPUNIT_CHECK( !s.get( gp, nKey )); + gp = s.get( nKey ); + CPPUNIT_CHECK( !gp ); CPPUNIT_ASSERT( gp.empty() ); - CPPUNIT_CHECK( !s.extract( gp, nKey )); + CPPUNIT_CHECK( !s.extract( nKey )); CPPUNIT_CHECK( gp.empty() ); nKey = arr[i+1]; - CPPUNIT_ASSERT( s.get_with( gp, nKey, less() )); + gp = s.get_with( nKey, less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey * 2 ); - CPPUNIT_ASSERT( s.extract_with( gp, nKey, less() )); + gp = s.extract_with( nKey, less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty() ); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey * 2 ); - gp.release(); - CPPUNIT_CHECK( !s.get_with( gp, nKey, less() )); + gp = s.get_with( nKey, less() ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !s.extract_with( gp, nKey, less() )); + CPPUNIT_CHECK( !s.extract_with( nKey, less() )); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_CHECK( s.empty() ); CPPUNIT_CHECK( check_size( s, 0 )); - CPPUNIT_CHECK( !s.get( gp, 100 )); - CPPUNIT_CHECK( !s.extract( gp, 100 )); + CPPUNIT_CHECK( !s.get( 100 )); + CPPUNIT_CHECK( !s.extract( 100 )); CPPUNIT_CHECK( gp.empty() ); Set::gc::force_dispose(); diff --git a/tests/test-hdr/set/hdr_set.h b/tests/test-hdr/set/hdr_set.h index d08ce90b..261f1bf4 100644 --- a/tests/test-hdr/set/hdr_set.h +++ b/tests/test-hdr/set/hdr_set.h @@ -360,19 +360,21 @@ namespace set { for ( int i = 0; i < nLimit; ++i ) { int nKey = arrRandom[i]; - CPPUNIT_ASSERT( s.get(gp, nKey )); + gp = s.get( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey ); - CPPUNIT_ASSERT( s.extract(gp, nKey)); + gp = s.extract( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey ); - CPPUNIT_CHECK( !s.get(gp, nKey)); - gp.release(); + CPPUNIT_CHECK( !s.get(nKey)); - CPPUNIT_CHECK( !s.extract(gp, nKey)); + gp = s.extract( nKey ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( s.empty() ); @@ -383,19 +385,21 @@ namespace set { for ( int i = 0; i < nLimit; ++i ) { int nKey = arrRandom[i]; - CPPUNIT_ASSERT( s.get_with(gp, other_item(nKey), other_less() )); + gp = s.get_with( other_item( nKey ), other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey ); - CPPUNIT_ASSERT( s.extract_with(gp, other_item(nKey), other_less() )); + gp = s.extract_with( other_item( nKey ), other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey ); - CPPUNIT_CHECK( !s.get_with(gp, other_item(nKey), other_less() )); - gp.release(); + gp = s.get_with( other_item( nKey ), other_less() ); + CPPUNIT_CHECK( !gp ); - CPPUNIT_CHECK( !s.extract_with(gp, other_item(nKey), other_less() )); + CPPUNIT_CHECK( !s.extract_with(other_item(nKey), other_less() )); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( s.empty() ); -- 2.34.1