movable guarded_ptr: LazyList, MichaelList
[libcds.git] / tests / test-hdr / ordered_list / hdr_michael.h
index 34e14f1055717bc2d3dcacdc2a3f1049b83e6324..4f3665df7c58ad0c1dbf3caac7af4bfa6d7be67a 100644 (file)
@@ -1,7 +1,7 @@
 //$$CDS-header$$
 
 #include "cppunit/cppunit_proxy.h"
-#include <cds/container/michael_list_base.h>
+#include <cds/container/details/michael_list_base.h>
 
 namespace ordlist {
     namespace cc = cds::container;
@@ -106,7 +106,7 @@ namespace ordlist {
             }
         };
         struct dummy_insert_functor {
-            void operator ()( item& i )
+            void operator ()( item& /*i*/ )
             {
                 // This functor should not be called
                 TestCase::current_test()->error( "CPPUNIT_ASSERT", "dummy_insert_functor should not be called", __FILE__, __LINE__ );
@@ -130,7 +130,7 @@ namespace ordlist {
         {
             i.nVal = i.nKey * 1024;
         }
-        static void dummy_insert_function( item& i )
+        static void dummy_insert_function( item& /*i*/ )
         {
             // This function should not be called
             TestCase::current_test()->error( "CPPUNIT_ASSERT", "dummy_insert_function should not be called", __FILE__, __LINE__ );
@@ -172,7 +172,7 @@ namespace ordlist {
         };
 
         struct dummy_check_value {
-            void operator()( item& i, int )
+            void operator()( item& /*i*/, int )
             {
                 // This functor should not be called
                 TestCase::current_test()->error( "CPPUNIT_ASSERT", "dummy_check_value should not be called", __FILE__, __LINE__ );
@@ -180,13 +180,13 @@ namespace ordlist {
         };
 
         struct ensure_functor {
-            void operator()( bool bNew, item& i, int n )
+            void operator()( bool /*bNew*/, item& i, int n )
             {
                 i.nVal = i.nKey * 1024;
             }
         };
 
-        static void ensure_func( bool bNew, item& i, int n )
+        static void ensure_func( bool /*bNew*/, item& i, int n )
         {
             i.nVal = n * 1033;
         }
@@ -244,8 +244,8 @@ namespace ordlist {
             // passed by ref
             {
                 insert_functor f;
-                CPPUNIT_ASSERT( l.insert( item(25), boost::ref(f)) );
-                CPPUNIT_ASSERT( !l.insert( item(100), boost::ref(f)) );
+                CPPUNIT_ASSERT( l.insert( item( 25 ), std::ref( f ) ) );
+                CPPUNIT_ASSERT( !l.insert( item( 100 ), std::ref( f ) ) );
             }
             // Test insert with function
             CPPUNIT_ASSERT( l.insert( 50, insert_function ));
@@ -265,7 +265,7 @@ namespace ordlist {
                     check_value f(1033);
                     i = 25;
                     CPPUNIT_ASSERT( l.find_with( 25, lt<value_type>() ));
-                    CPPUNIT_ASSERT( l.find_with( i, lt<value_type>(), boost::ref(f) ));
+                    CPPUNIT_ASSERT( l.find_with( i, lt<value_type>(), std::ref( f ) ) );
                 }
                 i = 50;
                 CPPUNIT_ASSERT( l.find( 50 ));
@@ -296,7 +296,7 @@ namespace ordlist {
                 CPPUNIT_ASSERT( ensureResult.first );
                 CPPUNIT_ASSERT( ensureResult.second );
 
-                ensureResult = l.ensure( 200, boost::ref(f) );
+                ensureResult = l.ensure( 200, std::ref( f ) );
                 CPPUNIT_ASSERT( ensureResult.first );
                 CPPUNIT_ASSERT( ensureResult.second );
 
@@ -343,14 +343,14 @@ namespace ordlist {
             {
                 erase_functor ef;
                 CPPUNIT_ASSERT( ef.nEraseCall == 0 );
-                CPPUNIT_ASSERT( l.erase_with( 160, lt<value_type>(), cds::ref(ef) ));
+                CPPUNIT_ASSERT( l.erase_with( 160, lt<value_type>(), std::ref(ef) ));
                 CPPUNIT_ASSERT( ef.nEraseCall == 1 );
-                CPPUNIT_ASSERT( !l.erase_with( 160, lt<value_type>(), cds::ref(ef) ));
+                CPPUNIT_ASSERT( !l.erase_with( 160, lt<value_type>(), std::ref(ef) ));
                 CPPUNIT_ASSERT( ef.nEraseCall == 1 );
 
-                CPPUNIT_ASSERT( l.erase( 250, cds::ref(ef) ));
+                CPPUNIT_ASSERT( l.erase( 250, std::ref(ef) ));
                 CPPUNIT_ASSERT( ef.nEraseCall == 2 );
-                CPPUNIT_ASSERT( !l.erase( 250, cds::ref(ef) ));
+                CPPUNIT_ASSERT( !l.erase( 250, std::ref(ef) ));
                 CPPUNIT_ASSERT( ef.nEraseCall == 2 );
             }
 
@@ -363,7 +363,6 @@ namespace ordlist {
             l.clear();
             CPPUNIT_ASSERT( l.empty() );
 
-#ifdef CDS_EMPLACE_SUPPORT
             {
                 int i;
 
@@ -386,7 +385,6 @@ namespace ordlist {
                 l.clear();
                 CPPUNIT_ASSERT( l.empty() );
             }
-#endif
 
             // Iterator test
             {
@@ -394,6 +392,28 @@ namespace ordlist {
                 for ( int i = 0; i < nCount; ++i )
                     CPPUNIT_ASSERT( l.insert(i) );
 
+                {
+                    typename OrdList::iterator it( l.begin() );
+                    typename OrdList::const_iterator cit( l.cbegin() );
+                    CPPUNIT_CHECK( it == cit );
+                    CPPUNIT_CHECK( it != l.end() );
+                    CPPUNIT_CHECK( it != l.cend() );
+                    CPPUNIT_CHECK( cit != l.end() );
+                    CPPUNIT_CHECK( cit != l.cend() );
+                    ++it;
+                    CPPUNIT_CHECK( it != cit );
+                    CPPUNIT_CHECK( it != l.end() );
+                    CPPUNIT_CHECK( it != l.cend() );
+                    CPPUNIT_CHECK( cit != l.end() );
+                    CPPUNIT_CHECK( cit != l.cend() );
+                    ++cit;
+                    CPPUNIT_CHECK( it == cit );
+                    CPPUNIT_CHECK( it != l.end() );
+                    CPPUNIT_CHECK( it != l.cend() );
+                    CPPUNIT_CHECK( cit != l.end() );
+                    CPPUNIT_CHECK( cit != l.cend() );
+                }
+
                 int i = 0;
                 for ( typename OrdList::iterator it = l.begin(), itEnd = l.end(); it != itEnd; ++it, ++i ) {
                     it->nVal = i * 2;
@@ -450,27 +470,28 @@ namespace ordlist {
                 for ( int i = 0; i < nLimit; ++i ) {
                     int nKey = arr[i];
 
-                    CPPUNIT_ASSERT( l.get(gp, nKey));
+                    gp = l.get( nKey );
+                    CPPUNIT_ASSERT( gp );
                     CPPUNIT_ASSERT( !gp.empty());
                     CPPUNIT_CHECK( gp->nKey == nKey );
                     CPPUNIT_CHECK( gp->nVal == nKey * 2 );
-                    gp.release();
 
-                    CPPUNIT_ASSERT( l.extract(gp, nKey));
+                    gp = l.extract( nKey );
+                    CPPUNIT_ASSERT( gp );
                     CPPUNIT_ASSERT( !gp.empty());
                     CPPUNIT_CHECK( gp->nKey == nKey );
                     CPPUNIT_CHECK( gp->nVal == nKey*2 );
-                    gp.release();
 
-                    CPPUNIT_CHECK( !l.get(gp, nKey));
+                    gp = l.get( nKey );
+                    CPPUNIT_CHECK( !gp );
                     CPPUNIT_CHECK( gp.empty());
-                    CPPUNIT_CHECK( !l.extract( gp, nKey));
+                    CPPUNIT_CHECK( !l.extract( nKey));
                     CPPUNIT_CHECK( gp.empty());
                 }
                 CPPUNIT_ASSERT( l.empty());
-                CPPUNIT_CHECK( !l.get(gp, arr[0]));
+                CPPUNIT_CHECK( !l.get(arr[0]));
                 CPPUNIT_CHECK( gp.empty());
-                CPPUNIT_CHECK( !l.extract( gp, arr[0]));
+                CPPUNIT_CHECK( !l.extract( arr[0]));
                 CPPUNIT_CHECK( gp.empty());
             }
 
@@ -483,27 +504,28 @@ namespace ordlist {
                     int nKey = arr[i];
                     other_item key( nKey );
 
-                    CPPUNIT_ASSERT( l.get_with(gp, key, other_less()));
+                    gp = l.get_with( key, other_less() );
+                    CPPUNIT_ASSERT( gp );
                     CPPUNIT_ASSERT( !gp.empty());
                     CPPUNIT_CHECK( gp->nKey == nKey );
                     CPPUNIT_CHECK( gp->nVal == nKey * 2 );
-                    gp.release();
 
-                    CPPUNIT_ASSERT( l.extract_with(gp, key, other_less()));
+                    gp = l.extract_with( key, other_less() );
+                    CPPUNIT_ASSERT( gp );
                     CPPUNIT_ASSERT( !gp.empty());
                     CPPUNIT_CHECK( gp->nKey == nKey );
                     CPPUNIT_CHECK( gp->nVal == nKey*2 );
-                    gp.release();
 
-                    CPPUNIT_CHECK( !l.get_with(gp, key, other_less()));
+                    gp = l.get_with( key, other_less() );
+                    CPPUNIT_CHECK( !gp );
                     CPPUNIT_CHECK( gp.empty());
-                    CPPUNIT_CHECK( !l.extract_with( gp, key, other_less()));
+                    CPPUNIT_CHECK( !l.extract_with( key, other_less()));
                     CPPUNIT_CHECK( gp.empty());
                 }
                 CPPUNIT_ASSERT( l.empty());
-                CPPUNIT_CHECK( !l.get_with(gp, other_item(arr[0]), other_less()));
+                CPPUNIT_CHECK( !l.get_with(other_item(arr[0]), other_less()));
                 CPPUNIT_CHECK( gp.empty());
-                CPPUNIT_CHECK( !l.extract_with( gp, other_item(arr[0]), other_less()));
+                CPPUNIT_CHECK( !l.extract_with( other_item(arr[0]), other_less()));
                 CPPUNIT_CHECK( gp.empty());
             }
         }
@@ -536,11 +558,12 @@ namespace ordlist {
                     {
                         rcu_lock lock;
                         value_type * pGet = l.get( a[i] );
-                        CPPUNIT_ASSERT( pGet != NULL );
+                        CPPUNIT_ASSERT( pGet != nullptr );
                         CPPUNIT_CHECK( pGet->nKey == a[i] );
                         CPPUNIT_CHECK( pGet->nVal == a[i] * 2 );
 
-                        CPPUNIT_ASSERT( l.extract( ep, a[i] ));
+                        ep = l.extract( a[i] );
+                        CPPUNIT_ASSERT( ep );
                         CPPUNIT_ASSERT( !ep.empty() );
                         CPPUNIT_CHECK( ep->nKey == a[i] );
                         CPPUNIT_CHECK( (*ep).nVal == a[i] * 2 );
@@ -548,8 +571,9 @@ namespace ordlist {
                     ep.release();
                     {
                         rcu_lock lock;
-                        CPPUNIT_CHECK( l.get( a[i]) == NULL );
-                        CPPUNIT_CHECK( !l.extract( ep, a[i] ));
+                        CPPUNIT_CHECK( l.get( a[i] ) == nullptr );
+                        ep = l.extract( a[i] );
+                        CPPUNIT_CHECK( !ep );
                         CPPUNIT_CHECK( ep.empty() );
                     }
                 }
@@ -557,8 +581,8 @@ namespace ordlist {
 
                 {
                     rcu_lock lock;
-                    CPPUNIT_CHECK( l.get( a[0] ) == NULL );
-                    CPPUNIT_CHECK( !l.extract( ep, a[0] ) );
+                    CPPUNIT_CHECK( l.get( a[0] ) == nullptr );
+                    CPPUNIT_CHECK( !l.extract( a[0] ) );
                     CPPUNIT_CHECK( ep.empty() );
                 }
 
@@ -572,11 +596,12 @@ namespace ordlist {
                     {
                         rcu_lock lock;
                         value_type * pGet = l.get_with( itm, other_less() );
-                        CPPUNIT_ASSERT( pGet != NULL );
+                        CPPUNIT_ASSERT( pGet != nullptr );
                         CPPUNIT_CHECK( pGet->nKey == a[i] );
                         CPPUNIT_CHECK( pGet->nVal == a[i] * 2 );
 
-                        CPPUNIT_ASSERT( l.extract_with( ep, itm, other_less() ));
+                        ep = l.extract_with( itm, other_less() );
+                        CPPUNIT_ASSERT( ep );
                         CPPUNIT_ASSERT( !ep.empty() );
                         CPPUNIT_CHECK( ep->nKey == a[i] );
                         CPPUNIT_CHECK( ep->nVal == a[i] * 2 );
@@ -584,8 +609,9 @@ namespace ordlist {
                     ep.release();
                     {
                         rcu_lock lock;
-                        CPPUNIT_CHECK( l.get_with( itm, other_less()) == NULL );
-                        CPPUNIT_CHECK( !l.extract_with( ep, itm, other_less() ));
+                        CPPUNIT_CHECK( l.get_with( itm, other_less() ) == nullptr );
+                        ep = l.extract_with( itm, other_less() );
+                        CPPUNIT_CHECK( !ep );
                         CPPUNIT_CHECK( ep.empty() );
                     }
                 }
@@ -593,8 +619,8 @@ namespace ordlist {
 
                 {
                     rcu_lock lock;
-                    CPPUNIT_CHECK( l.get_with( other_item(0), other_less() ) == NULL );
-                    CPPUNIT_CHECK( !l.extract_with( ep, other_item(0), other_less() ));
+                    CPPUNIT_CHECK( l.get_with( other_item( 0 ), other_less() ) == nullptr );
+                    CPPUNIT_CHECK( !l.extract_with( other_item(0), other_less() ));
                     CPPUNIT_CHECK( ep.empty() );
                 }
             }
@@ -648,7 +674,6 @@ namespace ordlist {
             l.clear();
             CPPUNIT_ASSERT( l.empty() );
 
-#ifdef CDS_EMPLACE_SUPPORT
             // insert test
             CPPUNIT_ASSERT( l.emplace( 501 ) != l.end() );
             CPPUNIT_ASSERT( l.emplace( 251, 152 ) != l.end());
@@ -673,9 +698,31 @@ namespace ordlist {
             CPPUNIT_ASSERT( it->nKey == 1001 );
             CPPUNIT_ASSERT( it->nVal == 1001 * 2 );
 
+            {
+                typename OrdList::iterator it( l.begin() );
+                typename OrdList::const_iterator cit( l.cbegin() );
+                CPPUNIT_CHECK( it == cit );
+                CPPUNIT_CHECK( it != l.end() );
+                CPPUNIT_CHECK( it != l.cend() );
+                CPPUNIT_CHECK( cit != l.end() );
+                CPPUNIT_CHECK( cit != l.cend() );
+                ++it;
+                CPPUNIT_CHECK( it != cit );
+                CPPUNIT_CHECK( it != l.end() );
+                CPPUNIT_CHECK( it != l.cend() );
+                CPPUNIT_CHECK( cit != l.end() );
+                CPPUNIT_CHECK( cit != l.cend() );
+                ++cit;
+                CPPUNIT_CHECK( it == cit );
+                CPPUNIT_CHECK( it != l.end() );
+                CPPUNIT_CHECK( it != l.cend() );
+                CPPUNIT_CHECK( cit != l.end() );
+                CPPUNIT_CHECK( cit != l.cend() );
+            }
+
+
             l.clear();
             CPPUNIT_ASSERT( l.empty() );
-#endif
         }
 
         void HP_cmp();
@@ -683,15 +730,10 @@ namespace ordlist {
         void HP_cmpmix();
         void HP_ic();
 
-        void PTB_cmp();
-        void PTB_less();
-        void PTB_cmpmix();
-        void PTB_ic();
-
-        void HRC_cmp();
-        void HRC_less();
-        void HRC_cmpmix();
-        void HRC_ic();
+        void DHP_cmp();
+        void DHP_less();
+        void DHP_cmpmix();
+        void DHP_ic();
 
         void RCU_GPI_cmp();
         void RCU_GPI_less();
@@ -729,15 +771,10 @@ namespace ordlist {
             CPPUNIT_TEST(HP_cmpmix)
             CPPUNIT_TEST(HP_ic)
 
-            CPPUNIT_TEST(PTB_cmp)
-            CPPUNIT_TEST(PTB_less)
-            CPPUNIT_TEST(PTB_cmpmix)
-            CPPUNIT_TEST(PTB_ic)
-
-            CPPUNIT_TEST(HRC_cmp)
-            CPPUNIT_TEST(HRC_less)
-            CPPUNIT_TEST(HRC_cmpmix)
-            CPPUNIT_TEST(HRC_ic)
+            CPPUNIT_TEST(DHP_cmp)
+            CPPUNIT_TEST(DHP_less)
+            CPPUNIT_TEST(DHP_cmpmix)
+            CPPUNIT_TEST(DHP_ic)
 
             CPPUNIT_TEST(RCU_GPI_cmp)
             CPPUNIT_TEST(RCU_GPI_less)