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