From: khizmax Date: Fri, 31 Oct 2014 13:19:29 +0000 (+0300) Subject: Fixed iterator issues in set/map X-Git-Tag: v2.0.0~156 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=commitdiff_plain;h=0594e601c8b1fcf9f8ca595d49ef025be04aa8d1 Fixed iterator issues in set/map --- diff --git a/cds/container/impl/lazy_kvlist.h b/cds/container/impl/lazy_kvlist.h index e1433a51..b71876e4 100644 --- a/cds/container/impl/lazy_kvlist.h +++ b/cds/container/impl/lazy_kvlist.h @@ -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()); } diff --git a/cds/container/impl/lazy_list.h b/cds/container/impl/lazy_list.h index e44fbe42..bc82f5fa 100644 --- a/cds/container/impl/lazy_list.h +++ b/cds/container/impl/lazy_list.h @@ -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() ); } diff --git a/cds/container/impl/michael_kvlist.h b/cds/container/impl/michael_kvlist.h index 7dce75f5..bd82088c 100644 --- a/cds/container/impl/michael_kvlist.h +++ b/cds/container/impl/michael_kvlist.h @@ -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(); } diff --git a/cds/container/impl/michael_list.h b/cds/container/impl/michael_list.h index 17224e31..aa899236 100644 --- a/cds/container/impl/michael_list.h +++ b/cds/container/impl/michael_list.h @@ -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(); } diff --git a/cds/container/impl/skip_list_map.h b/cds/container/impl/skip_list_map.h index 303ea953..2bc344b8 100644 --- a/cds/container/impl/skip_list_map.h +++ b/cds/container/impl/skip_list_map.h @@ -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() ); } diff --git a/cds/container/impl/skip_list_set.h b/cds/container/impl/skip_list_set.h index 83252f80..ee1bb700 100644 --- a/cds/container/impl/skip_list_set.h +++ b/cds/container/impl/skip_list_set.h @@ -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() ); } diff --git a/cds/container/lazy_kvlist_nogc.h b/cds/container/lazy_kvlist_nogc.h index e77a5b42..96e9483a 100644 --- a/cds/container/lazy_kvlist_nogc.h +++ b/cds/container/lazy_kvlist_nogc.h @@ -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()); } diff --git a/cds/container/lazy_kvlist_rcu.h b/cds/container/lazy_kvlist_rcu.h index 218c2bc3..12e7c297 100644 --- a/cds/container/lazy_kvlist_rcu.h +++ b/cds/container/lazy_kvlist_rcu.h @@ -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()); } diff --git a/cds/container/lazy_list_nogc.h b/cds/container/lazy_list_nogc.h index eac78730..bc5d6149 100644 --- a/cds/container/lazy_list_nogc.h +++ b/cds/container/lazy_list_nogc.h @@ -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()); } diff --git a/cds/container/lazy_list_rcu.h b/cds/container/lazy_list_rcu.h index a7fedd31..d35f3184 100644 --- a/cds/container/lazy_list_rcu.h +++ b/cds/container/lazy_list_rcu.h @@ -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() ); } diff --git a/cds/container/michael_kvlist_nogc.h b/cds/container/michael_kvlist_nogc.h index ca1faa03..73215dbe 100644 --- a/cds/container/michael_kvlist_nogc.h +++ b/cds/container/michael_kvlist_nogc.h @@ -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(); } diff --git a/cds/container/michael_kvlist_rcu.h b/cds/container/michael_kvlist_rcu.h index 7783fb8d..420d367c 100644 --- a/cds/container/michael_kvlist_rcu.h +++ b/cds/container/michael_kvlist_rcu.h @@ -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(); } diff --git a/cds/container/michael_list_nogc.h b/cds/container/michael_list_nogc.h index 2f970b94..3812342c 100644 --- a/cds/container/michael_list_nogc.h +++ b/cds/container/michael_list_nogc.h @@ -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(); } diff --git a/cds/container/michael_list_rcu.h b/cds/container/michael_list_rcu.h index 65a8351e..24b6b62f 100644 --- a/cds/container/michael_list_rcu.h +++ b/cds/container/michael_list_rcu.h @@ -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(); } diff --git a/cds/container/michael_map.h b/cds/container/michael_map.h index 285baeb5..1f7291e9 100644 --- a/cds/container/michael_map.h +++ b/cds/container/michael_map.h @@ -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(); } diff --git a/cds/container/michael_map_nogc.h b/cds/container/michael_map_nogc.h index fbeb044e..cfa193e8 100644 --- a/cds/container/michael_map_nogc.h +++ b/cds/container/michael_map_nogc.h @@ -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(); } diff --git a/cds/container/michael_map_rcu.h b/cds/container/michael_map_rcu.h index 5fd03535..ddf7e850 100644 --- a/cds/container/michael_map_rcu.h +++ b/cds/container/michael_map_rcu.h @@ -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(); } diff --git a/cds/container/michael_set.h b/cds/container/michael_set.h index 76e801e9..91c7ef94 100644 --- a/cds/container/michael_set.h +++ b/cds/container/michael_set.h @@ -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(); } diff --git a/cds/container/michael_set_nogc.h b/cds/container/michael_set_nogc.h index 326c602e..bc46d7bc 100644 --- a/cds/container/michael_set_nogc.h +++ b/cds/container/michael_set_nogc.h @@ -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(); } diff --git a/cds/container/michael_set_rcu.h b/cds/container/michael_set_rcu.h index 95ee8fd8..7655ebed 100644 --- a/cds/container/michael_set_rcu.h +++ b/cds/container/michael_set_rcu.h @@ -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(); } diff --git a/cds/container/skip_list_map_nogc.h b/cds/container/skip_list_map_nogc.h index e4146eb9..ce6f85b2 100644 --- a/cds/container/skip_list_map_nogc.h +++ b/cds/container/skip_list_map_nogc.h @@ -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(); } diff --git a/cds/container/skip_list_map_rcu.h b/cds/container/skip_list_map_rcu.h index 2701d0e1..ea14f08c 100644 --- a/cds/container/skip_list_map_rcu.h +++ b/cds/container/skip_list_map_rcu.h @@ -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() ); } diff --git a/cds/container/skip_list_set_nogc.h b/cds/container/skip_list_set_nogc.h index ae83672b..9427f5b2 100644 --- a/cds/container/skip_list_set_nogc.h +++ b/cds/container/skip_list_set_nogc.h @@ -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() ); } diff --git a/cds/container/skip_list_set_rcu.h b/cds/container/skip_list_set_rcu.h index 227a3b80..85bc71ad 100644 --- a/cds/container/skip_list_set_rcu.h +++ b/cds/container/skip_list_set_rcu.h @@ -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() ); } diff --git a/cds/container/split_list_map.h b/cds/container/split_list_map.h index cf560e5d..eef5927a 100644 --- a/cds/container/split_list_map.h +++ b/cds/container/split_list_map.h @@ -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(); } diff --git a/cds/container/split_list_map_nogc.h b/cds/container/split_list_map_nogc.h index 6104f191..b5e03a9e 100644 --- a/cds/container/split_list_map_nogc.h +++ b/cds/container/split_list_map_nogc.h @@ -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(); } diff --git a/cds/container/split_list_map_rcu.h b/cds/container/split_list_map_rcu.h index c18aa9dc..ee395aed 100644 --- a/cds/container/split_list_map_rcu.h +++ b/cds/container/split_list_map_rcu.h @@ -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(); } diff --git a/cds/container/split_list_set.h b/cds/container/split_list_set.h index 5d911109..31ec11ff 100644 --- a/cds/container/split_list_set.h +++ b/cds/container/split_list_set.h @@ -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: diff --git a/cds/container/split_list_set_nogc.h b/cds/container/split_list_set_nogc.h index 49e07c06..62810334 100644 --- a/cds/container/split_list_set_nogc.h +++ b/cds/container/split_list_set_nogc.h @@ -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: diff --git a/cds/container/split_list_set_rcu.h b/cds/container/split_list_set_rcu.h index 14fe8c38..67a5be77 100644 --- a/cds/container/split_list_set_rcu.h +++ b/cds/container/split_list_set_rcu.h @@ -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: diff --git a/cds/intrusive/details/michael_set_base.h b/cds/intrusive/details/michael_set_base.h index 09be328c..c7bfdb28 100644 --- a/cds/intrusive/details/michael_set_base.h +++ b/cds/intrusive/details/michael_set_base.h @@ -93,6 +93,7 @@ namespace cds { namespace intrusive { template 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 operator ==(iterator const& i ) const + bool operator ==(iterator const& i) const { return m_pCurBucket == i.m_pCurBucket && m_itList == i.m_itList; } diff --git a/cds/intrusive/details/split_list_base.h b/cds/intrusive/details/split_list_base.h index a5d52720..3b3abee9 100644 --- a/cds/intrusive/details/split_list_base.h +++ b/cds/intrusive/details/split_list_base.h @@ -775,6 +775,8 @@ namespace cds { namespace intrusive { class iterator_type { typedef OrderedList ordered_list_type; + friend class iterator_type ; + protected: typedef typename select_list_iterator::type list_iterator; typedef NodeTraits node_traits; diff --git a/cds/intrusive/impl/lazy_list.h b/cds/intrusive/impl/lazy_list.h index c485b7ac..ca192390 100644 --- a/cds/intrusive/impl/lazy_list.h +++ b/cds/intrusive/impl/lazy_list.h @@ -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(); } diff --git a/cds/intrusive/impl/michael_list.h b/cds/intrusive/impl/michael_list.h index 2922cb6a..09e5072e 100644 --- a/cds/intrusive/impl/michael_list.h +++ b/cds/intrusive/impl/michael_list.h @@ -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(); } diff --git a/cds/intrusive/impl/skip_list.h b/cds/intrusive/impl/skip_list.h index 4a4c761e..b4b34067 100644 --- a/cds/intrusive/impl/skip_list.h +++ b/cds/intrusive/impl/skip_list.h @@ -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(); } diff --git a/cds/intrusive/lazy_list_nogc.h b/cds/intrusive/lazy_list_nogc.h index 6eb74189..c024d9d9 100644 --- a/cds/intrusive/lazy_list_nogc.h +++ b/cds/intrusive/lazy_list_nogc.h @@ -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( &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(&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( &m_Tail )); + return cend(); + } + const_iterator cend() const + { + return const_iterator( const_cast(&m_Tail) ); } public: diff --git a/cds/intrusive/lazy_list_rcu.h b/cds/intrusive/lazy_list_rcu.h index 1790d2a7..adad3206 100644 --- a/cds/intrusive/lazy_list_rcu.h +++ b/cds/intrusive/lazy_list_rcu.h @@ -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(); } diff --git a/cds/intrusive/michael_list_nogc.h b/cds/intrusive/michael_list_nogc.h index 96ae276e..ca2ca629 100644 --- a/cds/intrusive/michael_list_nogc.h +++ b/cds/intrusive/michael_list_nogc.h @@ -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) ); } diff --git a/cds/intrusive/michael_list_rcu.h b/cds/intrusive/michael_list_rcu.h index 1cd4b662..44d100a6 100644 --- a/cds/intrusive/michael_list_rcu.h +++ b/cds/intrusive/michael_list_rcu.h @@ -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(); } diff --git a/cds/intrusive/michael_set.h b/cds/intrusive/michael_set.h index c6dafa81..8b1bee12 100644 --- a/cds/intrusive/michael_set.h +++ b/cds/intrusive/michael_set.h @@ -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 diff --git a/cds/intrusive/michael_set_nogc.h b/cds/intrusive/michael_set_nogc.h index 983d10c2..9c9ae882 100644 --- a/cds/intrusive/michael_set_nogc.h +++ b/cds/intrusive/michael_set_nogc.h @@ -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 diff --git a/cds/intrusive/michael_set_rcu.h b/cds/intrusive/michael_set_rcu.h index 69695a6a..13fdc347 100644 --- a/cds/intrusive/michael_set_rcu.h +++ b/cds/intrusive/michael_set_rcu.h @@ -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 /** diff --git a/cds/intrusive/skip_list_nogc.h b/cds/intrusive/skip_list_nogc.h index ba4ce746..6326cd11 100644 --- a/cds/intrusive/skip_list_nogc.h +++ b/cds/intrusive/skip_list_nogc.h @@ -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(); } diff --git a/cds/intrusive/skip_list_rcu.h b/cds/intrusive/skip_list_rcu.h index d1c17cfa..4a61dfc8 100644 --- a/cds/intrusive/skip_list_rcu.h +++ b/cds/intrusive/skip_list_rcu.h @@ -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(); } diff --git a/cds/intrusive/split_list.h b/cds/intrusive/split_list.h index 687401de..62166ec5 100644 --- a/cds/intrusive/split_list.h +++ b/cds/intrusive/split_list.h @@ -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() ); } }; diff --git a/cds/intrusive/split_list_nogc.h b/cds/intrusive/split_list_nogc.h index 7e7b4fa5..18e1cc07 100644 --- a/cds/intrusive/split_list_nogc.h +++ b/cds/intrusive/split_list_nogc.h @@ -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() ); } diff --git a/cds/intrusive/split_list_rcu.h b/cds/intrusive/split_list_rcu.h index d21ba0f4..fa3bc86b 100644 --- a/cds/intrusive/split_list_rcu.h +++ b/cds/intrusive/split_list_rcu.h @@ -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() ); } }; diff --git a/tests/test-hdr/map/hdr_map.h b/tests/test-hdr/map/hdr_map.h index 5f96b1b9..f4961e74 100644 --- a/tests/test-hdr/map/hdr_map.h +++ b/tests/test-hdr/map/hdr_map.h @@ -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 ); diff --git a/tests/test-hdr/ordered_list/hdr_intrusive_lazy.h b/tests/test-hdr/ordered_list/hdr_intrusive_lazy.h index 2c910c90..76198cd6 100644 --- a/tests/test-hdr/ordered_list/hdr_intrusive_lazy.h +++ b/tests/test-hdr/ordered_list/hdr_intrusive_lazy.h @@ -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() ); diff --git a/tests/test-hdr/ordered_list/hdr_intrusive_michael.h b/tests/test-hdr/ordered_list/hdr_intrusive_michael.h index 557f4396..c1d3049c 100644 --- a/tests/test-hdr/ordered_list/hdr_intrusive_michael.h +++ b/tests/test-hdr/ordered_list/hdr_intrusive_michael.h @@ -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() ); diff --git a/tests/test-hdr/ordered_list/hdr_lazy.h b/tests/test-hdr/ordered_list/hdr_lazy.h index bbaac658..fef2592b 100644 --- a/tests/test-hdr/ordered_list/hdr_lazy.h +++ b/tests/test-hdr/ordered_list/hdr_lazy.h @@ -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() ); } diff --git a/tests/test-hdr/ordered_list/hdr_lazy_kv.h b/tests/test-hdr/ordered_list/hdr_lazy_kv.h index ccbd7117..1aef413f 100644 --- a/tests/test-hdr/ordered_list/hdr_lazy_kv.h +++ b/tests/test-hdr/ordered_list/hdr_lazy_kv.h @@ -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 ); diff --git a/tests/test-hdr/ordered_list/hdr_michael.h b/tests/test-hdr/ordered_list/hdr_michael.h index 3036a557..b612cbbd 100644 --- a/tests/test-hdr/ordered_list/hdr_michael.h +++ b/tests/test-hdr/ordered_list/hdr_michael.h @@ -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() ); } diff --git a/tests/test-hdr/ordered_list/hdr_michael_kv.h b/tests/test-hdr/ordered_list/hdr_michael_kv.h index 1093774c..24f77f4f 100644 --- a/tests/test-hdr/ordered_list/hdr_michael_kv.h +++ b/tests/test-hdr/ordered_list/hdr_michael_kv.h @@ -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 ); diff --git a/tests/test-hdr/set/hdr_intrusive_set.h b/tests/test-hdr/set/hdr_intrusive_set.h index a6345126..e58bbd61 100644 --- a/tests/test-hdr/set/hdr_intrusive_set.h +++ b/tests/test-hdr/set/hdr_intrusive_set.h @@ -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; diff --git a/tests/test-hdr/set/hdr_set.h b/tests/test-hdr/set/hdr_set.h index 81fcaa27..f7ac01dc 100644 --- a/tests/test-hdr/set/hdr_set.h +++ b/tests/test-hdr/set/hdr_set.h @@ -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, diff --git a/tests/unit/map2/map_find_int.cpp b/tests/unit/map2/map_find_int.cpp index 491d43cb..0933cdf1 100644 --- a/tests/unit/map2/map_find_int.cpp +++ b/tests/unit/map2/map_find_int.cpp @@ -59,6 +59,17 @@ namespace map2 { std::random_shuffle( m_Arr.begin(), m_Arr.end() ); } + template + static bool check_result( Iterator const& it, Map const& map ) + { + return it != map.end(); + } + template + static bool check_result( bool b, Map const& ) + { + return b; + } + template 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() ); diff --git a/tests/unit/map2/map_find_string.cpp b/tests/unit/map2/map_find_string.cpp index 807720b2..d4cb0ca7 100644 --- a/tests/unit/map2/map_find_string.cpp +++ b/tests/unit/map2/map_find_string.cpp @@ -10,8 +10,8 @@ // find int test in map in mutithreaded mode namespace map2 { -# define TEST_MAP(X) void X() { test::X >() ; } -# define TEST_MAP_NOLF(X) void X() { test_nolf::X >() ; } +# define TEST_MAP(X) void X() { test::X >() ; } +# define TEST_MAP_NOLF(X) void X() { test_nolf::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 + static bool check_result( Iterator const& it, Map const& map ) + { + return it != map.end(); + } + template + static bool check_result( bool b, Map const& ) + { + return b; + } + template 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() ); diff --git a/tests/unit/map2/map_insfind_int.cpp b/tests/unit/map2/map_insfind_int.cpp index f9a44a16..95faddff 100644 --- a/tests/unit/map2/map_insfind_int.cpp +++ b/tests/unit/map2/map_insfind_int.cpp @@ -26,6 +26,17 @@ namespace map2 { typedef size_t key_type; typedef size_t value_type; + template + static bool check_result( Iterator const& it, Map const& map ) + { + return it != map.end(); + } + template + static bool check_result( bool b, Map const& ) + { + return b; + } + template 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;