Remove CDS_RVALUE_SUPPORT, CDS_MOVE_SEMANTICS_SUPPORT macros and emulating code
[libcds.git] / cds / container / striped_set / std_hash_set_vc.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_CONTAINER_STRIPED_SET_STD_HASH_SET_MSVC_ADAPTER_H
4 #define __CDS_CONTAINER_STRIPED_SET_STD_HASH_SET_MSVC_ADAPTER_H
5
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
8 #endif
9
10 #include <cds/container/striped_set/adapter.h>
11 #include <hash_set>
12
13 //@cond
14 namespace cds { namespace container {
15     namespace striped_set {
16
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 > >
20         {
21             typedef stdext::hash_set< T, Traits, Alloc > set_type;
22             typedef typename set_type::iterator iterator;
23
24             void operator()( set_type& set, iterator itWhat )
25             {
26                 set.insert( *itWhat );
27             }
28         };
29
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 > >
32         {};
33
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 > >
37         {
38             typedef stdext::hash_set< T, Traits, Alloc > set_type;
39             typedef typename set_type::iterator iterator;
40
41             void operator()( set_type& set, iterator itWhat )
42             {
43                 set.insert( std::move( *itWhat ) );
44             }
45         };
46
47     }   // namespace striped_set
48 }} // namespace cds::container
49
50 namespace cds { namespace intrusive { namespace striped_set {
51
52     /// std::unordered_set  adapter for hash set bucket
53     template <typename T, class Traits, class Alloc, CDS_SPEC_OPTIONS>
54     class adapt< stdext::hash_set<T, Traits, Alloc>, CDS_OPTIONS >
55     {
56     public:
57         typedef stdext::hash_set<T, Traits, Alloc>  container_type  ;   ///< underlying container type
58
59     private:
60         /// Adapted container type
61         class adapted_container: public cds::container::striped_set::adapted_container
62         {
63         public:
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
67
68             static bool const has_find_with = false;
69             static bool const has_erase_with = false;
70
71         private:
72             //@cond
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 >
77                         , CDS_OPTIONS
78                     >::type
79                 >::copy_policy
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>
83             >::type copy_item;
84             //@endcond
85
86         private:
87             //@cond
88             container_type  m_Set;
89             //@endcond
90
91         public:
92
93             template <typename Q, typename Func>
94             bool insert( const Q& val, Func f )
95             {
96                 std::pair<iterator, bool> res = m_Set.insert( value_type(val) );
97                 if ( res.second )
98                     ::cds::unref(f)( *res.first );
99                 return res.second;
100             }
101
102             template <typename Q, typename Func>
103             std::pair<bool, bool> ensure( const Q& val, Func func )
104             {
105                 std::pair<iterator, bool> res = m_Set.insert( value_type(val) );
106                 ::cds::unref(func)( res.second, *res.first, val );
107                 return std::make_pair( true, res.second );
108             }
109
110             template <typename Q, typename Func>
111             bool erase( const Q& key, Func f )
112             {
113                 iterator it = m_Set.find( value_type(key) );
114                 if ( it == m_Set.end() )
115                     return false;
116                 ::cds::unref(f)( *it );
117                 m_Set.erase( it );
118                 return true;
119             }
120
121             template <typename Q, typename Func>
122             bool find( Q& val, Func f )
123             {
124                 iterator it = m_Set.find( value_type(val) );
125                 if ( it == m_Set.end() )
126                     return false;
127                 ::cds::unref(f)( *it, val );
128                 return true;
129             }
130
131             /// Clears the container
132             void clear()
133             {
134                 m_Set.clear();
135             }
136
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(); }
141
142             void move_item( adapted_container& /*from*/, iterator itWhat )
143             {
144                 assert( m_Set.find( *itWhat ) == m_Set.end() );
145                 copy_item()( m_Set, itWhat );
146             }
147
148             size_t size() const
149             {
150                 return m_Set.size();
151             }
152         };
153
154     public:
155         typedef adapted_container type ; ///< Result of \p adapt metafunction
156
157     };
158 }}} // namespace cds::intrusive::striped_set
159
160 //@endcond
161
162 #endif  // #ifndef __CDS_CONTAINER_STRIPED_SET_STD_HASH_SET_MSVC_ADAPTER_H