From 36606fed48807c8fabb9f2c968a18ff2e4b6daae Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 1 Nov 2014 15:50:17 +0300 Subject: [PATCH] Add some magic to satisfy Intel C++ compiler on boost::intrusive adapters --- cds/intrusive/striped_set/boost_avl_set.h | 14 +- cds/intrusive/striped_set/boost_list.h | 311 ++++++++-------- cds/intrusive/striped_set/boost_set.h | 14 +- cds/intrusive/striped_set/boost_sg_set.h | 13 +- cds/intrusive/striped_set/boost_slist.h | 349 +++++++++--------- cds/intrusive/striped_set/boost_splay_set.h | 17 +- cds/intrusive/striped_set/boost_treap_set.h | 17 +- .../striped_set/boost_unordered_set.h | 296 ++++++++------- 8 files changed, 569 insertions(+), 462 deletions(-) diff --git a/cds/intrusive/striped_set/boost_avl_set.h b/cds/intrusive/striped_set/boost_avl_set.h index 82ce92ed..b83aea46 100644 --- a/cds/intrusive/striped_set/boost_avl_set.h +++ b/cds/intrusive/striped_set/boost_avl_set.h @@ -9,6 +9,17 @@ //@cond namespace cds { namespace intrusive { namespace striped_set { +#if CDS_COMPILER == CDS_COMPILER_INTEL && CDS_COMPILER_VERSION <= 1500 + template + class adapt< boost::intrusive::avl_set< T, P1, P2, P3, P4, P5 >, Options... > + { + public: + typedef boost::intrusive::avl_set< T > container_type; ///< underlying intrusive container type + + public: + typedef details::boost_intrusive_set_adapter type; ///< Result of the metafunction + }; +#else template class adapt< boost::intrusive::avl_set< T, BIOptons... >, Options... > { @@ -17,8 +28,9 @@ namespace cds { namespace intrusive { namespace striped_set { public: typedef details::boost_intrusive_set_adapter type ; ///< Result of the metafunction - }; +#endif + }}} // namespace cds::intrusive::striped_set //@endcond diff --git a/cds/intrusive/striped_set/boost_list.h b/cds/intrusive/striped_set/boost_list.h index c0b34001..56a1c93b 100644 --- a/cds/intrusive/striped_set/boost_list.h +++ b/cds/intrusive/striped_set/boost_list.h @@ -9,189 +9,204 @@ //@cond namespace cds { namespace intrusive { namespace striped_set { - template - class adapt< boost::intrusive::list< T, BIOptons... >, Options... > - { - public: - typedef boost::intrusive::list< T, BIOptons... > container_type ; ///< underlying intrusive container type - - private: - /// Adapted intrusive container - class adapted_container: public cds::intrusive::striped_set::adapted_sequential_container + namespace details { + template + class adapt_boost_list { public: - typedef typename container_type::value_type value_type ; ///< value type stored in the container - typedef typename container_type::iterator iterator ; ///< container iterator - typedef typename container_type::const_iterator const_iterator ; ///< container const iterator - typedef typename cds::opt::details::make_comparator_from_option_list< value_type, Options... >::type key_comparator; + typedef List container_type; ///< underlying intrusive container type private: - struct find_predicate + /// Adapted intrusive container + class adapted_container : public cds::intrusive::striped_set::adapted_sequential_container { - bool operator()( value_type const& i1, value_type const& i2) const + public: + typedef typename container_type::value_type value_type; ///< value type stored in the container + typedef typename container_type::iterator iterator; ///< container iterator + typedef typename container_type::const_iterator const_iterator; ///< container const iterator + typedef typename cds::opt::details::make_comparator_from_option_list< value_type, Options... >::type key_comparator; + + private: + struct find_predicate { - return key_comparator()( i1, i2 ) < 0; - } - - template - bool operator()( Q const& i1, value_type const& i2) const + bool operator()( value_type const& i1, value_type const& i2 ) const + { + return key_comparator()(i1, i2) < 0; + } + + template + bool operator()( Q const& i1, value_type const& i2 ) const + { + return key_comparator()(i1, i2) < 0; + } + + template + bool operator()( value_type const& i1, Q const& i2 ) const + { + return key_comparator()(i1, i2) < 0; + } + }; + + template + iterator find_key( Q const& key, Pred pred ) { - return key_comparator()( i1, i2 ) < 0; + iterator itEnd = m_List.end(); + iterator it; + for ( it = m_List.begin(); it != itEnd; ++it ) { + if ( !pred( *it, key ) ) + break; + } + return it; } - template - bool operator()( value_type const& i1, Q const& i2) const - { - return key_comparator()( i1, i2 ) < 0; - } - }; + private: + container_type m_List; - template - iterator find_key( Q const& key, Pred pred) - { - iterator itEnd = m_List.end(); - iterator it; - for ( it = m_List.begin(); it != itEnd; ++it ) { - if ( !pred( *it, key ) ) - break; - } - return it; - } + public: + adapted_container() + {} - private: - container_type m_List; + container_type& base_container() + { + return m_List; + } - public: - adapted_container() - {} + template + bool insert( value_type& val, Func f ) + { + iterator it = find_key( val, find_predicate() ); + if ( it == m_List.end() || key_comparator()(val, *it) != 0 ) { + m_List.insert( it, val ); + f( val ); - container_type& base_container() - { - return m_List; - } + return true; + } - template - bool insert( value_type& val, Func f ) - { - iterator it = find_key( val, find_predicate() ); - if ( it == m_List.end() || key_comparator()( val, *it ) != 0 ) { - m_List.insert( it, val ); - f( val ); - - return true; + // key already exists + return false; } - // key already exists - return false; - } - - template - std::pair ensure( value_type& val, Func f ) - { - iterator it = find_key( val, find_predicate() ); - if ( it == m_List.end() || key_comparator()( val, *it ) != 0 ) { - // insert new - m_List.insert( it, val ); - f( true, val, val ); - return std::make_pair( true, true ); - } - else { - // already exists - f( false, *it, val ); - return std::make_pair( true, false ); + template + std::pair ensure( value_type& val, Func f ) + { + iterator it = find_key( val, find_predicate() ); + if ( it == m_List.end() || key_comparator()(val, *it) != 0 ) { + // insert new + m_List.insert( it, val ); + f( true, val, val ); + return std::make_pair( true, true ); + } + else { + // already exists + f( false, *it, val ); + return std::make_pair( true, false ); + } } - } - bool unlink( value_type& val ) - { - iterator it = find_key( val, find_predicate() ); - if ( it == m_List.end() || &(*it) != &val ) - return false; + bool unlink( value_type& val ) + { + iterator it = find_key( val, find_predicate() ); + if ( it == m_List.end() || &(*it) != &val ) + return false; - m_List.erase( it ); - return true; - } + m_List.erase( it ); + return true; + } - template - value_type * erase( Q const& key, Func f ) - { - iterator it = find_key( key, find_predicate() ); - if ( it == m_List.end() || key_comparator()( key, *it ) != 0 ) - return nullptr; + template + value_type * erase( Q const& key, Func f ) + { + iterator it = find_key( key, find_predicate() ); + if ( it == m_List.end() || key_comparator()(key, *it) != 0 ) + return nullptr; - // key exists - value_type& val = *it; - f( val ); - m_List.erase( it ); + // key exists + value_type& val = *it; + f( val ); + m_List.erase( it ); - return &val; - } + return &val; + } - template - value_type * erase( Q const& key, Less pred, Func f ) - { - iterator it = find_key( key, pred ); - if ( it == m_List.end() || pred( key, *it ) || pred( *it, key ) ) - return nullptr; + template + value_type * erase( Q const& key, Less pred, Func f ) + { + iterator it = find_key( key, pred ); + if ( it == m_List.end() || pred( key, *it ) || pred( *it, key ) ) + return nullptr; - // key exists - value_type& val = *it; - f( val ); - m_List.erase( it ); + // key exists + value_type& val = *it; + f( val ); + m_List.erase( it ); - return &val; - } + return &val; + } - template - bool find( Q& key, Func f ) - { - return find( key, find_predicate(), f ); - } + template + bool find( Q& key, Func f ) + { + return find( key, find_predicate(), f ); + } - template - bool find( Q& key, Less pred, Func f ) - { - iterator it = find_key( key, pred ); - if ( it == m_List.end() || pred( key, *it ) || pred( *it, key )) - return false; + template + bool find( Q& key, Less pred, Func f ) + { + iterator it = find_key( key, pred ); + if ( it == m_List.end() || pred( key, *it ) || pred( *it, key ) ) + return false; - // key exists - f( *it, key ); - return true; - } + // key exists + f( *it, key ); + return true; + } - void clear() - { - m_List.clear(); - } + void clear() + { + m_List.clear(); + } - template - void clear( Disposer disposer ) - { - m_List.clear_and_dispose( disposer ); - } + template + void clear( Disposer disposer ) + { + m_List.clear_and_dispose( disposer ); + } - iterator begin() { return m_List.begin(); } - const_iterator begin() const { return m_List.begin(); } - iterator end() { return m_List.end(); } - const_iterator end() const { return m_List.end(); } + iterator begin() { return m_List.begin(); } + const_iterator begin() const { return m_List.begin(); } + iterator end() { return m_List.end(); } + const_iterator end() const { return m_List.end(); } - size_t size() const - { - return (size_t) m_List.size(); - } + size_t size() const + { + return (size_t)m_List.size(); + } - void move_item( adapted_container& from, iterator itWhat ) - { - value_type& val = *itWhat; - from.base_container().erase( itWhat ); - insert( val, []( value_type& ) {} ); - } + void move_item( adapted_container& from, iterator itWhat ) + { + value_type& val = *itWhat; + from.base_container().erase( itWhat ); + insert( val, []( value_type& ) {} ); + } + }; + public: + typedef adapted_container type; ///< Result of the metafunction }; - public: - typedef adapted_container type ; ///< Result of the metafunction - }; + } // namespace details + +#if CDS_COMPILER == CDS_COMPILER_INTEL && CDS_COMPILER_VERSION <= 1500 + template + class adapt< boost::intrusive::list< T, P1, P2, P3, P4 >, Options... > + : public details::adapt_boost_list< boost::intrusive::list< T, P1, P2, P3, P4 >, Options... > + {}; +#else + template + class adapt< boost::intrusive::list< T, BIOptions... >, Options... > + : public details::adapt_boost_list< boost::intrusive::list< T, BIOptions... >, Options... > + {}; +#endif + }}} // namespace cds::intrusive::striped_set //@endcond diff --git a/cds/intrusive/striped_set/boost_set.h b/cds/intrusive/striped_set/boost_set.h index a92b6901..6f467dd0 100644 --- a/cds/intrusive/striped_set/boost_set.h +++ b/cds/intrusive/striped_set/boost_set.h @@ -9,6 +9,17 @@ //@cond namespace cds { namespace intrusive { namespace striped_set { +#if CDS_COMPILER == CDS_COMPILER_INTEL && CDS_COMPILER_VERSION <= 1500 + template + class adapt< boost::intrusive::set< T, O1, O2, O3, O4 >, Options... > + { + public: + typedef boost::intrusive::set< T, O1, O2, O3, O4 > container_type; ///< underlying intrusive container type + + public: + typedef details::boost_intrusive_set_adapter type; ///< Result of the metafunction + }; +#else template class adapt< boost::intrusive::set< T, BIOptons... >, Options... > { @@ -17,8 +28,9 @@ namespace cds { namespace intrusive { namespace striped_set { public: typedef details::boost_intrusive_set_adapter type ; ///< Result of the metafunction - }; +#endif + }}} // namespace cds::intrusive::striped_set //@endcond diff --git a/cds/intrusive/striped_set/boost_sg_set.h b/cds/intrusive/striped_set/boost_sg_set.h index b924bca6..8cc78dde 100644 --- a/cds/intrusive/striped_set/boost_sg_set.h +++ b/cds/intrusive/striped_set/boost_sg_set.h @@ -9,6 +9,17 @@ //@cond namespace cds { namespace intrusive { namespace striped_set { +#if CDS_COMPILER == CDS_COMPILER_INTEL && CDS_COMPILER_VERSION <= 1500 + template + class adapt< boost::intrusive::sg_set< T, O1, O2, O3, O4 >, Options... > + { + public: + typedef boost::intrusive::sg_set< T, O1, O2, O3, O4 > container_type; ///< underlying intrusive container type + + public: + typedef details::boost_intrusive_set_adapter type; ///< Result of the metafunction + }; +#else template class adapt< boost::intrusive::sg_set< T, BIOptons... >, Options... > { @@ -17,8 +28,8 @@ namespace cds { namespace intrusive { namespace striped_set { public: typedef details::boost_intrusive_set_adapter type ; ///< Result of the metafunction - }; +#endif }}} // namespace cds::intrusive::striped_set //@endcond diff --git a/cds/intrusive/striped_set/boost_slist.h b/cds/intrusive/striped_set/boost_slist.h index 65680fea..518372a0 100644 --- a/cds/intrusive/striped_set/boost_slist.h +++ b/cds/intrusive/striped_set/boost_slist.h @@ -9,205 +9,220 @@ //@cond namespace cds { namespace intrusive { namespace striped_set { - template - class adapt< boost::intrusive::slist< T, BIOptons... >, Options... > - { - public: - typedef boost::intrusive::slist< T, BIOptons... > container_type ; ///< underlying intrusive container type - - private: - /// Adapted intrusive container - class adapted_container: public cds::intrusive::striped_set::adapted_sequential_container + namespace details { + template + class adapt_boost_slist< List, Options... > { public: - typedef typename container_type::value_type value_type ; ///< value type stored in the container - typedef typename container_type::iterator iterator ; ///< container iterator - typedef typename container_type::const_iterator const_iterator ; ///< container const iterator - - typedef typename cds::opt::details::make_comparator_from_option_list< value_type, Options... >::type key_comparator; + typedef List container_type; ///< underlying intrusive container type private: + /// Adapted intrusive container + class adapted_container : public cds::intrusive::striped_set::adapted_sequential_container + { + public: + typedef typename container_type::value_type value_type; ///< value type stored in the container + typedef typename container_type::iterator iterator; ///< container iterator + typedef typename container_type::const_iterator const_iterator; ///< container const iterator + + typedef typename cds::opt::details::make_comparator_from_option_list< value_type, Options... >::type key_comparator; + + private: + + template + std::pair< iterator, bool > find_prev_item( Q const& key, Less pred ) + { + iterator itPrev = m_List.before_begin(); + iterator itEnd = m_List.end(); + for ( iterator it = m_List.begin(); it != itEnd; ++it ) { + if ( pred( key, *it ) ) + itPrev = it; + else if ( pred( *it, key ) ) + break; + else + return std::make_pair( itPrev, true ); + } + return std::make_pair( itPrev, false ); + } - template - std::pair< iterator, bool > find_prev_item( Q const& key, Less pred ) - { - iterator itPrev = m_List.before_begin(); - iterator itEnd = m_List.end(); - for ( iterator it = m_List.begin(); it != itEnd; ++it ) { - if ( pred( key, *it ) ) - itPrev = it; - else if ( pred( *it, key ) ) - break; - else - return std::make_pair( itPrev, true ); - } - return std::make_pair( itPrev, false ); - } - - template - std::pair< iterator, bool > find_prev_item( Q const& key ) - { - return find_prev_item_cmp( key, key_comparator() ); - } + template + std::pair< iterator, bool > find_prev_item( Q const& key ) + { + return find_prev_item_cmp( key, key_comparator() ); + } - template - std::pair< iterator, bool > find_prev_item_cmp( Q const& key, Compare cmp ) - { - iterator itPrev = m_List.before_begin(); - iterator itEnd = m_List.end(); - for ( iterator it = m_List.begin(); it != itEnd; ++it ) { - int nCmp = cmp( key, *it ); - if ( nCmp < 0 ) - itPrev = it; - else if ( nCmp > 0 ) - break; - else - return std::make_pair( itPrev, true ); - } - return std::make_pair( itPrev, false ); - } - - template - value_type * erase_( Q const& key, Compare cmp, Func f ) - { - std::pair< iterator, bool > pos = find_prev_item_cmp( key, cmp ); - if ( !pos.second ) - return nullptr; + template + std::pair< iterator, bool > find_prev_item_cmp( Q const& key, Compare cmp ) + { + iterator itPrev = m_List.before_begin(); + iterator itEnd = m_List.end(); + for ( iterator it = m_List.begin(); it != itEnd; ++it ) { + int nCmp = cmp( key, *it ); + if ( nCmp < 0 ) + itPrev = it; + else if ( nCmp > 0 ) + break; + else + return std::make_pair( itPrev, true ); + } + return std::make_pair( itPrev, false ); + } - // key exists - iterator it = pos.first; - value_type& val = *(++it); - f( val ); - m_List.erase_after( pos.first ); + template + value_type * erase_( Q const& key, Compare cmp, Func f ) + { + std::pair< iterator, bool > pos = find_prev_item_cmp( key, cmp ); + if ( !pos.second ) + return nullptr; - return &val; - } + // key exists + iterator it = pos.first; + value_type& val = *(++it); + f( val ); + m_List.erase_after( pos.first ); - private: - container_type m_List; + return &val; + } - public: - adapted_container() - {} + private: + container_type m_List; - container_type& base_container() - { - return m_List; - } + public: + adapted_container() + {} - template - bool insert( value_type& val, Func f ) - { - std::pair< iterator, bool > pos = find_prev_item( val ); - if ( !pos.second ) { - m_List.insert_after( pos.first, val ); - f( val ); - return true; + container_type& base_container() + { + return m_List; } - // key already exists - return false; - } - - template - std::pair ensure( value_type& val, Func f ) - { - std::pair< iterator, bool > pos = find_prev_item( val ); - if ( !pos.second ) { - // insert new - m_List.insert_after( pos.first, val ); - f( true, val, val ); - return std::make_pair( true, true ); + template + bool insert( value_type& val, Func f ) + { + std::pair< iterator, bool > pos = find_prev_item( val ); + if ( !pos.second ) { + m_List.insert_after( pos.first, val ); + f( val ); + return true; + } + + // key already exists + return false; } - else { - // already exists - f( false, *(++pos.first), val ); - return std::make_pair( true, false ); + + template + std::pair ensure( value_type& val, Func f ) + { + std::pair< iterator, bool > pos = find_prev_item( val ); + if ( !pos.second ) { + // insert new + m_List.insert_after( pos.first, val ); + f( true, val, val ); + return std::make_pair( true, true ); + } + else { + // already exists + f( false, *(++pos.first), val ); + return std::make_pair( true, false ); + } } - } - bool unlink( value_type& val ) - { - std::pair< iterator, bool > pos = find_prev_item( val ); - if ( !pos.second ) - return false; + bool unlink( value_type& val ) + { + std::pair< iterator, bool > pos = find_prev_item( val ); + if ( !pos.second ) + return false; - ++pos.first; - if ( &(*pos.first) != &val ) - return false; + ++pos.first; + if ( &(*pos.first) != &val ) + return false; - m_List.erase( pos.first ); - return true; - } + m_List.erase( pos.first ); + return true; + } - template - value_type * erase( Q const& key, Func f ) - { - return erase_( key, key_comparator(), f ); - } + template + value_type * erase( Q const& key, Func f ) + { + return erase_( key, key_comparator(), f ); + } - template - value_type * erase( Q const& key, Less pred, Func f ) - { - return erase_( key, cds::opt::details::make_comparator_from_less(), f ); - } + template + value_type * erase( Q const& key, Less pred, Func f ) + { + return erase_( key, cds::opt::details::make_comparator_from_less(), f ); + } - template - bool find( Q& key, Func f ) - { - std::pair< iterator, bool > pos = find_prev_item( key ); - if ( !pos.second ) - return false; + template + bool find( Q& key, Func f ) + { + std::pair< iterator, bool > pos = find_prev_item( key ); + if ( !pos.second ) + return false; - // key exists - f( *(++pos.first), key ); - return true; - } + // key exists + f( *(++pos.first), key ); + return true; + } - template - bool find( Q& key, Less pred, Func f ) - { - std::pair< iterator, bool > pos = find_prev_item( key, pred ); - if ( !pos.second ) - return false; + template + bool find( Q& key, Less pred, Func f ) + { + std::pair< iterator, bool > pos = find_prev_item( key, pred ); + if ( !pos.second ) + return false; - // key exists - f( *(++pos.first), key ); - return true; - } + // key exists + f( *(++pos.first), key ); + return true; + } - void clear() - { - m_List.clear(); - } + void clear() + { + m_List.clear(); + } - template - void clear( Disposer disposer ) - { - m_List.clear_and_dispose( disposer ); - } + template + void clear( Disposer disposer ) + { + m_List.clear_and_dispose( disposer ); + } - iterator begin() { return m_List.begin(); } - const_iterator begin() const { return m_List.begin(); } - iterator end() { return m_List.end(); } - const_iterator end() const { return m_List.end(); } + iterator begin() { return m_List.begin(); } + const_iterator begin() const { return m_List.begin(); } + iterator end() { return m_List.end(); } + const_iterator end() const { return m_List.end(); } - size_t size() const - { - return (size_t) m_List.size(); - } + size_t size() const + { + return (size_t)m_List.size(); + } - void move_item( adapted_container& from, iterator itWhat ) - { - value_type& val = *itWhat; - from.base_container().erase( itWhat ); - insert( val, []( value_type& ) {} ); - } + void move_item( adapted_container& from, iterator itWhat ) + { + value_type& val = *itWhat; + from.base_container().erase( itWhat ); + insert( val, []( value_type& ) {} ); + } + }; + public: + typedef adapted_container type; ///< Result of the metafunction }; - public: - typedef adapted_container type ; ///< Result of the metafunction - }; + } // namespace details + +#if CDS_COMPILER == CDS_COMPILER_INTEL && CDS_COMPILER_VERSION <= 1500 + template + class adapt< boost::intrusive::slist< T, P1, P2, P3, P4, P5 >, Options... > + : public details::adapt_boost_slist< boost::intrusive::slist< T, P1, P2, P3, P4, P5 >, Options... > + {}; +#else + template + class adapt< boost::intrusive::slist< T, BIOptions... >, Options... > + : public details::adapt_boost_slist< boost::intrusive::slist< T, BIOptions... >, Options... > + {}; +#endif + }}} // namespace cds::intrusive::striped_set //@endcond diff --git a/cds/intrusive/striped_set/boost_splay_set.h b/cds/intrusive/striped_set/boost_splay_set.h index 0bd769ff..ad2d1bf7 100644 --- a/cds/intrusive/striped_set/boost_splay_set.h +++ b/cds/intrusive/striped_set/boost_splay_set.h @@ -9,16 +9,29 @@ //@cond namespace cds { namespace intrusive { namespace striped_set { +#if CDS_COMPILER == CDS_COMPILER_INTEL && CDS_COMPILER_VERSION <= 1500 + template + class adapt< boost::intrusive::splay_set< T, O1, O2, O3, O4 >, Options... > + { + public: + typedef boost::intrusive::splay_set< T, O1, O2, O3, O4 > container_type; ///< underlying intrusive container type + + public: + typedef details::boost_intrusive_set_adapter type; ///< Result of the metafunction + + }; +#else template class adapt< boost::intrusive::splay_set< T, BIOptons... >, Options... > { public: - typedef boost::intrusive::splay_set< T, BIOptons... > container_type ; ///< underlying intrusive container type + typedef boost::intrusive::splay_set< T, BIOptons... > container_type ; ///< underlying intrusive container type public: - typedef details::boost_intrusive_set_adapter type ; ///< Result of the metafunction + typedef details::boost_intrusive_set_adapter type ; ///< Result of the metafunction }; +#endif }}} // namespace cds::intrusive::striped_set //@endcond diff --git a/cds/intrusive/striped_set/boost_treap_set.h b/cds/intrusive/striped_set/boost_treap_set.h index 9df0f682..fff8ffc8 100644 --- a/cds/intrusive/striped_set/boost_treap_set.h +++ b/cds/intrusive/striped_set/boost_treap_set.h @@ -9,16 +9,27 @@ //@cond namespace cds { namespace intrusive { namespace striped_set { - template - class adapt< boost::intrusive::treap_set< T, BIOptons... >, Options... > +#if CDS_COMPILER == CDS_COMPILER_INTEL && CDS_COMPILER_VERSION <= 1500 + template + class adapt< boost::intrusive::treap_set< T, O1, O2, O3, O4 >, Options... > { public: - typedef boost::intrusive::treap_set< T, BIOptons... > container_type ; ///< underlying intrusive container type + typedef boost::intrusive::treap_set< T, O1, O2, O3, O4 > container_type ; ///< underlying intrusive container type public: typedef details::boost_intrusive_set_adapter type ; ///< Result of the metafunction + }; +#else + template + class adapt< boost::intrusive::treap_set< T, BIOptons... >, Options... > + { + public: + typedef boost::intrusive::treap_set< T, BIOptons... > container_type; ///< underlying intrusive container type + public: + typedef details::boost_intrusive_set_adapter type; ///< Result of the metafunction }; +#endif }}} // namespace cds::intrusive::striped_set //@endcond diff --git a/cds/intrusive/striped_set/boost_unordered_set.h b/cds/intrusive/striped_set/boost_unordered_set.h index b2009b2f..ea833054 100644 --- a/cds/intrusive/striped_set/boost_unordered_set.h +++ b/cds/intrusive/striped_set/boost_unordered_set.h @@ -10,171 +10,189 @@ //@cond namespace cds { namespace intrusive { namespace striped_set { - template - class adapt< boost::intrusive::unordered_set< T, BIOptons... >, Options... > - { - public: - typedef boost::intrusive::unordered_set< T, BIOptons... > container_type ; ///< underlying intrusive container type - - private: - class adapted_container + namespace details { + template + class adapt_boost_unordered_set { public: - typedef typename container_type::value_type value_type ; ///< value type stored in the container - typedef typename container_type::iterator iterator ; ///< container iterator - typedef typename container_type::const_iterator const_iterator ; ///< container const iterator - - typedef typename opt::value< - typename opt::find_option< - opt::buffer< opt::v::static_buffer< cds::any_type, 256 > >, - Options... - >::type - >::buffer initial_buffer_type; - typedef typename initial_buffer_type::template rebind< typename container_type::bucket_type >::other buffer_type; - typedef cds::intrusive::striped_set::load_factor_resizing<256> default_resizing_policy; + typedef Set container_type; ///< underlying intrusive container type private: - template - struct equal_from_compare + class adapted_container { - Compare& m_cmp; - equal_from_compare( Compare& cmp ) - : m_cmp( cmp ) - {} + public: + typedef typename container_type::value_type value_type; ///< value type stored in the container + typedef typename container_type::iterator iterator; ///< container iterator + typedef typename container_type::const_iterator const_iterator; ///< container const iterator - equal_from_compare( equal_from_compare const& src ) - : m_cmp( src.m_cmp ) + typedef typename opt::value < + typename opt::find_option < + opt::buffer< opt::v::static_buffer< cds::any_type, 256 > >, + Options... + > ::type + > ::buffer initial_buffer_type; + typedef typename initial_buffer_type::template rebind< typename container_type::bucket_type >::other buffer_type; + typedef cds::intrusive::striped_set::load_factor_resizing<256> default_resizing_policy; + + private: + template + struct equal_from_compare + { + Compare& m_cmp; + equal_from_compare( Compare& cmp ) + : m_cmp( cmp ) + {} + + equal_from_compare( equal_from_compare const& src ) + : m_cmp( src.m_cmp ) + {} + + template + bool operator()( A& a, B& b ) const + { + return !m_cmp( a, b ) && !m_cmp( b, a ); + } + + template + bool operator()( A& a, B& b ) + { + return !m_cmp( a, b ) && !m_cmp( b, a ); + } + }; + + buffer_type m_Buckets; // buffer should be declared first since it is used in m_Set ctor. + container_type m_Set; + + public: + adapted_container() + : m_Set( typename container_type::bucket_traits( m_Buckets.buffer(), m_Buckets.capacity() ) ) {} - template - bool operator()( A& a, B& b ) const + container_type& base_container() { - return !m_cmp( a, b ) && !m_cmp( b, a ); + return m_Set; } - template - bool operator()( A& a, B& b ) + template + bool insert( value_type& val, Func f ) { - return !m_cmp( a, b ) && !m_cmp( b, a ); + std::pair res = m_Set.insert( val ); + if ( res.second ) + f( val ); + return res.second; } - }; - buffer_type m_Buckets ; // buffer should be declared first since it is used in m_Set ctor. - container_type m_Set; + template + std::pair ensure( value_type& val, Func f ) + { + std::pair res = m_Set.insert( val ); + f( res.second, *res.first, val ); + return std::make_pair( true, res.second ); + } - public: - adapted_container() - : m_Set( typename container_type::bucket_traits( m_Buckets.buffer(), m_Buckets.capacity() )) - {} + bool unlink( value_type& val ) + { + iterator it = m_Set.find( value_type( val ) ); + if ( it == m_Set.end() || &(*it) != &val ) + return false; + m_Set.erase( it ); + return true; + } - container_type& base_container() - { - return m_Set; - } + template + value_type * erase( Q const& key, Func f ) + { + iterator it = m_Set.find( key, typename container_type::hasher(), typename container_type::key_equal() ); + if ( it == m_Set.end() ) + return nullptr; + value_type& val = *it; + f( val ); + m_Set.erase( it ); + return &val; + } - template - bool insert( value_type& val, Func f ) - { - std::pair res = m_Set.insert( val ); - if ( res.second ) + template + value_type * erase( Q const& key, Less pred, Func f ) + { + iterator it = m_Set.find( key, typename container_type::hasher(), equal_from_compare( pred ) ); + if ( it == m_Set.end() ) + return nullptr; + value_type& val = *it; f( val ); - return res.second; - } + m_Set.erase( it ); + return &val; + } - template - std::pair ensure( value_type& val, Func f ) - { - std::pair res = m_Set.insert( val ); - f( res.second, *res.first, val ); - return std::make_pair( true, res.second ); - } + template + bool find( Q& key, Func f ) + { + iterator it = m_Set.find( key, typename container_type::hasher(), typename container_type::key_equal() ); + if ( it == m_Set.end() ) + return false; + f( *it, key ); + return true; + } - bool unlink( value_type& val ) - { - iterator it = m_Set.find( value_type(val) ); - if ( it == m_Set.end() || &(*it) != &val ) - return false; - m_Set.erase( it ); - return true; - } - - template - value_type * erase( Q const& key, Func f ) - { - iterator it = m_Set.find( key, typename container_type::hasher(), typename container_type::key_equal() ); - if ( it == m_Set.end() ) - return nullptr; - value_type& val = *it; - f( val ); - m_Set.erase( it ); - return &val; - } - - template - value_type * erase( Q const& key, Less pred, Func f ) - { - iterator it = m_Set.find( key, typename container_type::hasher(), equal_from_compare(pred) ); - if ( it == m_Set.end() ) - return nullptr; - value_type& val = *it; - f( val ); - m_Set.erase( it ); - return &val; - } - - template - bool find( Q& key, Func f ) - { - iterator it = m_Set.find( key, typename container_type::hasher(), typename container_type::key_equal() ); - if ( it == m_Set.end() ) - return false; - f( *it, key ); - return true; - } - - template - bool find( Q& key, Less pred, Func f ) - { - iterator it = m_Set.find( key, typename container_type::hasher(), equal_from_compare(pred) ); - if ( it == m_Set.end() ) - return false; - f( *it, key ); - return true; - } - - void clear() - { - m_Set.clear(); - } + template + bool find( Q& key, Less pred, Func f ) + { + iterator it = m_Set.find( key, typename container_type::hasher(), equal_from_compare( pred ) ); + if ( it == m_Set.end() ) + return false; + f( *it, key ); + return true; + } - template - void clear( Disposer disposer ) - { - m_Set.clear_and_dispose( disposer ); - } + void clear() + { + m_Set.clear(); + } - iterator begin() { return m_Set.begin(); } - const_iterator begin() const { return m_Set.begin(); } - iterator end() { return m_Set.end(); } - const_iterator end() const { return m_Set.end(); } + template + void clear( Disposer disposer ) + { + m_Set.clear_and_dispose( disposer ); + } - size_t size() const - { - return (size_t) m_Set.size(); - } + iterator begin() { return m_Set.begin(); } + const_iterator begin() const { return m_Set.begin(); } + iterator end() { return m_Set.end(); } + const_iterator end() const { return m_Set.end(); } - void move_item( adapted_container& from, iterator itWhat ) - { - value_type& val = *itWhat; - from.base_container().erase( itWhat ); - insert( val, []( value_type& ) {} ); - } - }; + size_t size() const + { + return (size_t)m_Set.size(); + } + + void move_item( adapted_container& from, iterator itWhat ) + { + value_type& val = *itWhat; + from.base_container().erase( itWhat ); + insert( val, []( value_type& ) {} ); + } + }; - public: - typedef adapted_container type ; ///< Result of the metafunction + public: + typedef adapted_container type; ///< Result of the metafunction + }; + } // namespace details + +#if CDS_COMPILER == CDS_COMPILER_INTEL && CDS_COMPILER_VERSION <= 1500 + template + class adapt < boost::intrusive::unordered_set< T, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 >, Options... > + : public details::adapt_boost_unordered_set < boost::intrusive::unordered_set< T, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 >, Options... > + {}; +#else + template + class adapt < boost::intrusive::unordered_set< T, BIOptons... >, Options... > + : public details::adapt_boost_unordered_set < boost::intrusive::unordered_set< T, BIOptons... >, Options... > + {}; +#endif - }; }}} // namespace cds::intrusive::striped_set //@endcond -- 2.34.1