movable guarded_ptr: LazyList, MichaelList
[libcds.git] / tests / test-hdr / ordered_list / hdr_lazy.h
index bbaac65812f770f409fdab7adfb26839da28b1f3..b472bdb69a8f638ed4cf657555c5dce5ae79bce4 100644 (file)
@@ -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__ );
@@ -117,7 +117,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__ );
@@ -171,7 +171,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__ );
@@ -179,13 +179,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;
         }
@@ -389,7 +389,29 @@ namespace ordlist {
             {
                 int nCount = 100;
                 for ( int i = 0; i < nCount; ++i )
-                    CPPUNIT_ASSERT( l.insert(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 ) {
@@ -447,27 +469,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());
             }
 
@@ -480,27 +503,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());
             }
 
@@ -538,7 +562,8 @@ namespace ordlist {
                         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 );
@@ -547,8 +572,7 @@ namespace ordlist {
                     {
                         rcu_lock lock;
                         CPPUNIT_CHECK( l.get( a[i] ) == nullptr );
-                        CPPUNIT_CHECK( !l.extract( ep, a[i] ));
-                        CPPUNIT_CHECK( ep.empty() );
+                        CPPUNIT_CHECK( !l.extract( a[i] ));
                     }
                 }
                 CPPUNIT_ASSERT( l.empty() );
@@ -556,7 +580,8 @@ namespace ordlist {
                 {
                     rcu_lock lock;
                     CPPUNIT_CHECK( l.get( a[0] ) == nullptr );
-                    CPPUNIT_CHECK( !l.extract( ep, a[0] ) );
+                    ep = l.extract( a[0] );
+                    CPPUNIT_CHECK( !ep );
                     CPPUNIT_CHECK( ep.empty() );
                 }
 
@@ -574,7 +599,8 @@ namespace ordlist {
                         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 );
@@ -583,7 +609,8 @@ namespace ordlist {
                     {
                         rcu_lock lock;
                         CPPUNIT_CHECK( l.get_with( itm, other_less() ) == nullptr );
-                        CPPUNIT_CHECK( !l.extract_with( ep, itm, other_less() ));
+                        ep = l.extract_with( itm, other_less() );
+                        CPPUNIT_CHECK( !ep );
                         CPPUNIT_CHECK( ep.empty() );
                     }
                 }
@@ -592,7 +619,7 @@ namespace ordlist {
                 {
                     rcu_lock lock;
                     CPPUNIT_CHECK( l.get_with( other_item( 0 ), other_less() ) == nullptr );
-                    CPPUNIT_CHECK( !l.extract_with( ep, other_item(0), other_less() ));
+                    CPPUNIT_CHECK( !l.extract_with( other_item(0), other_less() ));
                     CPPUNIT_CHECK( ep.empty() );
                 }
             }
@@ -669,6 +696,29 @@ 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() );
         }