3 #ifndef __CDS_CONTAINER_STRIPED_SET_STD_HASH_SET_MSVC_ADAPTER_H
4 #define __CDS_CONTAINER_STRIPED_SET_STD_HASH_SET_MSVC_ADAPTER_H
6 #ifndef __CDS_CONTAINER_STRIPED_SET_STD_HASH_SET_ADAPTER_H
7 # error <cds/container/striped_set/std_hash_set.h> must be included instead of <cds/container/striped_set/std_hash_set_vc.h> header
10 #include <cds/container/striped_set/adapter.h>
14 namespace cds { namespace container {
15 namespace striped_set {
17 // Copy policy for stdext::hash_set
18 template <typename T, typename Traits, typename Alloc>
19 struct copy_item_policy< stdext::hash_set< T, Traits, Alloc > >
21 typedef stdext::hash_set< T, Traits, Alloc > set_type;
22 typedef typename set_type::iterator iterator;
24 void operator()( set_type& set, iterator itWhat )
26 set.insert( *itWhat );
30 template <typename T, typename Traits, typename Alloc>
31 struct swap_item_policy< stdext::hash_set< T, Traits, Alloc > >: public copy_item_policy< stdext::hash_set< T, Traits, Alloc > >
34 // Move policy for stdext::hash_set
35 template <typename T, typename Hash, typename Pred, typename Alloc>
36 struct move_item_policy< stdext::hash_set< T, Traits, Alloc > >
38 typedef stdext::hash_set< T, Traits, Alloc > set_type;
39 typedef typename set_type::iterator iterator;
41 void operator()( set_type& set, iterator itWhat )
43 set.insert( std::move( *itWhat ) );
47 } // namespace striped_set
48 }} // namespace cds::container
50 namespace cds { namespace intrusive { namespace striped_set {
52 /// std::unordered_set adapter for hash set bucket
53 template <typename T, class Traits, class Alloc, typename... Options>
54 class adapt< stdext::hash_set<T, Traits, Alloc>, Options... >
57 typedef stdext::hash_set<T, Traits, Alloc> container_type ; ///< underlying container type
60 /// Adapted container type
61 class adapted_container: public cds::container::striped_set::adapted_container
64 typedef typename container_type::value_type value_type ; ///< value type stored in the container
65 typedef typename container_type::iterator iterator ; ///< container iterator
66 typedef typename container_type::const_iterator const_iterator ; ///< container const iterator
68 static bool const has_find_with = false;
69 static bool const has_erase_with = false;
73 typedef typename cds::opt::select<
74 typename cds::opt::value<
75 typename cds::opt::find_option<
76 cds::opt::copy_policy< cds::container::striped_set::move_item >
80 , cds::container::striped_set::copy_item, cds::container::striped_set::copy_item_policy<container_type>
81 , cds::container::striped_set::swap_item, cds::container::striped_set::swap_item_policy<container_type> // not defined
82 , cds::container::striped_set::move_item, cds::container::striped_set::move_item_policy<container_type>
93 template <typename Q, typename Func>
94 bool insert( const Q& val, Func f )
96 std::pair<iterator, bool> res = m_Set.insert( value_type(val) );
102 template <typename Q, typename Func>
103 std::pair<bool, bool> ensure( const Q& val, Func func )
105 std::pair<iterator, bool> res = m_Set.insert( value_type(val) );
106 ::func( res.second, *res.first, val );
107 return std::make_pair( true, res.second );
110 template <typename Q, typename Func>
111 bool erase( const Q& key, Func f )
113 iterator it = m_Set.find( value_type(key) );
114 if ( it == m_Set.end() )
121 template <typename Q, typename Func>
122 bool find( Q& val, Func f )
124 iterator it = m_Set.find( value_type(val) );
125 if ( it == m_Set.end() )
131 /// Clears the container
137 iterator begin() { return m_Set.begin(); }
138 const_iterator begin() const { return m_Set.begin(); }
139 iterator end() { return m_Set.end(); }
140 const_iterator end() const { return m_Set.end(); }
142 void move_item( adapted_container& /*from*/, iterator itWhat )
144 assert( m_Set.find( *itWhat ) == m_Set.end() );
145 copy_item()( m_Set, itWhat );
155 typedef adapted_container type ; ///< Result of \p adapt metafunction
158 }}} // namespace cds::intrusive::striped_set
162 #endif // #ifndef __CDS_CONTAINER_STRIPED_SET_STD_HASH_SET_MSVC_ADAPTER_H