Fixed iterator issues in set/map
authorkhizmax <khizmax@gmail.com>
Fri, 31 Oct 2014 13:19:29 +0000 (16:19 +0300)
committerkhizmax <khizmax@gmail.com>
Fri, 31 Oct 2014 13:19:29 +0000 (16:19 +0300)
59 files changed:
cds/container/impl/lazy_kvlist.h
cds/container/impl/lazy_list.h
cds/container/impl/michael_kvlist.h
cds/container/impl/michael_list.h
cds/container/impl/skip_list_map.h
cds/container/impl/skip_list_set.h
cds/container/lazy_kvlist_nogc.h
cds/container/lazy_kvlist_rcu.h
cds/container/lazy_list_nogc.h
cds/container/lazy_list_rcu.h
cds/container/michael_kvlist_nogc.h
cds/container/michael_kvlist_rcu.h
cds/container/michael_list_nogc.h
cds/container/michael_list_rcu.h
cds/container/michael_map.h
cds/container/michael_map_nogc.h
cds/container/michael_map_rcu.h
cds/container/michael_set.h
cds/container/michael_set_nogc.h
cds/container/michael_set_rcu.h
cds/container/skip_list_map_nogc.h
cds/container/skip_list_map_rcu.h
cds/container/skip_list_set_nogc.h
cds/container/skip_list_set_rcu.h
cds/container/split_list_map.h
cds/container/split_list_map_nogc.h
cds/container/split_list_map_rcu.h
cds/container/split_list_set.h
cds/container/split_list_set_nogc.h
cds/container/split_list_set_rcu.h
cds/intrusive/details/michael_set_base.h
cds/intrusive/details/split_list_base.h
cds/intrusive/impl/lazy_list.h
cds/intrusive/impl/michael_list.h
cds/intrusive/impl/skip_list.h
cds/intrusive/lazy_list_nogc.h
cds/intrusive/lazy_list_rcu.h
cds/intrusive/michael_list_nogc.h
cds/intrusive/michael_list_rcu.h
cds/intrusive/michael_set.h
cds/intrusive/michael_set_nogc.h
cds/intrusive/michael_set_rcu.h
cds/intrusive/skip_list_nogc.h
cds/intrusive/skip_list_rcu.h
cds/intrusive/split_list.h
cds/intrusive/split_list_nogc.h
cds/intrusive/split_list_rcu.h
tests/test-hdr/map/hdr_map.h
tests/test-hdr/ordered_list/hdr_intrusive_lazy.h
tests/test-hdr/ordered_list/hdr_intrusive_michael.h
tests/test-hdr/ordered_list/hdr_lazy.h
tests/test-hdr/ordered_list/hdr_lazy_kv.h
tests/test-hdr/ordered_list/hdr_michael.h
tests/test-hdr/ordered_list/hdr_michael_kv.h
tests/test-hdr/set/hdr_intrusive_set.h
tests/test-hdr/set/hdr_set.h
tests/unit/map2/map_find_int.cpp
tests/unit/map2/map_find_string.cpp
tests/unit/map2/map_insfind_int.cpp

index e1433a51d33cc358198a154437348df035eb10ab..b71876e43ae1ea8adcb62e83d535f19a762bb9bc 100644 (file)
@@ -314,7 +314,7 @@ namespace cds { namespace container {
             ++it;   // skip dummy head
             return it;
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             const_iterator it( head() );
             ++it;   // skip dummy head
@@ -328,7 +328,7 @@ namespace cds { namespace container {
         {
             return const_iterator( tail());
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( tail());
         }
index e44fbe42bbbdc3c51946fe9bc5ac5a69d7255ab9..bc82f5fa8ad0443c01a0934cf6e211a699e1c0e8 100644 (file)
@@ -300,7 +300,7 @@ namespace cds { namespace container {
             ++it        ;   // skip dummy head node
             return it;
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             const_iterator it( head() );
             ++it        ;   // skip dummy head node
@@ -314,7 +314,7 @@ namespace cds { namespace container {
         {
             return const_iterator( tail() );
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( tail() );
         }
index 7dce75f5c7a586d7118573918c564e91eb1e0f1e..bd82088cf346e74935e35140aad800fd7539d1db 100644 (file)
@@ -299,7 +299,7 @@ namespace cds { namespace container {
         {
             return const_iterator( head() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( head() );
         }
@@ -311,7 +311,7 @@ namespace cds { namespace container {
         {
             return const_iterator();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index 17224e31d5d5a1488af0c568b4fc17d1844325d5..aa89923694434f9de011f37c4638045f229b94bf 100644 (file)
@@ -279,7 +279,7 @@ namespace cds { namespace container {
         {
             return const_iterator( head() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( head() );
         }
@@ -291,7 +291,7 @@ namespace cds { namespace container {
         {
             return const_iterator();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index 303ea953133ef2a2c8244f4769d74522155f4d2d..2bc344b871fa8a949fe17e2d4ea35ecf04d6a575 100644 (file)
@@ -199,7 +199,7 @@ namespace cds { namespace container {
         {
             return cbegin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( base_class::cbegin() );
         }
@@ -217,7 +217,7 @@ namespace cds { namespace container {
         {
             return cend();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( base_class::cend() );
         }
index 83252f804748d0bad532debadff97285da244c83..ee1bb7005904e314e0371044f212a9c02fb2f400 100644 (file)
@@ -190,7 +190,7 @@ namespace cds { namespace container {
         }
 
         /// Returns a forward const iterator addressing the first element in a set
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( base_class::cbegin() );
         }
@@ -208,7 +208,7 @@ namespace cds { namespace container {
         }
 
         /// Returns a forward const iterator that addresses the location succeeding the last element in a set.
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( base_class::cend() );
         }
index e77a5b421b6894984afd7da5085b895daf65ddcf..96e9483addb05d945a30872cdad351d3dc0cd524 100644 (file)
@@ -261,7 +261,7 @@ namespace cds { namespace container {
             ++it ;  // skip dummy head
             return it;
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             const_iterator it( head() );
             ++it ;  // skip dummy head
@@ -275,7 +275,7 @@ namespace cds { namespace container {
         {
             return const_iterator( tail());
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( tail());
         }
index 218c2bc3e374c3bab008165fde1fb840b51a16fa..12e7c29715d3df2b864938664644af08666a4c50 100644 (file)
@@ -295,7 +295,7 @@ namespace cds { namespace container {
             ++it;   // skip dummy head
             return it;
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             const_iterator it( head() );
             ++it;   // skip dummy head
@@ -309,7 +309,7 @@ namespace cds { namespace container {
         {
             return const_iterator( tail());
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( tail());
         }
index eac78730090bbe70827cfd9a18b5bcd3791f60a0..bc5d614930ad12bb4c4457870c1c1113e24db0d5 100644 (file)
@@ -226,7 +226,7 @@ namespace cds { namespace container {
             ++it    ;   // skip dummy head node
             return it;
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             const_iterator it( head() );
             ++it    ;   // skip dummy head node
@@ -240,7 +240,7 @@ namespace cds { namespace container {
         {
             return const_iterator( tail());
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( tail());
         }
index a7fedd31a2ea7a6e090ef78fa1036bbd0802226d..d35f318465faf9488e071af4ddb655c161820ab8 100644 (file)
@@ -291,7 +291,7 @@ namespace cds { namespace container {
             ++it        ;   // skip dummy head node
             return it;
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             const_iterator it( head() );
             ++it        ;   // skip dummy head node
@@ -305,7 +305,7 @@ namespace cds { namespace container {
         {
             return const_iterator( tail() );
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( tail() );
         }
index ca1faa037dfa9a836f1e0259da8bee45b41872f7..73215dbeee9f546439d08ff066af26edae76620b 100644 (file)
@@ -276,7 +276,7 @@ namespace cds { namespace container {
         {
             return const_iterator( head() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( head() );
         }
@@ -288,7 +288,7 @@ namespace cds { namespace container {
         {
             return const_iterator();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index 7783fb8dbaa47362fd5e71b19bb9624d652e9dfa..420d367c78d105f604002cd7f97c597a087931f4 100644 (file)
@@ -283,7 +283,7 @@ namespace cds { namespace container {
         {
             return const_iterator( head() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( head() );
         }
@@ -295,7 +295,7 @@ namespace cds { namespace container {
         {
             return const_iterator();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index 2f970b944f0f046f3abb25bccfec17ea5c11d272..3812342cc0c0412747b3daca84cb1ad13fc28546 100644 (file)
@@ -234,7 +234,7 @@ namespace cds { namespace container {
         {
             return const_iterator( head() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( head() );
         }
@@ -246,7 +246,7 @@ namespace cds { namespace container {
         {
             return const_iterator();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index 65a8351e0a8dcd0beb328bf63bc5e5adab070925..24b6b62fc14d247d916b8d24286a98036b0a8e88 100644 (file)
@@ -278,7 +278,7 @@ namespace cds { namespace container {
         {
             return const_iterator( head() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( head() );
         }
@@ -290,7 +290,7 @@ namespace cds { namespace container {
         {
             return const_iterator();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index 285baeb561fb880c0c6671db6ea8def127928dbf..1f7291e9f9ea494eb2ea5fa267547846a673abc3 100644 (file)
@@ -327,7 +327,7 @@ namespace cds { namespace container {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -339,7 +339,7 @@ namespace cds { namespace container {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
index fbeb044eee6d5e451318cd1501826be768c3e3f5..cfa193e8e6b0ea19891156921bfa163ed56323c7 100644 (file)
@@ -178,12 +178,6 @@ namespace cds { namespace container {
             {
                 return !( *this == i );
             }
-
-            /// Checks if the iterator is not equal to \p end()
-            explicit operator bool() const
-            {
-                return *this != iterator_type();
-            }
         };
 
 
@@ -220,7 +214,7 @@ namespace cds { namespace container {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -232,7 +226,7 @@ namespace cds { namespace container {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
index 5fd03535ad76ab80075046d9ff863afbf285ae4a..ddf7e8504d2bda36ce68ec326ccb9a1fcae0842e 100644 (file)
@@ -248,7 +248,7 @@ namespace cds { namespace container {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -260,7 +260,7 @@ namespace cds { namespace container {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
index 76e801e9465e6b2991469b23c1b5f6a25ea6dcc3..91c7ef9453890564092a512118a84cf24d60f9c1 100644 (file)
@@ -255,7 +255,7 @@ namespace cds { namespace container {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -267,7 +267,7 @@ namespace cds { namespace container {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
index 326c602eeeb00f4d036d909b21e1d4cdc7ca2a7b..bc46d7bc1606de5585abcebedb65f312ed0ba98d 100644 (file)
@@ -119,7 +119,7 @@ namespace cds { namespace container {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -131,7 +131,7 @@ namespace cds { namespace container {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
index 95ee8fd8157fb682a263c6c5f45fa0efdeb01a63..7655ebedb482e5e0015ff0b9dd98580462e288a5 100644 (file)
@@ -201,7 +201,7 @@ namespace cds { namespace container {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -213,7 +213,7 @@ namespace cds { namespace container {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
index e4146eb9e82736c2dba0f83eb574b817a6225ab5..ce6f85b2c0f2c25b64ddf8c359df4362636dbf1e 100644 (file)
@@ -169,7 +169,7 @@ namespace cds { namespace container {
         {
             return base_class::begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return base_class::cbegin();
         }
@@ -181,7 +181,7 @@ namespace cds { namespace container {
         {
             return base_class::end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return base_class::cend();
         }
index 2701d0e1649e3d8f0993a50cf07a6d4b9cd0057c..ea14f08c0cccd5353a23975ff5393b32b3ec2456 100644 (file)
@@ -197,7 +197,7 @@ namespace cds { namespace container {
         {
             return cbegin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( base_class::cbegin() );
         }
@@ -215,7 +215,7 @@ namespace cds { namespace container {
         {
             return cend();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( base_class::cend() );
         }
index ae83672bab812138fccdd1cc1ab404855576d5e1..9427f5b20d256d9744b259b397208c02f9dacb1b 100644 (file)
@@ -189,7 +189,7 @@ namespace cds { namespace container {
         {
             return const_iterator( base_class::begin() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( base_class::cbegin() );
         }
@@ -207,7 +207,7 @@ namespace cds { namespace container {
         {
             return const_iterator( base_class::end() );
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( base_class::cend() );
         }
index 227a3b8079424d9b48ba59f4b8c5d47880c16ece..85bc71adc6255f76ba67f02656d58f65f61a7db6 100644 (file)
@@ -229,7 +229,7 @@ namespace cds { namespace container {
         {
             return const_iterator( base_class::begin() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( base_class::cbegin() );
         }
@@ -247,7 +247,7 @@ namespace cds { namespace container {
         {
             return const_iterator( base_class::end() );
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( base_class::cend() );
         }
index cf560e5d4f2a274ae0bf5cd57619139240495557..eef5927ad0df70978d869f717f42250b81fc099c 100644 (file)
@@ -184,7 +184,7 @@ namespace cds { namespace container {
         {
             return base_class::begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return base_class::cbegin();
         }
@@ -196,7 +196,7 @@ namespace cds { namespace container {
         {
             return base_class::end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return base_class::cend();
         }
index 6104f191a035fa63660e530bafe9e264a1b3a6f3..b5e03a9e2e41c0b9ca48bf17ab0f44815d1a7733 100644 (file)
@@ -100,7 +100,7 @@ namespace cds { namespace container {
         {
             return base_class::begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return base_class::cbegin();
         }
@@ -112,7 +112,7 @@ namespace cds { namespace container {
         {
             return base_class::end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return base_class::cend();
         }
index c18aa9dc12130c4066abd403f2696b5167546a3b..ee395aed00f09a92628c8c0dfd4e9ffdc32f743a 100644 (file)
@@ -217,7 +217,7 @@ namespace cds { namespace container {
         {
             return base_class::begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return base_class::cbegin();
         }
@@ -229,7 +229,7 @@ namespace cds { namespace container {
         {
             return base_class::end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return base_class::cend();
         }
index 5d91110998d85071832b24662d5a659a3374662c..31ec11ff13a3844517e63745c63535e133759cd3 100644 (file)
@@ -351,13 +351,23 @@ namespace cds { namespace container {
         /// Returns a forward const iterator addressing the first element in a set
         const_iterator begin() const
         {
-            return const_iterator( base_class::begin() );
+            return cbegin();
+        }
+        /// Returns a forward const iterator addressing the first element in a set
+        const_iterator cbegin() const
+        {
+            return const_iterator( base_class::cbegin() );
         }
 
         /// Returns an const iterator that addresses the location succeeding the last element in a set
         const_iterator end() const
         {
-            return const_iterator( base_class::end() );
+            return cend();
+        }
+        /// Returns an const iterator that addresses the location succeeding the last element in a set
+        const_iterator cend() const
+        {
+            return const_iterator( base_class::cend() );
         }
 
     public:
index 49e07c06eba2f4d6290bca0a7cfb44c8402ae43e..628103349ce56e4141530ddfbd98b4373d12db2e 100644 (file)
@@ -219,13 +219,23 @@ namespace cds { namespace container {
         /// Returns a forward const iterator addressing the first element in a set
         const_iterator begin() const
         {
-            return const_iterator( base_class::begin() );
+            return cbegin();
+        }
+        /// Returns a forward const iterator addressing the first element in a set
+        const_iterator cbegin() const
+        {
+            return const_iterator( base_class::cbegin() );
         }
 
         /// Returns an const iterator that addresses the location succeeding the last element in a set
         const_iterator end() const
         {
-            return const_iterator( base_class::end() );
+            return cend();
+        }
+        /// Returns an const iterator that addresses the location succeeding the last element in a set
+        const_iterator cend() const
+        {
+            return const_iterator( base_class::cend() );
         }
 
     protected:
index 14fe8c38767736159f1122a26d3a44d478c34ffa..67a5be7712acb87d60b9e2ebd967315c620d7f69 100644 (file)
@@ -388,13 +388,23 @@ namespace cds { namespace container {
         /// Returns a forward const iterator addressing the first element in a set
         const_iterator begin() const
         {
-            return const_iterator( base_class::begin() );
+            return cbegin();
+        }
+        /// Returns a forward const iterator addressing the first element in a set
+        const_iterator cbegin() const
+        {
+            return const_iterator( base_class::cbegin() );
         }
 
         /// Returns an const iterator that addresses the location succeeding the last element in a set
         const_iterator end() const
         {
-            return const_iterator( base_class::end() );
+            return cend();
+        }
+        /// Returns an const iterator that addresses the location succeeding the last element in a set
+        const_iterator cend() const
+        {
+            return const_iterator( base_class::cend() );
         }
 
     public:
index 09be328c4c103a267188b4d1c5e0a9beaeb531b6..c7bfdb282a31c7ef35a12f32e1cde11f532d23fc 100644 (file)
@@ -93,6 +93,7 @@ namespace cds { namespace intrusive {
             template <typename OrderedList, bool IsConst>
             class iterator
             {
+                friend class iterator < OrderedList, !IsConst > ;
             protected:
                 typedef OrderedList bucket_type;
                 typedef typename list_iterator_selector< bucket_type, IsConst>::bucket_ptr bucket_ptr;
@@ -102,6 +103,8 @@ namespace cds { namespace intrusive {
                 list_iterator   m_itList;
                 bucket_ptr      m_pEndBucket;
 
+                friend class iterator < bucket_type, !IsConst > ;
+
                 void next()
                 {
                     if ( m_pCurBucket < m_pEndBucket ) {
@@ -176,7 +179,7 @@ namespace cds { namespace intrusive {
                 }
 
                 template <bool C>
-                bool operator ==(iterator<OrderedList, C> const& i ) const
+                bool operator ==(iterator<bucket_type, C> const& i) const
                 {
                     return m_pCurBucket == i.m_pCurBucket && m_itList == i.m_itList;
                 }
index a5d52720c7d49686583c4214feab4274218f98a1..3b3abee95667076ced3b8cebeb3963da0beebf02 100644 (file)
@@ -775,6 +775,8 @@ namespace cds { namespace intrusive {
             class iterator_type
             {
                 typedef OrderedList     ordered_list_type;
+                friend class iterator_type <NodeTraits, OrderedList, !IsConst >;
+
             protected:
                 typedef typename select_list_iterator<ordered_list_type, IsConst>::type    list_iterator;
                 typedef NodeTraits      node_traits;
index c485b7ac50fbcb51b4afa7c1d855950a04d40f40..ca19239054930a4330b5bed2b690b83cb4fc0e32 100644 (file)
@@ -443,7 +443,7 @@ namespace cds { namespace intrusive {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -455,7 +455,7 @@ namespace cds { namespace intrusive {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
index 2922cb6ab14a7c64b8342f27ecbb09bc671bafab..09e5072e982f3bce4e3c7f7c18d8d5e8e5da3f9e 100644 (file)
@@ -452,7 +452,7 @@ namespace cds { namespace intrusive {
         }
 
         /// Returns a forward const iterator addressing the first element in a list
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( m_pHead );
         }
@@ -470,7 +470,7 @@ namespace cds { namespace intrusive {
         }
 
         /// Returns an const iterator that addresses the location succeeding the last element in a list
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index 4a4c761e3c931a94cc5d23a69e85caaa25f8b461..b4b3406717a2477448bd1b1a07d9f213d8fcc0d8 100644 (file)
@@ -999,7 +999,7 @@ namespace cds { namespace intrusive {
         {
             return const_iterator( *m_Head.head() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( *m_Head.head() );
         }
@@ -1017,7 +1017,7 @@ namespace cds { namespace intrusive {
         {
             return const_iterator();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index 6eb7418904405a95b807691b48378fcbdec6b8ca..c024d9d9eeb7519abf1add7e25417eea7b1dba7d 100644 (file)
@@ -280,15 +280,24 @@ namespace cds { namespace intrusive {
         /// Returns a forward const iterator addressing the first element in a list
         const_iterator begin() const
         {
-            const_iterator it( const_cast<node_type *>( &m_Head ));
-            ++it        ;   // skip dummy head
+            return cbegin();
+        }
+        /// Returns a forward const iterator addressing the first element in a list
+        const_iterator cbegin() const
+        {
+            const_iterator it( const_cast<node_type *>(&m_Head) );
+            ++it;   // skip dummy head
             return it;
         }
 
         /// Returns an const iterator that addresses the location succeeding the last element in a list
         const_iterator end() const
         {
-            return const_iterator( const_cast<node_type *>( &m_Tail ));
+            return cend();
+        }
+        const_iterator cend() const
+        {
+            return const_iterator( const_cast<node_type *>(&m_Tail) );
         }
 
     public:
index 1790d2a77b47392a41b3e25e024faf4dcd013944..adad3206aae4996d5909090de216138d75c0c5a6 100644 (file)
@@ -366,7 +366,7 @@ namespace cds { namespace intrusive {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -378,7 +378,7 @@ namespace cds { namespace intrusive {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
index 96ae276ef69b438e13f5712185a177e26a4f6fbe..ca2ca629e9b99a6f1ba2b092db24224617fad191 100644 (file)
@@ -257,7 +257,7 @@ namespace cds { namespace intrusive {
             return const_iterator(m_pHead.load(memory_model::memory_order_relaxed) );
         }
         /// Returns a forward const iterator addressing the first element in a list
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator(m_pHead.load(memory_model::memory_order_relaxed) );
         }
index 1cd4b6622977c6a76c6b5e4c6beafa107b262995..44d100a66c4114c803d0739afafb9f7b49cf713b 100644 (file)
@@ -278,7 +278,7 @@ namespace cds { namespace intrusive {
             return const_iterator(m_pHead );
         }
         /// Returns a forward const iterator addressing the first element in a list
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator(m_pHead );
         }
@@ -289,7 +289,7 @@ namespace cds { namespace intrusive {
             return const_iterator();
         }
         /// Returns an const iterator that addresses the location succeeding the last element in a list
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index c6dafa8130c513b4a6428c009dc61a0bf260f2f2..8b1bee123114e2349dbfa110b289c16c03912b02 100644 (file)
@@ -310,7 +310,7 @@ namespace cds { namespace intrusive {
         {
             return get_const_begin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return get_const_begin();
         }
@@ -322,7 +322,7 @@ namespace cds { namespace intrusive {
         {
             return get_const_end();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return get_const_end();
         }
@@ -332,11 +332,11 @@ namespace cds { namespace intrusive {
         //@cond
         const_iterator get_const_begin() const
         {
-            return const_iterator( m_Buckets[0].begin(), m_Buckets, m_Buckets + bucket_count() );
+            return const_iterator( m_Buckets[0].cbegin(), m_Buckets, m_Buckets + bucket_count() );
         }
         const_iterator get_const_end() const
         {
-            return const_iterator( m_Buckets[bucket_count() - 1].end(), m_Buckets + bucket_count() - 1, m_Buckets + bucket_count() );
+            return const_iterator( m_Buckets[bucket_count() - 1].cend(), m_Buckets + bucket_count() - 1, m_Buckets + bucket_count() );
         }
         //@endcond
 
index 983d10c2421e7f161dc42a5566412234c1df605b..9c9ae882e6ed5ca2551117a33a95629b38a74b9f 100644 (file)
@@ -112,11 +112,11 @@ namespace cds { namespace intrusive {
         //@{
         const_iterator begin() const
         {
-            return get_const_begin();
+            return cbegin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
-            return get_const_begin();
+            return const_iterator( m_Buckets[0].cbegin(), m_Buckets, m_Buckets + bucket_count() );
         }
         //@}
 
@@ -124,26 +124,14 @@ namespace cds { namespace intrusive {
         //@{
         const_iterator end() const
         {
-            return get_const_end();
+            return cend();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
-            return get_const_end();
+            return const_iterator( m_Buckets[bucket_count() - 1].cend(), m_Buckets + bucket_count() - 1, m_Buckets + bucket_count() );
         }
         //@}
 
-    private:
-        //@cond
-        const_iterator get_const_begin() const
-        {
-            return const_iterator( m_Buckets[0].begin(), m_Buckets, m_Buckets + bucket_count() );
-        }
-        const_iterator get_const_end() const
-        {
-            return const_iterator( m_Buckets[bucket_count() - 1].end(), m_Buckets + bucket_count() - 1, m_Buckets + bucket_count() );
-        }
-        //@endcond
-
     public:
         /// Initializes hash set
         /** @copydetails cds_intrusive_MichaelHashSet_hp_ctor
index 69695a6ad19d4a7c60b6176596cf3fcef8ed20fb..13fdc34796eb7230110d3b757d94719fb089130c 100644 (file)
@@ -165,11 +165,11 @@ namespace cds { namespace intrusive {
         //@{
         const_iterator begin() const
         {
-            return get_const_begin();
+            return cbegin();
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
-            return get_const_begin();
+            return const_iterator( m_Buckets[0].cbegin(), m_Buckets, m_Buckets + bucket_count() );
         }
         //@}
 
@@ -177,26 +177,14 @@ namespace cds { namespace intrusive {
         //@{
         const_iterator end() const
         {
-            return get_const_end();
+            return cend();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
-            return get_const_end();
+            return const_iterator( m_Buckets[bucket_count() - 1].cend(), m_Buckets + bucket_count() - 1, m_Buckets + bucket_count() );
         }
         //@}
 
-    private:
-        //@cond
-        const_iterator get_const_begin() const
-        {
-            return const_iterator( m_Buckets[0].begin(), m_Buckets, m_Buckets + bucket_count() );
-        }
-        const_iterator get_const_end() const
-        {
-            return const_iterator( m_Buckets[bucket_count() - 1].end(), m_Buckets + bucket_count() - 1, m_Buckets + bucket_count() );
-        }
-        //@endcond
-
     public:
         /// Initialize hash set
         /**
index ba4ce74658afdbbc7718b9d42e239e6120dd8522..6326cd1184eceff861b2bf1b2bc6e45ac4fd7415 100644 (file)
@@ -621,7 +621,7 @@ namespace cds { namespace intrusive {
         {
             return const_iterator( *m_Head.head() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( *m_Head.head() );
         }
@@ -639,7 +639,7 @@ namespace cds { namespace intrusive {
         {
             return const_iterator();
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index d1c17cfa5d8810e2b649ffa08f8bf7d515deba93..4a61dfc85f14e0bd194e35d92a36608772859c0a 100644 (file)
@@ -1416,7 +1416,7 @@ retry:
         }
 
         /// Returns a forward const iterator addressing the first element in a set
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( *m_Head.head() );
         }
@@ -1434,7 +1434,7 @@ retry:
         }
 
         /// Returns a forward const iterator that addresses the location succeeding the last element in a set.
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator();
         }
index 687401de386c73386491c62f7bfe8f4064113393..62166ec5d55904b4850842820e2909e81764cc23 100644 (file)
@@ -1083,13 +1083,23 @@ namespace cds { namespace intrusive {
         /// Returns a forward const iterator addressing the first element in a split-list
         const_iterator begin() const
         {
-            return const_iterator( m_List.begin(), m_List.end() );
+            return cbegin();
+        }
+        /// Returns a forward const iterator addressing the first element in a split-list
+        const_iterator cbegin() const
+        {
+            return const_iterator( m_List.cbegin(), m_List.cend() );
         }
 
         /// Returns an const iterator that addresses the location succeeding the last element in a split-list
         const_iterator end() const
         {
-            return const_iterator( m_List.end(), m_List.end() );
+            return cend();
+        }
+        /// Returns an const iterator that addresses the location succeeding the last element in a split-list
+        const_iterator cend() const
+        {
+            return const_iterator( m_List.cend(), m_List.cend() );
         }
 
     };
index 7e7b4fa5bacc4023e04c663db6488d4e5eea022d..18e1cc07c17c25ad4895fbc6e8e5f229c943e0f9 100644 (file)
@@ -492,7 +492,7 @@ namespace cds { namespace intrusive {
         {
             return const_iterator( m_List.begin(), m_List.end() );
         }
-        const_iterator cbegin()
+        const_iterator cbegin() const
         {
             return const_iterator( m_List.cbegin(), m_List.cend() );
         }
@@ -504,7 +504,7 @@ namespace cds { namespace intrusive {
         {
             return const_iterator( m_List.end(), m_List.end() );
         }
-        const_iterator cend()
+        const_iterator cend() const
         {
             return const_iterator( m_List.cend(), m_List.cend() );
         }
index d21ba0f4d73eb7619633f6aacc700bba8cd79d56..fa3bc86b99e69e42655ea738e0e74a558aee71df 100644 (file)
@@ -979,13 +979,23 @@ namespace cds { namespace intrusive {
         /// Returns a forward const iterator addressing the first element in a split-list
         const_iterator begin() const
         {
-            return const_iterator( m_List.begin(), m_List.end() );
+            return cbegin();
+        }
+        /// Returns a forward const iterator addressing the first element in a split-list
+        const_iterator cbegin() const
+        {
+            return const_iterator( m_List.cbegin(), m_List.cend() );
         }
 
         /// Returns an const iterator that addresses the location succeeding the last element in a split-list
         const_iterator end() const
         {
-            return const_iterator( m_List.end(), m_List.end() );
+            return cend();
+        }
+        /// Returns an const iterator that addresses the location succeeding the last element in a split-list
+        const_iterator cend() const
+        {
+            return const_iterator( m_List.cend(), m_List.cend() );
         }
 
     };
index 5f96b1b903176b6273da5ff050926162ea768764..f4961e74d9286a0b8e5fb3cbe7fcc8861accf0d3 100644 (file)
@@ -582,7 +582,33 @@ namespace map {
                 }
                 CPPUNIT_ASSERT( check_size( m, 500 ));
 
+                {
+                    typename Map::iterator it( m.begin() );
+                    typename Map::const_iterator cit( m.cbegin() );
+                    CPPUNIT_CHECK( it == cit );
+                    CPPUNIT_CHECK( it != m.end() );
+                    CPPUNIT_CHECK( it != m.cend() );
+                    CPPUNIT_CHECK( cit != m.end() );
+                    CPPUNIT_CHECK( cit != m.cend() );
+                    ++it;
+                    CPPUNIT_CHECK( it != cit );
+                    CPPUNIT_CHECK( it != m.end() );
+                    CPPUNIT_CHECK( it != m.cend() );
+                    CPPUNIT_CHECK( cit != m.end() );
+                    CPPUNIT_CHECK( cit != m.cend() );
+                    ++cit;
+                    CPPUNIT_CHECK( it == cit );
+                    CPPUNIT_CHECK( it != m.end() );
+                    CPPUNIT_CHECK( it != m.cend() );
+                    CPPUNIT_CHECK( cit != m.end() );
+                    CPPUNIT_CHECK( cit != m.cend() );
+                }
+
+
                 for ( iterator it = m.begin(), itEnd = m.end(); it != itEnd; ++it ) {
+                    iterator it2 = it;
+                    CPPUNIT_CHECK( it2 == it );
+                    CPPUNIT_CHECK( it2 == itEnd );
                     CPPUNIT_ASSERT( it->first * 2 == (*it).second.m_val );
                     it->second = it->first;
                 }
@@ -608,6 +634,28 @@ namespace map {
                 CPPUNIT_ASSERT( s.insert( i, i * 2 ));
             }
 
+            {
+                typename Map::iterator it( s.begin() );
+                typename Map::const_iterator cit( s.cbegin() );
+                CPPUNIT_CHECK( it == cit );
+                CPPUNIT_CHECK( it != s.end() );
+                CPPUNIT_CHECK( it != s.cend() );
+                CPPUNIT_CHECK( cit != s.end() );
+                CPPUNIT_CHECK( cit != s.cend() );
+                ++it;
+                CPPUNIT_CHECK( it != cit );
+                CPPUNIT_CHECK( it != s.end() );
+                CPPUNIT_CHECK( it != s.cend() );
+                CPPUNIT_CHECK( cit != s.end() );
+                CPPUNIT_CHECK( cit != s.cend() );
+                ++cit;
+                CPPUNIT_CHECK( it == cit );
+                CPPUNIT_CHECK( it != s.end() );
+                CPPUNIT_CHECK( it != s.cend() );
+                CPPUNIT_CHECK( cit != s.end() );
+                CPPUNIT_CHECK( cit != s.cend() );
+            }
+
             int nCount = 0;
             for ( iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) {
                 CPPUNIT_ASSERT( it->first * 2 == it->second.m_val );
index 2c910c90e884fcca7c779ea0912e8deee7120534..76198cd69e49c480cb5d05cd2844aaa83d78ae0c 100644 (file)
@@ -386,7 +386,13 @@ namespace ordlist {
                 // Iterator test
                 {
                     typename OrdList::iterator it = l.begin();
+                    typename OrdList::const_iterator cit = l.cbegin();
                     CPPUNIT_ASSERT( it != l.end() );
+                    CPPUNIT_ASSERT( it != l.cend() );
+                    CPPUNIT_ASSERT( cit != l.end() );
+                    CPPUNIT_ASSERT( cit != l.cend() );
+                    CPPUNIT_ASSERT( cit == it );
+
                     CPPUNIT_ASSERT( it->nKey == v2.nKey );
                     CPPUNIT_ASSERT( it->nVal == v2.nVal );
                     CPPUNIT_ASSERT( ++it != l.end() );
@@ -689,7 +695,13 @@ namespace ordlist {
 
                     {
                         typename OrdList::iterator it = l.begin();
+                        typename OrdList::const_iterator cit = l.cbegin();
                         CPPUNIT_ASSERT( it != l.end() );
+                        CPPUNIT_ASSERT( it != l.cend() );
+                        CPPUNIT_ASSERT( cit != l.end() );
+                        CPPUNIT_ASSERT( cit != l.cend() );
+                        CPPUNIT_ASSERT( cit == it );
+
                         CPPUNIT_ASSERT( it->nKey == v2.nKey );
                         CPPUNIT_ASSERT( it->nVal == v2.nVal );
                         CPPUNIT_ASSERT( ++it != l.end() );
index 557f43961770eaf8cf91bb4279d7792cd47bbc06..c1d3049c8258833fe3f711acba1316e1b14982c1 100644 (file)
@@ -388,7 +388,13 @@ namespace ordlist {
                 // begin/end
                 {
                     typename OrdList::iterator it = l.begin();
+                    typename OrdList::const_iterator cit = l.cbegin();
                     CPPUNIT_ASSERT( it != l.end() );
+                    CPPUNIT_ASSERT( it != l.cend() );
+                    CPPUNIT_ASSERT( cit != l.end() );
+                    CPPUNIT_ASSERT( cit != l.cend() );
+                    CPPUNIT_ASSERT( cit == it );
+
                     CPPUNIT_ASSERT( it->nKey == v2.nKey );
                     CPPUNIT_ASSERT( it->nVal == v2.nVal );
                     CPPUNIT_ASSERT( ++it != l.end() );
@@ -707,7 +713,13 @@ namespace ordlist {
 
                     {
                         typename OrdList::iterator it = l.begin();
+                        typename OrdList::const_iterator cit = l.cbegin();
                         CPPUNIT_ASSERT( it != l.end() );
+                        CPPUNIT_ASSERT( it != l.cend() );
+                        CPPUNIT_ASSERT( cit != l.end() );
+                        CPPUNIT_ASSERT( cit != l.cend() );
+                        CPPUNIT_ASSERT( cit == it );
+
                         CPPUNIT_ASSERT( it->nKey == v2.nKey );
                         CPPUNIT_ASSERT( it->nVal == v2.nVal );
                         CPPUNIT_ASSERT( ++it != l.end() );
index bbaac65812f770f409fdab7adfb26839da28b1f3..fef2592b94680fc30989d35a1e896a88403ce44b 100644 (file)
@@ -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 ) {
@@ -669,6 +691,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() );
         }
index ccbd71174f9350129db8398fa03a6b3d92a95a1e..1aef413f2a665abe7abaad2ff04246e7723653ba 100644 (file)
@@ -215,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 );
@@ -537,6 +559,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 );
index 3036a5578f332549bf5d2083dc1260eedb469a51..b612cbbdbce84d1c513d2bf2e2ec16eb3be16d8e 100644 (file)
@@ -392,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;
@@ -670,6 +692,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() );
         }
index 1093774caa6cc0432483a0ee4b6ea597093d4cb7..24f77f4f2b7b782c93489f1b52ebd9b79757d231 100644 (file)
@@ -215,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 );
@@ -548,6 +570,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 );
index a6345126370ed3c7713137bee640676a3b611e5f..e58bbd61764133254b16fc7682c228a9b9b0cf28 100644 (file)
@@ -564,8 +564,33 @@ namespace set {
                     CPPUNIT_ASSERT( s.insert( v[i] ));
                 }
 
+                {
+                    typename Set::iterator it( s.begin() );
+                    typename Set::const_iterator cit( s.cbegin() );
+                    CPPUNIT_CHECK( it == cit );
+                    CPPUNIT_CHECK( it != s.end() );
+                    CPPUNIT_CHECK( it != s.cend() );
+                    CPPUNIT_CHECK( cit != s.end() );
+                    CPPUNIT_CHECK( cit != s.cend() );
+                    ++it;
+                    CPPUNIT_CHECK( it != cit );
+                    CPPUNIT_CHECK( it != s.end() );
+                    CPPUNIT_CHECK( it != s.cend() );
+                    CPPUNIT_CHECK( cit != s.end() );
+                    CPPUNIT_CHECK( cit != s.cend() );
+                    ++cit;
+                    CPPUNIT_CHECK( it == cit );
+                    CPPUNIT_CHECK( it != s.end() );
+                    CPPUNIT_CHECK( it != s.cend() );
+                    CPPUNIT_CHECK( cit != s.end() );
+                    CPPUNIT_CHECK( cit != s.cend() );
+                }
+
                 int nCount = 0;
                 for ( set_iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) {
+                    set_iterator it2 = it;
+                    CPPUNIT_CHECK( it == it2 );
+                    CPPUNIT_CHECK( it2 != itEnd );
                     CPPUNIT_ASSERT( (*it).nKey * 2 == it->nVal );
                     it->nVal = (*it).nKey;
                     ++nCount;
index 81fcaa278e0b01c2ba13d15c80ed63e298c03be2..f7ac01dc8dda1ae043eded04daadaa341795575d 100644 (file)
@@ -776,6 +776,9 @@ namespace set {
                     CPPUNIT_ASSERT( s.insert( std::make_pair( i, i * 2) ) != s.end() );
                 }
                 for ( iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) {
+                    iterator it2 = it;
+                    CPPUNIT_CHECK( it2 == it );
+                    CPPUNIT_CHECK( it2 != itEnd );
                     CPPUNIT_ASSERT( (*it).nKey * 2 == it->nVal );
                     it->nVal = (*it).nKey;
                 }
@@ -800,6 +803,29 @@ namespace set {
             for ( int i = 0; size_t(i) < nMaxCount; ++i ) {
                 CPPUNIT_ASSERT( s.insert( std::make_pair( i, i * 2) ));
             }
+
+            {
+                typename Set::iterator it( s.begin() );
+                typename Set::const_iterator cit( s.cbegin() );
+                CPPUNIT_CHECK( it == cit );
+                CPPUNIT_CHECK( it != s.end() );
+                CPPUNIT_CHECK( it != s.cend() );
+                CPPUNIT_CHECK( cit != s.end() );
+                CPPUNIT_CHECK( cit != s.cend() );
+                ++it;
+                CPPUNIT_CHECK( it != cit );
+                CPPUNIT_CHECK( it != s.end() );
+                CPPUNIT_CHECK( it != s.cend() );
+                CPPUNIT_CHECK( cit != s.end() );
+                CPPUNIT_CHECK( cit != s.cend() );
+                ++cit;
+                CPPUNIT_CHECK( it == cit );
+                CPPUNIT_CHECK( it != s.end() );
+                CPPUNIT_CHECK( it != s.cend() );
+                CPPUNIT_CHECK( cit != s.end() );
+                CPPUNIT_CHECK( cit != s.cend() );
+            }
+
             size_t nCount = 0;
             for ( iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) {
                 CPPUNIT_ASSERT_EX( (*it).nKey * 2 == it->nVal,
index 491d43cb17f1fc0356de6f6cb77304ef73a0c0f1..0933cdf1593e2c648b9f5670ae40886fc43f435d 100644 (file)
@@ -59,6 +59,17 @@ namespace map2 {
             std::random_shuffle( m_Arr.begin(), m_Arr.end() );
         }
 
+        template <typename Iterator, typename Map>
+        static bool check_result( Iterator const& it, Map const& map )
+        {
+            return it != map.end();
+        }
+        template <typename Map>
+        static bool check_result( bool b, Map const& )
+        {
+            return b;
+        }
+
         template <class Map>
         class TestThread: public CppUnitMini::TestThread
         {
@@ -110,9 +121,9 @@ namespace map2 {
                     if ( m_nThreadNo & 1 ) {
                         ValueVector::const_iterator itEnd = arr.end();
                         for ( ValueVector::const_iterator it = arr.begin(); it != itEnd; ++it ) {
-                            bool bFound = rMap.find( it->nKey );
+                            auto bFound = rMap.find( it->nKey );
                             if ( it->bExists ) {
-                                if ( bFound )
+                                if ( check_result( bFound, rMap ))
                                     ++m_KeyExists.nSuccess;
                                 else {
                                     //rMap.find( it->nKey );
@@ -120,7 +131,7 @@ namespace map2 {
                                 }
                             }
                             else {
-                                if ( bFound ) {
+                                if ( check_result( bFound, rMap )) {
                                     //rMap.find( it->nKey );
                                     ++m_KeyNotExists.nFailed;
                                 }
@@ -132,9 +143,9 @@ namespace map2 {
                     else {
                         ValueVector::const_reverse_iterator itEnd = arr.rend();
                         for ( ValueVector::const_reverse_iterator it = arr.rbegin(); it != itEnd; ++it ) {
-                            bool bFound = rMap.find( it->nKey );
+                            auto bFound = rMap.find( it->nKey );
                             if ( it->bExists ) {
-                                if ( bFound )
+                                if ( check_result( bFound, rMap ))
                                     ++m_KeyExists.nSuccess;
                                 else {
                                     //rMap.find( it->nKey );
@@ -142,7 +153,7 @@ namespace map2 {
                                 }
                             }
                             else {
-                                if ( bFound ) {
+                                if ( check_result( bFound, rMap )) {
                                     //rMap.find( it->nKey );
                                     ++m_KeyNotExists.nFailed;
                                 }
@@ -168,7 +179,7 @@ namespace map2 {
             timer.reset();
             for ( size_t i = 0; i < m_Arr.size(); ++i ) {
                 if ( m_Arr[i].bExists ) {
-                    CPPUNIT_ASSERT( testMap.insert( m_Arr[i].nKey, m_Arr[i] ) );
+                    CPPUNIT_ASSERT( check_result( testMap.insert( m_Arr[i].nKey, m_Arr[i] ), testMap ));
                 }
             }
             CPPUNIT_MSG( "   Duration=" << timer.duration() );
index 807720b2911e3e35b43d3ac5f14dada73d06b9cd..d4cb0ca73ab77681612fdc57e5a38812c929a9c6 100644 (file)
@@ -10,8 +10,8 @@
 // find int test in map<int> in mutithreaded mode
 namespace map2 {
 
-#    define TEST_MAP(X)         void X() { test<MapTypes<key_type, value_type>::X >()    ; }
-#    define TEST_MAP_NOLF(X)    void X() { test_nolf<MapTypes<key_type, value_type>::X >()    ; }
+#   define TEST_MAP(X)         void X() { test<MapTypes<key_type, value_type>::X >()    ; }
+#   define TEST_MAP_NOLF(X)    void X() { test_nolf<MapTypes<key_type, value_type>::X >()    ; }
 #   define TEST_MAP_EXTRACT(X)  TEST_MAP(X)
 #   define TEST_MAP_NOLF_EXTRACT(X) TEST_MAP_NOLF(X)
 
@@ -37,6 +37,17 @@ namespace map2 {
         size_t                  m_nRealMapSize;
         bool                    m_bSeqInit;
 
+        template <typename Iterator, typename Map>
+        static bool check_result( Iterator const& it, Map const& map )
+        {
+            return it != map.end();
+        }
+        template <typename Map>
+        static bool check_result( bool b, Map const& )
+        {
+            return b;
+        }
+
         template <class MAP>
         class TestThread: public CppUnitMini::TestThread
         {
@@ -88,15 +99,15 @@ namespace map2 {
                     if ( m_nThreadNo & 1 ) {
                         ValueVector::const_iterator itEnd = arr.end();
                         for ( ValueVector::const_iterator it = arr.begin(); it != itEnd; ++it ) {
-                            bool bFound = rMap.find( *(it->pKey) );
+                            auto bFound = rMap.find( *(it->pKey) );
                             if ( it->bExists ) {
-                                if ( bFound )
+                                if ( check_result(bFound, rMap))
                                     ++m_KeyExists.nSuccess;
                                 else
                                     ++m_KeyExists.nFailed;
                             }
                             else {
-                                if ( bFound )
+                                if ( check_result(bFound, rMap))
                                     ++m_KeyNotExists.nFailed;
                                 else
                                     ++m_KeyNotExists.nSuccess;
@@ -106,15 +117,15 @@ namespace map2 {
                     else {
                         ValueVector::const_reverse_iterator itEnd = arr.rend();
                         for ( ValueVector::const_reverse_iterator it = arr.rbegin(); it != itEnd; ++it ) {
-                            bool bFound = rMap.find( *(it->pKey) );
+                            auto bFound = rMap.find( *(it->pKey) );
                             if ( it->bExists ) {
-                                if ( bFound )
+                                if ( check_result(bFound, rMap))
                                     ++m_KeyExists.nSuccess;
                                 else
                                     ++m_KeyExists.nFailed;
                             }
                             else {
-                                if ( bFound )
+                                if ( check_result( bFound, rMap ))
                                     ++m_KeyNotExists.nFailed;
                                 else
                                     ++m_KeyNotExists.nSuccess;
@@ -169,7 +180,7 @@ namespace map2 {
             for ( size_t i = 0; i < m_Arr.size(); ++i ) {
                 // Âñå êëþ÷è â arrData - óíèêàëüíûå, ïîýòîìó îøèáîê ïðè âñòàâêå áûòü íå äîëæíî
                 if ( m_Arr[i].bExists )
-                    CPPUNIT_ASSERT( testMap.insert( *(m_Arr[i].pKey), m_Arr[i] ) );
+                    CPPUNIT_ASSERT( check_result( testMap.insert( *(m_Arr[i].pKey), m_Arr[i] ), testMap ));
             }
             CPPUNIT_MSG( "   Duration=" << timer.duration() );
 
index f9a44a16f8804219a026471cf8aa6b3eec220ce4..95faddffc19240db85a50ca54ae64d9a558f06ab 100644 (file)
@@ -26,6 +26,17 @@ namespace map2 {
         typedef size_t  key_type;
         typedef size_t  value_type;
 
+        template <typename Iterator, typename Map>
+        static bool check_result( Iterator const& it, Map const& map )
+        {
+            return it != map.end();
+        }
+        template <typename Map>
+        static bool check_result( bool b, Map const& )
+        {
+            return b;
+        }
+
         template <class Map>
         class Inserter: public CppUnitMini::TestThread
         {
@@ -86,13 +97,13 @@ namespace map2 {
                 size_t const nArrSize = m_arrVal.size();
                 for ( size_t i = 0; i < nArrSize; ++i ) {
                     size_t const nItem = m_arrVal[i];
-                    if ( rMap.insert( nItem, nItem * 8 ) )
+                    if ( check_result( rMap.insert( nItem, nItem * 8 ), rMap ))
                         ++m_nInsertSuccess;
                     else
                         ++m_nInsertFailed;
 
                     for ( size_t k = 0; k <= i; ++k ) {
-                        if ( rMap.find( m_arrVal[k] ) )
+                        if ( check_result( rMap.find( m_arrVal[k] ), rMap ))
                             ++m_nFindSuccess;
                         else
                             ++m_nFindFail;