From: khizmax Date: Thu, 23 Apr 2015 19:31:58 +0000 (+0300) Subject: GCC 5 compatibility: std::list::size() O(1) complexity X-Git-Tag: v2.1.0~245^2~16 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=36ea79a115b06c47b80d834315f54a80a1e808cf;p=libcds.git GCC 5 compatibility: std::list::size() O(1) complexity --- diff --git a/cds/container/striped_map/std_list.h b/cds/container/striped_map/std_list.h index eba4c9f5..4e7bdc18 100644 --- a/cds/container/striped_map/std_list.h +++ b/cds/container/striped_map/std_list.h @@ -9,6 +9,11 @@ #include // std::pair #include +#undef CDS_STD_LIST_SIZE_CXX11_CONFORM +#if !( defined(__GLIBCXX__ ) && (!defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI == 0 )) +# define CDS_STD_LIST_SIZE_CXX11_CONFORM +#endif + //@cond namespace cds { namespace container { namespace striped_set { @@ -123,7 +128,7 @@ namespace cds { namespace intrusive { namespace striped_set { private: //@cond container_type m_List; -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) // GCC C++ lib bug: // In GCC (at least up to 4.7.x), the complexity of std::list::size() is O(N) // (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49561) @@ -134,7 +139,7 @@ namespace cds { namespace intrusive { namespace striped_set { public: adapted_container() -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) : m_nSize(0) # endif {} @@ -148,7 +153,7 @@ namespace cds { namespace intrusive { namespace striped_set { it = m_List.insert( it, value_type( key, mapped_type()) ); f( *it ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) ++m_nSize; # endif return true; @@ -166,7 +171,7 @@ namespace cds { namespace intrusive { namespace striped_set { //value_type newItem( key ); it = m_List.emplace( it, value_type( std::forward(key), std::move( mapped_type( std::forward(args)...) )) ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) ++m_nSize; # endif return true; @@ -183,7 +188,7 @@ namespace cds { namespace intrusive { namespace striped_set { value_type newItem( key, mapped_type() ); it = m_List.insert( it, newItem ); func( true, *it ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) ++m_nSize; # endif return std::make_pair( true, true ); @@ -205,7 +210,7 @@ namespace cds { namespace intrusive { namespace striped_set { // key exists f( *it ); m_List.erase( it ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) --m_nSize; # endif @@ -222,7 +227,7 @@ namespace cds { namespace intrusive { namespace striped_set { // key exists f( *it ); m_List.erase( it ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) --m_nSize; # endif @@ -269,14 +274,14 @@ namespace cds { namespace intrusive { namespace striped_set { assert( it == m_List.end() || key_comparator()( itWhat->first, it->first ) != 0 ); copy_item()( m_List, it, itWhat ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) ++m_nSize; # endif } size_t size() const { -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) return m_nSize; # else return m_List.size(); diff --git a/cds/container/striped_set/std_list.h b/cds/container/striped_set/std_list.h index 05a239f2..b0788c3b 100644 --- a/cds/container/striped_set/std_list.h +++ b/cds/container/striped_set/std_list.h @@ -8,6 +8,11 @@ #include // std::lower_bound #include +#undef CDS_STD_LIST_SIZE_CXX11_CONFORM +#if !( defined(__GLIBCXX__ ) && (!defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI == 0 )) +# define CDS_STD_LIST_SIZE_CXX11_CONFORM +#endif + //@cond namespace cds { namespace container { namespace striped_set { @@ -117,7 +122,7 @@ namespace cds { namespace intrusive { namespace striped_set { private: //@cond container_type m_List; -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) // GCC C++ lib bug: // In GCC, the complexity of std::list::size() is O(N) // (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49561) @@ -128,7 +133,7 @@ namespace cds { namespace intrusive { namespace striped_set { public: adapted_container() -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) : m_nSize(0) # endif {} @@ -142,7 +147,7 @@ namespace cds { namespace intrusive { namespace striped_set { it = m_List.insert( it, newItem ); f( *it ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) ++m_nSize; # endif return true; @@ -159,7 +164,7 @@ namespace cds { namespace intrusive { namespace striped_set { iterator it = std::lower_bound( m_List.begin(), m_List.end(), val, find_predicate() ); if ( it == m_List.end() || key_comparator()( val, *it ) != 0 ) { it = m_List.emplace( it, std::move( val ) ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) ++m_nSize; # endif return true; @@ -176,7 +181,7 @@ namespace cds { namespace intrusive { namespace striped_set { value_type newItem( val ); it = m_List.insert( it, newItem ); func( true, *it, val ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) ++m_nSize; # endif return std::make_pair( true, true ); @@ -198,7 +203,7 @@ namespace cds { namespace intrusive { namespace striped_set { // key exists f( *it ); m_List.erase( it ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) --m_nSize; # endif @@ -215,7 +220,7 @@ namespace cds { namespace intrusive { namespace striped_set { // key exists f( *it ); m_List.erase( it ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) --m_nSize; # endif @@ -263,14 +268,14 @@ namespace cds { namespace intrusive { namespace striped_set { assert( it == m_List.end() || key_comparator()( *itWhat, *it ) != 0 ); copy_item()( m_List, it, itWhat ); -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) ++m_nSize; # endif } size_t size() const { -# if defined(__GLIBCXX__ ) && !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 50000 ) +# if !defined(CDS_STD_LIST_SIZE_CXX11_CONFORM) return m_nSize; # else return m_List.size();