boost::intrusive::slist adaptation bugfix
[libcds.git] / cds / intrusive / striped_set / boost_slist.h
index 65680fea44cbf74915cf99b4751cb9ea717f1a99..25f2b6a208a76d00fa789b6c9726e23d413de6ea 100644 (file)
 //@cond
 namespace cds { namespace intrusive { namespace striped_set {
 
-    template <typename T, typename... BIOptons, typename... Options>
-    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 List, typename... Options>
+        class adapt_boost_slist
         {
         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 <typename Q, typename Less>
+                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 <typename Q, typename Less>
-            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 <typename Q>
-            std::pair< iterator, bool > find_prev_item( Q const& key )
-            {
-                return find_prev_item_cmp( key, key_comparator() );
-            }
+                template <typename Q>
+                std::pair< iterator, bool > find_prev_item( Q const& key )
+                {
+                    return find_prev_item_cmp( key, key_comparator() );
+                }
 
-            template <typename Q, typename Compare>
-            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 <typename Q, typename Compare, typename Func>
-            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 <typename Q, typename Compare>
+                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 <typename Q, typename Compare, typename Func>
+                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 <typename Func>
-            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 <typename Func>
-            std::pair<bool, bool> 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 <typename Func>
+                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 <typename Func>
+                std::pair<bool, bool> 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 <typename Q, typename Func>
-            value_type * erase( Q const& key, Func f )
-            {
-                return erase_( key, key_comparator(), f );
-            }
+                template <typename Q, typename Func>
+                value_type * erase( Q const& key, Func f )
+                {
+                    return erase_( key, key_comparator(), f );
+                }
 
-            template <typename Q, typename Less, typename Func>
-            value_type * erase( Q const& key, Less pred, Func f )
-            {
-                return erase_( key, cds::opt::details::make_comparator_from_less<Less>(), f );
-            }
+                template <typename Q, typename Less, typename Func>
+                value_type * erase( Q const& key, Less pred, Func f )
+                {
+                    return erase_( key, cds::opt::details::make_comparator_from_less<Less>(), f );
+                }
 
-            template <typename Q, typename Func>
-            bool find( Q& key, Func f )
-            {
-                std::pair< iterator, bool > pos = find_prev_item( key );
-                if ( !pos.second )
-                    return false;
+                template <typename Q, typename Func>
+                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 <typename Q, typename Less, typename Func>
-            bool find( Q& key, Less pred, Func f )
-            {
-                std::pair< iterator, bool > pos = find_prev_item( key, pred );
-                if ( !pos.second )
-                    return false;
+                template <typename Q, typename Less, typename Func>
+                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 <typename Disposer>
-            void clear( Disposer disposer )
-            {
-                m_List.clear_and_dispose( disposer );
-            }
+                template <typename Disposer>
+                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 <typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename... Options>
+    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 <typename T, typename... BIOptions, typename... Options>
+    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