1 | // |
2 | // Boost.Pointer Container |
3 | // |
4 | // Copyright Thorsten Ottosen 2008. Use, modification and |
5 | // distribution is subject to the Boost Software License, Version |
6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
7 | // http://www.boost.org/LICENSE_1_0.txt) |
8 | // |
9 | // For more information, see http://www.boost.org/libs/ptr_container/ |
10 | // |
11 | |
12 | #ifndef BOOST_PTR_CONTAINER_PTR_UNORDERED_SET_HPP |
13 | #define BOOST_PTR_CONTAINER_PTR_UNORDERED_SET_HPP |
14 | |
15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
16 | # pragma once |
17 | #endif |
18 | |
19 | #include <boost/ptr_container/indirect_fun.hpp> |
20 | #include <boost/ptr_container/ptr_set_adapter.hpp> |
21 | #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> |
22 | #include <boost/unordered_set.hpp> |
23 | |
24 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) |
25 | #pragma GCC diagnostic push |
26 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
27 | #endif |
28 | |
29 | namespace boost |
30 | { |
31 | |
32 | template |
33 | < |
34 | class Key, |
35 | class Hash = boost::hash<Key>, |
36 | class Pred = std::equal_to<Key>, |
37 | class CloneAllocator = heap_clone_allocator, |
38 | class Allocator = std::allocator< typename ptr_container_detail::void_ptr<Key>::type > |
39 | > |
40 | class ptr_unordered_set : |
41 | public ptr_set_adapter< Key, boost::unordered_set< |
42 | typename ptr_container_detail::void_ptr<Key>::type, |
43 | void_ptr_indirect_fun<Hash,Key>, |
44 | void_ptr_indirect_fun<Pred,Key>,Allocator>, |
45 | CloneAllocator, false > |
46 | { |
47 | typedef ptr_set_adapter< Key, boost::unordered_set< |
48 | typename ptr_container_detail::void_ptr<Key>::type, |
49 | void_ptr_indirect_fun<Hash,Key>, |
50 | void_ptr_indirect_fun<Pred,Key>,Allocator>, |
51 | CloneAllocator, false > |
52 | base_type; |
53 | |
54 | typedef ptr_unordered_set<Key,Hash,Pred,CloneAllocator,Allocator> this_type; |
55 | |
56 | public: |
57 | typedef typename base_type::size_type size_type; |
58 | |
59 | private: |
60 | using base_type::lower_bound; |
61 | using base_type::upper_bound; |
62 | using base_type::rbegin; |
63 | using base_type::rend; |
64 | using base_type::crbegin; |
65 | using base_type::crend; |
66 | using base_type::key_comp; |
67 | using base_type::value_comp; |
68 | using base_type::front; |
69 | using base_type::back; |
70 | |
71 | public: |
72 | using base_type::begin; |
73 | using base_type::end; |
74 | using base_type::cbegin; |
75 | using base_type::cend; |
76 | using base_type::bucket_count; |
77 | using base_type::max_bucket_count; |
78 | using base_type::bucket_size; |
79 | using base_type::bucket; |
80 | using base_type::load_factor; |
81 | using base_type::max_load_factor; |
82 | using base_type::rehash; |
83 | using base_type::key_eq; |
84 | using base_type::hash_function; |
85 | |
86 | public: |
87 | ptr_unordered_set() |
88 | {} |
89 | |
90 | explicit ptr_unordered_set( size_type n ) |
91 | : base_type( n, ptr_container_detail::unordered_associative_container_tag() ) |
92 | { } |
93 | |
94 | ptr_unordered_set( size_type n, |
95 | const Hash& comp, |
96 | const Pred& pred = Pred(), |
97 | const Allocator& a = Allocator() ) |
98 | : base_type( n, comp, pred, a ) |
99 | { } |
100 | |
101 | template< typename InputIterator > |
102 | ptr_unordered_set( InputIterator first, InputIterator last ) |
103 | : base_type( first, last ) |
104 | { } |
105 | |
106 | template< typename InputIterator > |
107 | ptr_unordered_set( InputIterator first, InputIterator last, |
108 | const Hash& comp, |
109 | const Pred& pred = Pred(), |
110 | const Allocator& a = Allocator() ) |
111 | : base_type( first, last, comp, pred, a ) |
112 | { } |
113 | |
114 | BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_set, |
115 | base_type, |
116 | this_type ) |
117 | |
118 | BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_unordered_set, |
119 | base_type ) |
120 | |
121 | }; |
122 | |
123 | |
124 | template |
125 | < |
126 | class Key, |
127 | class Hash = boost::hash<Key>, |
128 | class Pred = std::equal_to<Key>, |
129 | class CloneAllocator = heap_clone_allocator, |
130 | class Allocator = std::allocator<void*> |
131 | > |
132 | class ptr_unordered_multiset : |
133 | public ptr_multiset_adapter< Key, |
134 | boost::unordered_multiset<void*,void_ptr_indirect_fun<Hash,Key>, |
135 | void_ptr_indirect_fun<Pred,Key>,Allocator>, |
136 | CloneAllocator, false > |
137 | { |
138 | typedef ptr_multiset_adapter< Key, |
139 | boost::unordered_multiset<void*,void_ptr_indirect_fun<Hash,Key>, |
140 | void_ptr_indirect_fun<Pred,Key>,Allocator>, |
141 | CloneAllocator, false > |
142 | base_type; |
143 | typedef ptr_unordered_multiset<Key,Hash,Pred,CloneAllocator,Allocator> this_type; |
144 | |
145 | public: |
146 | typedef typename base_type::size_type size_type; |
147 | |
148 | private: |
149 | using base_type::lower_bound; |
150 | using base_type::upper_bound; |
151 | using base_type::rbegin; |
152 | using base_type::rend; |
153 | using base_type::crbegin; |
154 | using base_type::crend; |
155 | using base_type::key_comp; |
156 | using base_type::value_comp; |
157 | using base_type::front; |
158 | using base_type::back; |
159 | |
160 | public: |
161 | using base_type::begin; |
162 | using base_type::end; |
163 | using base_type::cbegin; |
164 | using base_type::cend; |
165 | using base_type::bucket_count; |
166 | using base_type::max_bucket_count; |
167 | using base_type::bucket_size; |
168 | using base_type::bucket; |
169 | using base_type::load_factor; |
170 | using base_type::max_load_factor; |
171 | using base_type::rehash; |
172 | using base_type::key_eq; |
173 | using base_type::hash_function; |
174 | |
175 | public: |
176 | ptr_unordered_multiset() |
177 | { } |
178 | |
179 | explicit ptr_unordered_multiset( size_type n ) |
180 | : base_type( n, ptr_container_detail::unordered_associative_container_tag() ) |
181 | { } |
182 | |
183 | ptr_unordered_multiset( size_type n, |
184 | const Hash& comp, |
185 | const Pred& pred = Pred(), |
186 | const Allocator& a = Allocator() ) |
187 | : base_type( n, comp, pred, a ) |
188 | { } |
189 | |
190 | template< typename InputIterator > |
191 | ptr_unordered_multiset( InputIterator first, InputIterator last ) |
192 | : base_type( first, last ) |
193 | { } |
194 | |
195 | template< typename InputIterator > |
196 | ptr_unordered_multiset( InputIterator first, InputIterator last, |
197 | const Hash& comp, |
198 | const Pred& pred = Pred(), |
199 | const Allocator& a = Allocator() ) |
200 | : base_type( first, last, comp, pred, a ) |
201 | { } |
202 | |
203 | BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_multiset, |
204 | base_type, |
205 | this_type ) |
206 | |
207 | BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_unordered_multiset, |
208 | base_type ) |
209 | |
210 | }; |
211 | |
212 | ///////////////////////////////////////////////////////////////////////// |
213 | // clonability |
214 | |
215 | template< typename K, typename H, typename P, typename CA, typename A > |
216 | inline ptr_unordered_set<K,H,P,CA,A>* |
217 | new_clone( const ptr_unordered_set<K,H,P,CA,A>& r ) |
218 | { |
219 | return r.clone().release(); |
220 | } |
221 | |
222 | template< typename K, typename H, typename P, typename CA, typename A > |
223 | inline ptr_unordered_multiset<K,H,P,CA,A>* |
224 | new_clone( const ptr_unordered_multiset<K,H,P,CA,A>& r ) |
225 | { |
226 | return r.clone().release(); |
227 | } |
228 | |
229 | ///////////////////////////////////////////////////////////////////////// |
230 | // swap |
231 | |
232 | template< typename K, typename H, typename P, typename CA, typename A > |
233 | inline void swap( ptr_unordered_set<K,H,P,CA,A>& l, |
234 | ptr_unordered_set<K,H,P,CA,A>& r ) |
235 | { |
236 | l.swap(r); |
237 | } |
238 | |
239 | template< typename K, typename H, typename P, typename CA, typename A > |
240 | inline void swap( ptr_unordered_multiset<K,H,P,CA,A>& l, |
241 | ptr_unordered_multiset<K,H,P,CA,A>& r ) |
242 | { |
243 | l.swap(r); |
244 | } |
245 | |
246 | } |
247 | |
248 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) |
249 | #pragma GCC diagnostic pop |
250 | #endif |
251 | |
252 | #endif |
253 | |