Renaming map member function insert_key() to insert_with()
[libcds.git] / tests / test-hdr / ordered_list / hdr_lazy_kv.h
index a542d80261396d50d16ec68fc122de8b2d51a7d8..e62dcf3b09b697e0daf67f8d35d83875d1e15ee0 100644 (file)
@@ -1,7 +1,7 @@
 //$$CDS-header$$
 
 #include "cppunit/cppunit_proxy.h"
-#include <cds/container/lazy_list_base.h>
+#include <cds/container/details/lazy_list_base.h>
 
 namespace ordlist {
     namespace cc = cds::container;
@@ -66,7 +66,7 @@ namespace ordlist {
 
         struct ensure_functor {
             template <typename T>
-            void operator()( bool bNew, T& pair )
+            void operator()( bool /*bNew*/, T& pair )
             {
                 pair.second.m_val = pair.first * 50;
             }
@@ -119,27 +119,27 @@ namespace ordlist {
             CPPUNIT_ASSERT( l.find( 100 ));
 
             check_value chk(0);
-            CPPUNIT_ASSERT( l.find( 100, boost::ref( chk ) ));
+            CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
 
             CPPUNIT_ASSERT( !l.find_with( 50, lt<key_type>() ));
             CPPUNIT_ASSERT( l.insert( 50, 500 ));
             CPPUNIT_ASSERT( l.find_with( 50, lt<key_type>() ));
             CPPUNIT_ASSERT( !l.insert( 50, 5 ));
             chk.m_nExpected = 500;
-            CPPUNIT_ASSERT( l.find( 50, boost::ref( chk ) ));
+            CPPUNIT_ASSERT( l.find( 50, std::ref( chk ) ) );
             chk.m_nExpected = 0;
-            CPPUNIT_ASSERT( l.find( 100, boost::ref( chk ) ));
+            CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
             CPPUNIT_ASSERT( !l.empty() );
 
             CPPUNIT_ASSERT( !l.find( 150 ));
-            CPPUNIT_ASSERT( l.insert_key( 150, insert_functor() ));
+            CPPUNIT_ASSERT( l.insert_with( 150, insert_functor() ));
             CPPUNIT_ASSERT( l.find( 150 ));
             chk.m_nExpected = 1500;
-            CPPUNIT_ASSERT( l.find_with( 150, lt<key_type>(), boost::ref( chk ) ));
+            CPPUNIT_ASSERT( l.find_with( 150, lt<key_type>(), std::ref( chk ) ) );
             chk.m_nExpected = 0;
-            CPPUNIT_ASSERT( l.find( 100, boost::ref( chk ) ));
+            CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
             chk.m_nExpected = 500;
-            CPPUNIT_ASSERT( l.find( 50, boost::ref( chk ) ));
+            CPPUNIT_ASSERT( l.find( 50, std::ref( chk ) ) );
             CPPUNIT_ASSERT( !l.empty() );
 
             // erase test
@@ -150,7 +150,7 @@ namespace ordlist {
             CPPUNIT_ASSERT( l.find( 50 ));
             {
                 erase_functor ef;
-                l.erase( 50, boost::ref(ef));
+                l.erase( 50, std::ref( ef ) );
                 CPPUNIT_ASSERT( ef.nKey == 50 );
                 CPPUNIT_ASSERT( ef.nVal == 500 );
             }
@@ -162,26 +162,26 @@ namespace ordlist {
             CPPUNIT_ASSERT( bEnsureResult.first );
             CPPUNIT_ASSERT( !bEnsureResult.second );
             chk.m_nExpected = 5000;
-            CPPUNIT_ASSERT( l.find( 100, boost::ref( chk ) ));
+            CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
 
             {
                 ensure_functor ef;
-                bEnsureResult = l.ensure( 50, boost::ref( ef ));
+                bEnsureResult = l.ensure( 50, std::ref( ef ) );
             }
             CPPUNIT_ASSERT( bEnsureResult.first );
             CPPUNIT_ASSERT( bEnsureResult.second );
             chk.m_nExpected = 2500;
-            CPPUNIT_ASSERT( l.find( 50, boost::ref( chk ) ));
+            CPPUNIT_ASSERT( l.find( 50, std::ref( chk ) ) );
 
             // erase test
             CPPUNIT_ASSERT( !l.empty() );
-            CPPUNIT_ASSERT( l.insert_key( 200, insert_functor() ));
+            CPPUNIT_ASSERT( l.insert_with( 200, insert_functor() ));
             CPPUNIT_ASSERT( l.insert( 25 ));
             CPPUNIT_ASSERT( l.erase( 100 ));
             CPPUNIT_ASSERT( l.erase( 150 ));
             {
                 erase_functor ef;
-                CPPUNIT_ASSERT( l.erase_with( 200, lt<key_type>(), cds::ref(ef)) );
+                CPPUNIT_ASSERT( l.erase_with( 200, lt<key_type>(), std::ref(ef)) );
                 CPPUNIT_ASSERT( ef.nKey == 200 );
                 CPPUNIT_ASSERT( ef.nVal == 2000 );
             }
@@ -193,7 +193,6 @@ namespace ordlist {
             l.clear();
             CPPUNIT_ASSERT( l.empty() );
 
-#ifdef CDS_EMPLACE_SUPPORT
             // insert test
             CPPUNIT_ASSERT( l.emplace( 501 ) );
             CPPUNIT_ASSERT( l.emplace( 251, 152 ));
@@ -203,13 +202,12 @@ namespace ordlist {
             CPPUNIT_ASSERT( !l.emplace( 251, 10) );
 
             check_value cv(0);
-            CPPUNIT_ASSERT( l.find( 501, cds::ref(cv) ));
+            CPPUNIT_ASSERT( l.find( 501, std::ref(cv) ));
             cv.m_nExpected = 152;
-            CPPUNIT_ASSERT( l.find( 251, cds::ref(cv) ));
+            CPPUNIT_ASSERT( l.find( 251, std::ref(cv) ));
 
             l.clear();
             CPPUNIT_ASSERT( l.empty() );
-#endif
 
             // Iterator test
             {
@@ -217,6 +215,28 @@ namespace ordlist {
                 for ( int i = 0; i < nCount; ++i )
                     CPPUNIT_ASSERT( l.insert(i, i * 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() );
+                }
+
                 int i = 0;
                 for ( typename OrdList::iterator it = l.begin(), itEnd = l.end(); it != itEnd; ++it, ++i ) {
                     CPPUNIT_ASSERT( it.key() == i );
@@ -227,7 +247,7 @@ namespace ordlist {
                 // Check that we have visited all items
                 for ( int i = 0; i < nCount; ++i ) {
                     chk.m_nExpected = i * 3;
-                    CPPUNIT_ASSERT( l.find( i, boost::ref(chk) ));
+                    CPPUNIT_ASSERT( l.find( i, std::ref( chk ) ) );
                 }
 
                 l.clear();
@@ -247,7 +267,7 @@ namespace ordlist {
                 // Check that we have visited all items
                 for ( int i = nCount; i > 0; --i ) {
                     chk.m_nExpected = (i - 1) * 7;
-                    CPPUNIT_ASSERT( l.find_with( i - 1, lt<key_type>(), boost::ref(chk) ));
+                    CPPUNIT_ASSERT( l.find_with( i - 1, lt<key_type>(), std::ref( chk ) ) );
                 }
 
                 l.clear();
@@ -277,27 +297,30 @@ 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->first == nKey );
                     CPPUNIT_CHECK( gp->second.m_val == nKey * 2 );
                     gp.release();
 
-                    CPPUNIT_ASSERT( l.extract(gp, nKey));
+                    gp = l.extract( nKey );
+                    CPPUNIT_ASSERT( gp );
                     CPPUNIT_ASSERT( !gp.empty());
                     CPPUNIT_CHECK( gp->first == nKey );
                     CPPUNIT_CHECK( gp->second.m_val == 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());
             }
 
@@ -310,27 +333,30 @@ namespace ordlist {
                     int nKey = arr[i];
                     other_key key = float(nKey + 0.3);
 
-                    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->first == nKey );
                     CPPUNIT_CHECK( gp->second.m_val == 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->first == nKey );
                     CPPUNIT_CHECK( gp->second.m_val == 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, 3.4f, other_less()));
+                CPPUNIT_CHECK( !l.get_with(3.4f, other_less()));
                 CPPUNIT_CHECK( gp.empty());
-                CPPUNIT_CHECK( !l.extract_with( gp, 3.4f, other_less()));
+                CPPUNIT_CHECK( !l.extract_with( 3.4f, other_less()));
                 CPPUNIT_CHECK( gp.empty());
             }
         }
@@ -363,11 +389,12 @@ namespace ordlist {
                     {
                         rcu_lock lock;
                         value_type * pGet = l.get( a[i] );
-                        CPPUNIT_ASSERT( pGet != NULL );
+                        CPPUNIT_ASSERT( pGet != nullptr );
                         CPPUNIT_CHECK( pGet->first == a[i] );
                         CPPUNIT_CHECK( pGet->second.m_val == 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->first == a[i] );
                         CPPUNIT_CHECK( (*ep).second.m_val == a[i] * 2 );
@@ -375,8 +402,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() );
                     }
                 }
@@ -384,9 +412,8 @@ namespace ordlist {
 
                 {
                     rcu_lock lock;
-                    CPPUNIT_CHECK( l.get( a[0] ) == NULL );
-                    CPPUNIT_CHECK( !l.extract( ep, a[0] ) );
-                    CPPUNIT_CHECK( ep.empty() );
+                    CPPUNIT_CHECK( l.get( a[0] ) == nullptr );
+                    CPPUNIT_CHECK( !l.extract( a[0] ) );
                 }
 
                 // extract_with/get_with
@@ -399,11 +426,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->first == a[i] );
                         CPPUNIT_CHECK( pGet->second.m_val == 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->first == a[i] );
                         CPPUNIT_CHECK( ep->second.m_val == a[i] * 2 );
@@ -411,8 +439,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() );
                     }
                 }
@@ -420,8 +449,8 @@ namespace ordlist {
 
                 {
                     rcu_lock lock;
-                    CPPUNIT_CHECK( l.get_with( 3.14f, other_less() ) == NULL );
-                    CPPUNIT_CHECK( !l.extract_with( ep, 3.14f, other_less() ));
+                    CPPUNIT_CHECK( l.get_with( 3.14f, other_less() ) == nullptr );
+                    CPPUNIT_CHECK( !l.extract_with( 3.14f, other_less() ));
                     CPPUNIT_CHECK( ep.empty() );
                 }
             }
@@ -463,7 +492,7 @@ namespace ordlist {
                 CPPUNIT_ASSERT( !l.empty() );
 
                 CPPUNIT_ASSERT( l.find( 150 ) == l.end() );
-                CPPUNIT_ASSERT( l.insert_key( 150, insert_functor() ) != l.end() );
+                CPPUNIT_ASSERT( l.insert_with( 150, insert_functor() ) != l.end() );
                 it = l.find( 150 );
                 CPPUNIT_ASSERT( it != l.end() );
                 CPPUNIT_ASSERT( it.key() == 150 );
@@ -512,7 +541,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());
@@ -533,7 +561,6 @@ namespace ordlist {
 
                 l.clear();
                 CPPUNIT_ASSERT( l.empty() );
-#endif
 
                 // Iterator test
                 {
@@ -541,6 +568,28 @@ namespace ordlist {
                     for ( int i = 0; i < nCount; ++i )
                         CPPUNIT_ASSERT( l.insert(i, i * 2 ) != l.end() );
 
+                    {
+                        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 iter = l.begin(), itEnd = l.end(); iter != itEnd; ++iter, ++i ) {
                         CPPUNIT_ASSERT( iter.key() == i );
@@ -594,10 +643,10 @@ namespace ordlist {
         void HP_cmpmix();
         void HP_ic();
 
-        void PTB_cmp();
-        void PTB_less();
-        void PTB_cmpmix();
-        void PTB_ic();
+        void DHP_cmp();
+        void DHP_less();
+        void DHP_cmpmix();
+        void DHP_ic();
 
         void RCU_GPI_cmp();
         void RCU_GPI_less();
@@ -624,11 +673,6 @@ namespace ordlist {
         void RCU_SHT_cmpmix();
         void RCU_SHT_ic();
 
-        void HRC_cmp();
-        void HRC_less();
-        void HRC_cmpmix();
-        void HRC_ic();
-
         void NOGC_cmp();
         void NOGC_less();
         void NOGC_cmpmix();
@@ -640,15 +684,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)