3 #ifndef __CDS_INTRUSIVE_STRIPED_SET_BOOST_LIST_ADAPTER_H
4 #define __CDS_INTRUSIVE_STRIPED_SET_BOOST_LIST_ADAPTER_H
6 #include <boost/intrusive/list.hpp>
7 #include <cds/intrusive/striped_set/adapter.h>
10 namespace cds { namespace intrusive { namespace striped_set {
12 template <typename T, typename... BIOptons, typename... Options>
13 class adapt< boost::intrusive::list< T, BIOptons... >, Options... >
16 typedef boost::intrusive::list< T, BIOptons... > container_type ; ///< underlying intrusive container type
19 /// Adapted intrusive container
20 class adapted_container: public cds::intrusive::striped_set::adapted_sequential_container
23 typedef typename container_type::value_type value_type ; ///< value type stored in the container
24 typedef typename container_type::iterator iterator ; ///< container iterator
25 typedef typename container_type::const_iterator const_iterator ; ///< container const iterator
26 typedef typename cds::opt::details::make_comparator_from_option_list< value_type, Options... >::type key_comparator;
31 bool operator()( value_type const& i1, value_type const& i2) const
33 return key_comparator()( i1, i2 ) < 0;
37 bool operator()( Q const& i1, value_type const& i2) const
39 return key_comparator()( i1, i2 ) < 0;
43 bool operator()( value_type const& i1, Q const& i2) const
45 return key_comparator()( i1, i2 ) < 0;
49 template <typename Q, typename Pred>
50 iterator find_key( Q const& key, Pred pred)
52 iterator itEnd = m_List.end();
54 for ( it = m_List.begin(); it != itEnd; ++it ) {
55 if ( !pred( *it, key ) )
62 container_type m_List;
68 container_type& base_container()
73 template <typename Func>
74 bool insert( value_type& val, Func f )
76 iterator it = find_key( val, find_predicate() );
77 if ( it == m_List.end() || key_comparator()( val, *it ) != 0 ) {
78 m_List.insert( it, val );
88 template <typename Func>
89 std::pair<bool, bool> ensure( value_type& val, Func f )
91 iterator it = find_key( val, find_predicate() );
92 if ( it == m_List.end() || key_comparator()( val, *it ) != 0 ) {
94 m_List.insert( it, val );
96 return std::make_pair( true, true );
100 f( false, *it, val );
101 return std::make_pair( true, false );
105 bool unlink( value_type& val )
107 iterator it = find_key( val, find_predicate() );
108 if ( it == m_List.end() || &(*it) != &val )
115 template <typename Q, typename Func>
116 value_type * erase( Q const& key, Func f )
118 iterator it = find_key( key, find_predicate() );
119 if ( it == m_List.end() || key_comparator()( key, *it ) != 0 )
123 value_type& val = *it;
130 template <typename Q, typename Less, typename Func>
131 value_type * erase( Q const& key, Less pred, Func f )
133 iterator it = find_key( key, pred );
134 if ( it == m_List.end() || pred( key, *it ) || pred( *it, key ) )
138 value_type& val = *it;
145 template <typename Q, typename Func>
146 bool find( Q& key, Func f )
148 return find( key, find_predicate(), f );
151 template <typename Q, typename Less, typename Func>
152 bool find( Q& key, Less pred, Func f )
154 iterator it = find_key( key, pred );
155 if ( it == m_List.end() || pred( key, *it ) || pred( *it, key ))
168 template <typename Disposer>
169 void clear( Disposer disposer )
171 m_List.clear_and_dispose( disposer );
174 iterator begin() { return m_List.begin(); }
175 const_iterator begin() const { return m_List.begin(); }
176 iterator end() { return m_List.end(); }
177 const_iterator end() const { return m_List.end(); }
181 return (size_t) m_List.size();
184 void move_item( adapted_container& from, iterator itWhat )
186 value_type& val = *itWhat;
187 from.base_container().erase( itWhat );
188 insert( val, []( value_type& ) {} );
193 typedef adapted_container type ; ///< Result of the metafunction
195 }}} // namespace cds::intrusive::striped_set
198 #endif // #ifndef __CDS_INTRUSIVE_STRIPED_SET_BOOST_LIST_ADAPTER_H