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/unordered_set.hpp> |
22 | |
23 | namespace boost |
24 | { |
25 | |
26 | template |
27 | < |
28 | class Key, |
29 | class Hash = boost::hash<Key>, |
30 | class Pred = std::equal_to<Key>, |
31 | class CloneAllocator = heap_clone_allocator, |
32 | class Allocator = std::allocator<void*> |
33 | > |
34 | class ptr_unordered_set : |
35 | public ptr_set_adapter< Key, |
36 | boost::unordered_set<void*,void_ptr_indirect_fun<Hash,Key>, |
37 | void_ptr_indirect_fun<Pred,Key>,Allocator>, |
38 | CloneAllocator, false > |
39 | { |
40 | typedef ptr_set_adapter< Key, |
41 | boost::unordered_set<void*,void_ptr_indirect_fun<Hash,Key>, |
42 | void_ptr_indirect_fun<Pred,Key>,Allocator>, |
43 | CloneAllocator, false > |
44 | base_type; |
45 | |
46 | typedef ptr_unordered_set<Key,Hash,Pred,CloneAllocator,Allocator> this_type; |
47 | |
48 | public: |
49 | typedef typename base_type::size_type size_type; |
50 | |
51 | private: |
52 | using base_type::lower_bound; |
53 | using base_type::upper_bound; |
54 | using base_type::rbegin; |
55 | using base_type::rend; |
56 | using base_type::crbegin; |
57 | using base_type::crend; |
58 | using base_type::key_comp; |
59 | using base_type::value_comp; |
60 | using base_type::front; |
61 | using base_type::back; |
62 | |
63 | public: |
64 | using base_type::begin; |
65 | using base_type::end; |
66 | using base_type::cbegin; |
67 | using base_type::cend; |
68 | using base_type::bucket_count; |
69 | using base_type::max_bucket_count; |
70 | using base_type::bucket_size; |
71 | using base_type::bucket; |
72 | using base_type::load_factor; |
73 | using base_type::max_load_factor; |
74 | using base_type::rehash; |
75 | using base_type::key_eq; |
76 | using base_type::hash_function; |
77 | |
78 | public: |
79 | ptr_unordered_set() |
80 | {} |
81 | |
82 | explicit ptr_unordered_set( size_type n ) |
83 | : base_type( n, ptr_container_detail::unordered_associative_container_tag() ) |
84 | { } |
85 | |
86 | ptr_unordered_set( size_type n, |
87 | const Hash& comp, |
88 | const Pred& pred = Pred(), |
89 | const Allocator& a = Allocator() ) |
90 | : base_type( n, comp, pred, a ) |
91 | { } |
92 | |
93 | template< typename InputIterator > |
94 | ptr_unordered_set( InputIterator first, InputIterator last ) |
95 | : base_type( first, last ) |
96 | { } |
97 | |
98 | template< typename InputIterator > |
99 | ptr_unordered_set( InputIterator first, InputIterator last, |
100 | const Hash& comp, |
101 | const Pred& pred = Pred(), |
102 | const Allocator& a = Allocator() ) |
103 | : base_type( first, last, comp, pred, a ) |
104 | { } |
105 | |
106 | BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_set, |
107 | base_type, |
108 | this_type ) |
109 | |
110 | BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_unordered_set, |
111 | base_type ) |
112 | |
113 | }; |
114 | |
115 | |
116 | template |
117 | < |
118 | class Key, |
119 | class Hash = boost::hash<Key>, |
120 | class Pred = std::equal_to<Key>, |
121 | class CloneAllocator = heap_clone_allocator, |
122 | class Allocator = std::allocator<void*> |
123 | > |
124 | class ptr_unordered_multiset : |
125 | public ptr_multiset_adapter< Key, |
126 | boost::unordered_multiset<void*,void_ptr_indirect_fun<Hash,Key>, |
127 | void_ptr_indirect_fun<Pred,Key>,Allocator>, |
128 | CloneAllocator, false > |
129 | { |
130 | typedef ptr_multiset_adapter< Key, |
131 | boost::unordered_multiset<void*,void_ptr_indirect_fun<Hash,Key>, |
132 | void_ptr_indirect_fun<Pred,Key>,Allocator>, |
133 | CloneAllocator, false > |
134 | base_type; |
135 | typedef ptr_unordered_multiset<Key,Hash,Pred,CloneAllocator,Allocator> this_type; |
136 | |
137 | public: |
138 | typedef typename base_type::size_type size_type; |
139 | |
140 | private: |
141 | using base_type::lower_bound; |
142 | using base_type::upper_bound; |
143 | using base_type::rbegin; |
144 | using base_type::rend; |
145 | using base_type::crbegin; |
146 | using base_type::crend; |
147 | using base_type::key_comp; |
148 | using base_type::value_comp; |
149 | using base_type::front; |
150 | using base_type::back; |
151 | |
152 | public: |
153 | using base_type::begin; |
154 | using base_type::end; |
155 | using base_type::cbegin; |
156 | using base_type::cend; |
157 | using base_type::bucket_count; |
158 | using base_type::max_bucket_count; |
159 | using base_type::bucket_size; |
160 | using base_type::bucket; |
161 | using base_type::load_factor; |
162 | using base_type::max_load_factor; |
163 | using base_type::rehash; |
164 | using base_type::key_eq; |
165 | using base_type::hash_function; |
166 | |
167 | public: |
168 | ptr_unordered_multiset() |
169 | { } |
170 | |
171 | explicit ptr_unordered_multiset( size_type n ) |
172 | : base_type( n, ptr_container_detail::unordered_associative_container_tag() ) |
173 | { } |
174 | |
175 | ptr_unordered_multiset( size_type n, |
176 | const Hash& comp, |
177 | const Pred& pred = Pred(), |
178 | const Allocator& a = Allocator() ) |
179 | : base_type( n, comp, pred, a ) |
180 | { } |
181 | |
182 | template< typename InputIterator > |
183 | ptr_unordered_multiset( InputIterator first, InputIterator last ) |
184 | : base_type( first, last ) |
185 | { } |
186 | |
187 | template< typename InputIterator > |
188 | ptr_unordered_multiset( InputIterator first, InputIterator last, |
189 | const Hash& comp, |
190 | const Pred& pred = Pred(), |
191 | const Allocator& a = Allocator() ) |
192 | : base_type( first, last, comp, pred, a ) |
193 | { } |
194 | |
195 | BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_multiset, |
196 | base_type, |
197 | this_type ) |
198 | |
199 | BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_unordered_multiset, |
200 | base_type ) |
201 | |
202 | }; |
203 | |
204 | ///////////////////////////////////////////////////////////////////////// |
205 | // clonability |
206 | |
207 | template< typename K, typename H, typename P, typename CA, typename A > |
208 | inline ptr_unordered_set<K,H,P,CA,A>* |
209 | new_clone( const ptr_unordered_set<K,H,P,CA,A>& r ) |
210 | { |
211 | return r.clone().release(); |
212 | } |
213 | |
214 | template< typename K, typename H, typename P, typename CA, typename A > |
215 | inline ptr_unordered_multiset<K,H,P,CA,A>* |
216 | new_clone( const ptr_unordered_multiset<K,H,P,CA,A>& r ) |
217 | { |
218 | return r.clone().release(); |
219 | } |
220 | |
221 | ///////////////////////////////////////////////////////////////////////// |
222 | // swap |
223 | |
224 | template< typename K, typename H, typename P, typename CA, typename A > |
225 | inline void swap( ptr_unordered_set<K,H,P,CA,A>& l, |
226 | ptr_unordered_set<K,H,P,CA,A>& r ) |
227 | { |
228 | l.swap(r); |
229 | } |
230 | |
231 | template< typename K, typename H, typename P, typename CA, typename A > |
232 | inline void swap( ptr_unordered_multiset<K,H,P,CA,A>& l, |
233 | ptr_unordered_multiset<K,H,P,CA,A>& r ) |
234 | { |
235 | l.swap(r); |
236 | } |
237 | |
238 | } |
239 | |
240 | #endif |
241 | |