]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost | |
4 | // Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // See http://www.boost.org/libs/container for documentation. | |
8 | // | |
9 | ////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef BOOST_CONTAINER_SET_HPP | |
12 | #define BOOST_CONTAINER_SET_HPP | |
13 | ||
14 | #ifndef BOOST_CONFIG_HPP | |
15 | # include <boost/config.hpp> | |
16 | #endif | |
17 | ||
18 | #if defined(BOOST_HAS_PRAGMA_ONCE) | |
19 | # pragma once | |
20 | #endif | |
21 | ||
22 | #include <boost/container/detail/config_begin.hpp> | |
23 | #include <boost/container/detail/workaround.hpp> | |
24 | // container | |
25 | #include <boost/container/container_fwd.hpp> | |
26 | // container/detail | |
27 | #include <boost/container/detail/mpl.hpp> | |
28 | #include <boost/container/detail/tree.hpp> | |
29 | #include <boost/container/new_allocator.hpp> //new_allocator | |
30 | // intrusive/detail | |
31 | #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair | |
32 | #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal | |
33 | // move | |
34 | #include <boost/move/traits.hpp> | |
35 | #include <boost/move/utility_core.hpp> | |
36 | // move/detail | |
37 | #include <boost/move/detail/move_helpers.hpp> | |
38 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
39 | #include <boost/move/detail/fwd_macros.hpp> | |
40 | #endif | |
41 | // std | |
42 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
43 | #include <initializer_list> | |
44 | #endif | |
45 | ||
46 | namespace boost { | |
47 | namespace container { | |
48 | ||
49 | #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED | |
50 | ||
51 | //! A set is a kind of associative container that supports unique keys (contains at | |
52 | //! most one of each key value) and provides for fast retrieval of the keys themselves. | |
53 | //! Class set supports bidirectional iterators. | |
54 | //! | |
55 | //! A set satisfies all of the requirements of a container and of a reversible container | |
56 | //! , and of an associative container. A set also provides most operations described in | |
57 | //! for unique keys. | |
58 | //! | |
59 | //! \tparam Key is the type to be inserted in the set, which is also the key_type | |
60 | //! \tparam Compare is the comparison functor used to order keys | |
61 | //! \tparam Allocator is the allocator to be used to allocate memory for this container | |
62 | //! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options. | |
63 | template <class Key, class Compare = std::less<Key>, class Allocator = new_allocator<Key>, class Options = tree_assoc_defaults > | |
64 | #else | |
65 | template <class Key, class Compare, class Allocator, class Options> | |
66 | #endif | |
67 | class set | |
68 | ///@cond | |
69 | : public container_detail::tree | |
70 | < Key, container_detail::identity<Key>, Compare, Allocator, Options> | |
71 | ///@endcond | |
72 | { | |
73 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
74 | private: | |
75 | BOOST_COPYABLE_AND_MOVABLE(set) | |
76 | typedef container_detail::tree | |
77 | < Key, container_detail::identity<Key>, Compare, Allocator, Options> base_t; | |
78 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
79 | ||
80 | public: | |
81 | ////////////////////////////////////////////// | |
82 | // | |
83 | // types | |
84 | // | |
85 | ////////////////////////////////////////////// | |
86 | typedef Key key_type; | |
87 | typedef Key value_type; | |
88 | typedef Compare key_compare; | |
89 | typedef Compare value_compare; | |
90 | typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type; | |
91 | typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer; | |
92 | typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer; | |
93 | typedef typename ::boost::container::allocator_traits<Allocator>::reference reference; | |
94 | typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference; | |
95 | typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type; | |
96 | typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type; | |
97 | typedef Allocator allocator_type; | |
98 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type; | |
99 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator; | |
100 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator; | |
101 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator; | |
102 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator; | |
103 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::node_type) node_type; | |
104 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::insert_return_type) insert_return_type; | |
105 | ||
106 | ////////////////////////////////////////////// | |
107 | // | |
108 | // construct/copy/destroy | |
109 | // | |
110 | ////////////////////////////////////////////// | |
111 | ||
112 | //! <b>Effects</b>: Default constructs an empty set. | |
113 | //! | |
114 | //! <b>Complexity</b>: Constant. | |
115 | set() BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value && | |
116 | container_detail::is_nothrow_default_constructible<Compare>::value) | |
117 | : base_t() | |
118 | {} | |
119 | ||
120 | //! <b>Effects</b>: Constructs an empty set using the specified comparison object | |
121 | //! and allocator. | |
122 | //! | |
123 | //! <b>Complexity</b>: Constant. | |
124 | explicit set(const Compare& comp, | |
125 | const allocator_type& a = allocator_type()) | |
126 | : base_t(comp, a) | |
127 | {} | |
128 | ||
129 | //! <b>Effects</b>: Constructs an empty set using the specified allocator object. | |
130 | //! | |
131 | //! <b>Complexity</b>: Constant. | |
132 | explicit set(const allocator_type& a) | |
133 | : base_t(a) | |
134 | {} | |
135 | ||
136 | //! <b>Effects</b>: Constructs an empty set using the specified comparison object and | |
137 | //! allocator, and inserts elements from the range [first ,last ). | |
138 | //! | |
139 | //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using | |
140 | //! comp and otherwise N logN, where N is last - first. | |
141 | template <class InputIterator> | |
142 | set(InputIterator first, InputIterator last, const Compare& comp = Compare(), | |
143 | const allocator_type& a = allocator_type()) | |
144 | : base_t(true, first, last, comp, a) | |
145 | {} | |
146 | ||
147 | //! <b>Effects</b>: Constructs an empty set using the specified | |
148 | //! allocator, and inserts elements from the range [first ,last ). | |
149 | //! | |
150 | //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using | |
151 | //! comp and otherwise N logN, where N is last - first. | |
152 | template <class InputIterator> | |
153 | set(InputIterator first, InputIterator last, const allocator_type& a) | |
154 | : base_t(true, first, last, key_compare(), a) | |
155 | {} | |
156 | ||
157 | //! <b>Effects</b>: Constructs an empty set using the specified comparison object and | |
158 | //! allocator, and inserts elements from the ordered unique range [first ,last). This function | |
159 | //! is more efficient than the normal range creation for ordered ranges. | |
160 | //! | |
161 | //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be | |
162 | //! unique values. | |
163 | //! | |
164 | //! <b>Complexity</b>: Linear in N. | |
165 | //! | |
166 | //! <b>Note</b>: Non-standard extension. | |
167 | template <class InputIterator> | |
168 | set( ordered_unique_range_t, InputIterator first, InputIterator last | |
169 | , const Compare& comp = Compare(), const allocator_type& a = allocator_type()) | |
170 | : base_t(ordered_range, first, last, comp, a) | |
171 | {} | |
172 | ||
173 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
174 | //! <b>Effects</b>: Constructs an empty set using the specified comparison object and | |
175 | //! allocator, and inserts elements from the range [il.begin(), il.end()). | |
176 | //! | |
177 | //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using | |
178 | //! comp and otherwise N logN, where N is il.begin() - il.end(). | |
179 | set(std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) | |
180 | : base_t(true, il.begin(), il.end(), comp, a) | |
181 | {} | |
182 | ||
183 | //! <b>Effects</b>: Constructs an empty set using the specified | |
184 | //! allocator, and inserts elements from the range [il.begin(), il.end()). | |
185 | //! | |
186 | //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using | |
187 | //! comp and otherwise N logN, where N is il.begin() - il.end(). | |
188 | set(std::initializer_list<value_type> il, const allocator_type& a) | |
189 | : base_t(true, il.begin(), il.end(), Compare(), a) | |
190 | {} | |
191 | ||
192 | //! <b>Effects</b>: Constructs an empty set using the specified comparison object and | |
193 | //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function | |
194 | //! is more efficient than the normal range creation for ordered ranges. | |
195 | //! | |
196 | //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be | |
197 | //! unique values. | |
198 | //! | |
199 | //! <b>Complexity</b>: Linear in N. | |
200 | //! | |
201 | //! <b>Note</b>: Non-standard extension. | |
202 | set( ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare() | |
203 | , const allocator_type& a = allocator_type()) | |
204 | : base_t(ordered_range, il.begin(), il.end(), comp, a) | |
205 | {} | |
206 | #endif | |
207 | ||
208 | //! <b>Effects</b>: Copy constructs a set. | |
209 | //! | |
210 | //! <b>Complexity</b>: Linear in x.size(). | |
211 | set(const set& x) | |
212 | : base_t(static_cast<const base_t&>(x)) | |
213 | {} | |
214 | ||
215 | //! <b>Effects</b>: Move constructs a set. Constructs *this using x's resources. | |
216 | //! | |
217 | //! <b>Complexity</b>: Constant. | |
218 | //! | |
219 | //! <b>Postcondition</b>: x is emptied. | |
220 | set(BOOST_RV_REF(set) x) | |
221 | BOOST_NOEXCEPT_IF(boost::container::container_detail::is_nothrow_move_constructible<Compare>::value) | |
222 | : base_t(BOOST_MOVE_BASE(base_t, x)) | |
223 | {} | |
224 | ||
225 | //! <b>Effects</b>: Copy constructs a set using the specified allocator. | |
226 | //! | |
227 | //! <b>Complexity</b>: Linear in x.size(). | |
228 | set(const set& x, const allocator_type &a) | |
229 | : base_t(static_cast<const base_t&>(x), a) | |
230 | {} | |
231 | ||
232 | //! <b>Effects</b>: Move constructs a set using the specified allocator. | |
233 | //! Constructs *this using x's resources. | |
234 | //! | |
235 | //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise. | |
236 | set(BOOST_RV_REF(set) x, const allocator_type &a) | |
237 | : base_t(BOOST_MOVE_BASE(base_t, x), a) | |
238 | {} | |
239 | ||
240 | //! <b>Effects</b>: Makes *this a copy of x. | |
241 | //! | |
242 | //! <b>Complexity</b>: Linear in x.size(). | |
243 | set& operator=(BOOST_COPY_ASSIGN_REF(set) x) | |
244 | { return static_cast<set&>(this->base_t::operator=(static_cast<const base_t&>(x))); } | |
245 | ||
246 | //! <b>Effects</b>: this->swap(x.get()). | |
247 | //! | |
248 | //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment | |
249 | //! is false and (allocation throws or value_type's move constructor throws) | |
250 | //! | |
251 | //! <b>Complexity</b>: Constant if allocator_traits_type:: | |
252 | //! propagate_on_container_move_assignment is true or | |
253 | //! this->get>allocator() == x.get_allocator(). Linear otherwise. | |
254 | set& operator=(BOOST_RV_REF(set) x) | |
255 | BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value || | |
256 | allocator_traits_type::is_always_equal::value) && | |
257 | boost::container::container_detail::is_nothrow_move_assignable<Compare>::value) | |
258 | { return static_cast<set&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); } | |
259 | ||
260 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
261 | //! <b>Effects</b>: Copy all elements from il to *this. | |
262 | //! | |
263 | //! <b>Complexity</b>: Linear in il.size(). | |
264 | set& operator=(std::initializer_list<value_type> il) | |
265 | { | |
266 | this->clear(); | |
267 | insert(il.begin(), il.end()); | |
268 | return *this; | |
269 | } | |
270 | #endif | |
271 | ||
272 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
273 | ||
274 | //! <b>Effects</b>: Returns a copy of the allocator that | |
275 | //! was passed to the object's constructor. | |
276 | //! | |
277 | //! <b>Complexity</b>: Constant. | |
278 | allocator_type get_allocator() const; | |
279 | ||
280 | //! <b>Effects</b>: Returns a reference to the internal allocator. | |
281 | //! | |
282 | //! <b>Throws</b>: Nothing | |
283 | //! | |
284 | //! <b>Complexity</b>: Constant. | |
285 | //! | |
286 | //! <b>Note</b>: Non-standard extension. | |
287 | stored_allocator_type &get_stored_allocator(); | |
288 | ||
289 | //! <b>Effects</b>: Returns a reference to the internal allocator. | |
290 | //! | |
291 | //! <b>Throws</b>: Nothing | |
292 | //! | |
293 | //! <b>Complexity</b>: Constant. | |
294 | //! | |
295 | //! <b>Note</b>: Non-standard extension. | |
296 | const stored_allocator_type &get_stored_allocator() const; | |
297 | ||
298 | //! <b>Effects</b>: Returns an iterator to the first element contained in the container. | |
299 | //! | |
300 | //! <b>Throws</b>: Nothing. | |
301 | //! | |
302 | //! <b>Complexity</b>: Constant | |
303 | iterator begin(); | |
304 | ||
305 | //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container. | |
306 | //! | |
307 | //! <b>Throws</b>: Nothing. | |
308 | //! | |
309 | //! <b>Complexity</b>: Constant. | |
310 | const_iterator begin() const; | |
311 | ||
312 | //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container. | |
313 | //! | |
314 | //! <b>Throws</b>: Nothing. | |
315 | //! | |
316 | //! <b>Complexity</b>: Constant. | |
317 | const_iterator cbegin() const; | |
318 | ||
319 | //! <b>Effects</b>: Returns an iterator to the end of the container. | |
320 | //! | |
321 | //! <b>Throws</b>: Nothing. | |
322 | //! | |
323 | //! <b>Complexity</b>: Constant. | |
324 | iterator end(); | |
325 | ||
326 | //! <b>Effects</b>: Returns a const_iterator to the end of the container. | |
327 | //! | |
328 | //! <b>Throws</b>: Nothing. | |
329 | //! | |
330 | //! <b>Complexity</b>: Constant. | |
331 | const_iterator end() const; | |
332 | ||
333 | //! <b>Effects</b>: Returns a const_iterator to the end of the container. | |
334 | //! | |
335 | //! <b>Throws</b>: Nothing. | |
336 | //! | |
337 | //! <b>Complexity</b>: Constant. | |
338 | const_iterator cend() const; | |
339 | ||
340 | //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning | |
341 | //! of the reversed container. | |
342 | //! | |
343 | //! <b>Throws</b>: Nothing. | |
344 | //! | |
345 | //! <b>Complexity</b>: Constant. | |
346 | reverse_iterator rbegin(); | |
347 | ||
348 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning | |
349 | //! of the reversed container. | |
350 | //! | |
351 | //! <b>Throws</b>: Nothing. | |
352 | //! | |
353 | //! <b>Complexity</b>: Constant. | |
354 | const_reverse_iterator rbegin() const; | |
355 | ||
356 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning | |
357 | //! of the reversed container. | |
358 | //! | |
359 | //! <b>Throws</b>: Nothing. | |
360 | //! | |
361 | //! <b>Complexity</b>: Constant. | |
362 | const_reverse_iterator crbegin() const; | |
363 | ||
364 | //! <b>Effects</b>: Returns a reverse_iterator pointing to the end | |
365 | //! of the reversed container. | |
366 | //! | |
367 | //! <b>Throws</b>: Nothing. | |
368 | //! | |
369 | //! <b>Complexity</b>: Constant. | |
370 | reverse_iterator rend(); | |
371 | ||
372 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end | |
373 | //! of the reversed container. | |
374 | //! | |
375 | //! <b>Throws</b>: Nothing. | |
376 | //! | |
377 | //! <b>Complexity</b>: Constant. | |
378 | const_reverse_iterator rend() const; | |
379 | ||
380 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end | |
381 | //! of the reversed container. | |
382 | //! | |
383 | //! <b>Throws</b>: Nothing. | |
384 | //! | |
385 | //! <b>Complexity</b>: Constant. | |
386 | const_reverse_iterator crend() const; | |
387 | ||
388 | //! <b>Effects</b>: Returns true if the container contains no elements. | |
389 | //! | |
390 | //! <b>Throws</b>: Nothing. | |
391 | //! | |
392 | //! <b>Complexity</b>: Constant. | |
393 | bool empty() const; | |
394 | ||
395 | //! <b>Effects</b>: Returns the number of the elements contained in the container. | |
396 | //! | |
397 | //! <b>Throws</b>: Nothing. | |
398 | //! | |
399 | //! <b>Complexity</b>: Constant. | |
400 | size_type size() const; | |
401 | ||
402 | //! <b>Effects</b>: Returns the largest possible size of the container. | |
403 | //! | |
404 | //! <b>Throws</b>: Nothing. | |
405 | //! | |
406 | //! <b>Complexity</b>: Constant. | |
407 | size_type max_size() const; | |
408 | #endif // #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
409 | ||
410 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
411 | ||
412 | //! <b>Effects</b>: Inserts an object x of type Key constructed with | |
413 | //! std::forward<Args>(args)... if and only if there is | |
414 | //! no element in the container with equivalent value. | |
415 | //! and returns the iterator pointing to the | |
416 | //! newly inserted element. | |
417 | //! | |
418 | //! <b>Returns</b>: The bool component of the returned pair is true if and only | |
419 | //! if the insertion takes place, and the iterator component of the pair | |
420 | //! points to the element with key equivalent to the key of x. | |
421 | //! | |
422 | //! <b>Throws</b>: If memory allocation throws or | |
423 | //! Key's in-place constructor throws. | |
424 | //! | |
425 | //! <b>Complexity</b>: Logarithmic. | |
426 | template <class... Args> | |
427 | std::pair<iterator,bool> emplace(BOOST_FWD_REF(Args)... args) | |
428 | { return this->base_t::emplace_unique(boost::forward<Args>(args)...); } | |
429 | ||
430 | //! <b>Effects</b>: Inserts an object of type Key constructed with | |
431 | //! std::forward<Args>(args)... if and only if there is | |
432 | //! no element in the container with equivalent value. | |
433 | //! p is a hint pointing to where the insert | |
434 | //! should start to search. | |
435 | //! | |
436 | //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x. | |
437 | //! | |
438 | //! <b>Complexity</b>: Logarithmic. | |
439 | template <class... Args> | |
440 | iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args) | |
441 | { return this->base_t::emplace_hint_unique(p, boost::forward<Args>(args)...); } | |
442 | ||
443 | #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
444 | ||
445 | #define BOOST_CONTAINER_SET_EMPLACE_CODE(N) \ | |
446 | BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ | |
447 | std::pair<iterator,bool> emplace(BOOST_MOVE_UREF##N)\ | |
448 | { return this->base_t::emplace_unique(BOOST_MOVE_FWD##N); }\ | |
449 | \ | |
450 | BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ | |
451 | iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ | |
452 | { return this->base_t::emplace_hint_unique(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\ | |
453 | // | |
454 | BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SET_EMPLACE_CODE) | |
455 | #undef BOOST_CONTAINER_SET_EMPLACE_CODE | |
456 | ||
457 | #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
458 | ||
459 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
460 | //! <b>Effects</b>: Inserts x if and only if there is no element in the container | |
461 | //! with key equivalent to the key of x. | |
462 | //! | |
463 | //! <b>Returns</b>: The bool component of the returned pair is true if and only | |
464 | //! if the insertion takes place, and the iterator component of the pair | |
465 | //! points to the element with key equivalent to the key of x. | |
466 | //! | |
467 | //! <b>Complexity</b>: Logarithmic. | |
468 | std::pair<iterator, bool> insert(const value_type &x); | |
469 | ||
470 | //! <b>Effects</b>: Move constructs a new value from x if and only if there is | |
471 | //! no element in the container with key equivalent to the key of x. | |
472 | //! | |
473 | //! <b>Returns</b>: The bool component of the returned pair is true if and only | |
474 | //! if the insertion takes place, and the iterator component of the pair | |
475 | //! points to the element with key equivalent to the key of x. | |
476 | //! | |
477 | //! <b>Complexity</b>: Logarithmic. | |
478 | std::pair<iterator, bool> insert(value_type &&x); | |
479 | #else | |
480 | private: | |
481 | typedef std::pair<iterator, bool> insert_return_pair; | |
482 | public: | |
483 | BOOST_MOVE_CONVERSION_AWARE_CATCH(insert, value_type, insert_return_pair, this->priv_insert) | |
484 | #endif | |
485 | ||
486 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
487 | //! <b>Effects</b>: Inserts a copy of x in the container if and only if there is | |
488 | //! no element in the container with key equivalent to the key of x. | |
489 | //! p is a hint pointing to where the insert should start to search. | |
490 | //! | |
491 | //! <b>Returns</b>: An iterator pointing to the element with key equivalent | |
492 | //! to the key of x. | |
493 | //! | |
494 | //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t | |
495 | //! is inserted right before p. | |
496 | iterator insert(const_iterator p, const value_type &x); | |
497 | ||
498 | //! <b>Effects</b>: Inserts an element move constructed from x in the container. | |
499 | //! p is a hint pointing to where the insert should start to search. | |
500 | //! | |
501 | //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x. | |
502 | //! | |
503 | //! <b>Complexity</b>: Logarithmic. | |
504 | iterator insert(const_iterator p, value_type &&x); | |
505 | #else | |
506 | BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, value_type, iterator, this->priv_insert, const_iterator, const_iterator) | |
507 | #endif | |
508 | ||
509 | //! <b>Requires</b>: first, last are not iterators into *this. | |
510 | //! | |
511 | //! <b>Effects</b>: inserts each element from the range [first,last) if and only | |
512 | //! if there is no element with key equivalent to the key of that element. | |
513 | //! | |
514 | //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last) | |
515 | template <class InputIterator> | |
516 | void insert(InputIterator first, InputIterator last) | |
517 | { this->base_t::insert_unique(first, last); } | |
518 | ||
519 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
520 | //! <b>Effects</b>: inserts each element from the range [il.begin(),il.end()) if and only | |
521 | //! if there is no element with key equivalent to the key of that element. | |
522 | //! | |
523 | //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end()) | |
524 | void insert(std::initializer_list<value_type> il) | |
525 | { this->base_t::insert_unique(il.begin(), il.end()); } | |
526 | #endif | |
527 | ||
528 | //! @copydoc ::boost::container::map::insert(node_type&&) | |
529 | insert_return_type insert(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh) | |
530 | { return this->base_t::insert_unique_node(boost::move(nh)); } | |
531 | ||
532 | //! @copydoc ::boost::container::map::insert(const_iterator, node_type&&) | |
533 | insert_return_type insert(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh) | |
534 | { return this->base_t::insert_unique_node(hint, boost::move(nh)); } | |
535 | ||
536 | //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&) | |
537 | template<class C2> | |
538 | BOOST_CONTAINER_FORCEINLINE void merge(set<Key, C2, Allocator, Options>& source) | |
539 | { | |
540 | typedef container_detail::tree | |
541 | <Key, container_detail::identity<Key>, C2, Allocator, Options> base2_t; | |
542 | this->base_t::merge_unique(static_cast<base2_t&>(source)); | |
543 | } | |
544 | ||
545 | //! @copydoc ::boost::container::set::merge(set<Key, C2, Allocator, Options>&) | |
546 | template<class C2> | |
547 | BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG set<Key, C2, Allocator, Options> BOOST_RV_REF_END source) | |
548 | { return this->merge(static_cast<set<Key, C2, Allocator, Options>&>(source)); } | |
549 | ||
550 | //! @copydoc ::boost::container::map::merge(multimap<Key, T, C2, Allocator, Options>&) | |
551 | template<class C2> | |
552 | BOOST_CONTAINER_FORCEINLINE void merge(multiset<Key, C2, Allocator, Options>& source) | |
553 | { | |
554 | typedef container_detail::tree | |
555 | <Key, container_detail::identity<Key>, C2, Allocator, Options> base2_t; | |
556 | this->base_t::merge_unique(static_cast<base2_t&>(source)); | |
557 | } | |
558 | ||
559 | //! @copydoc ::boost::container::set::merge(multiset<Key, C2, Allocator, Options>&) | |
560 | template<class C2> | |
561 | BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG multiset<Key, C2, Allocator, Options> BOOST_RV_REF_END source) | |
562 | { return this->merge(static_cast<multiset<Key, C2, Allocator, Options>&>(source)); } | |
563 | ||
564 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
565 | ||
566 | //! <b>Effects</b>: Erases the element pointed to by p. | |
567 | //! | |
568 | //! <b>Returns</b>: Returns an iterator pointing to the element immediately | |
569 | //! following q prior to the element being erased. If no such element exists, | |
570 | //! returns end(). | |
571 | //! | |
572 | //! <b>Complexity</b>: Amortized constant time | |
573 | iterator erase(const_iterator p); | |
574 | ||
575 | //! <b>Effects</b>: Erases all elements in the container with key equivalent to x. | |
576 | //! | |
577 | //! <b>Returns</b>: Returns the number of erased elements. | |
578 | //! | |
579 | //! <b>Complexity</b>: log(size()) + count(k) | |
580 | size_type erase(const key_type& x); | |
581 | ||
582 | //! <b>Effects</b>: Erases all the elements in the range [first, last). | |
583 | //! | |
584 | //! <b>Returns</b>: Returns last. | |
585 | //! | |
586 | //! <b>Complexity</b>: log(size())+N where N is the distance from first to last. | |
587 | iterator erase(const_iterator first, const_iterator last); | |
588 | ||
589 | //! <b>Effects</b>: Swaps the contents of *this and x. | |
590 | //! | |
591 | //! <b>Throws</b>: Nothing. | |
592 | //! | |
593 | //! <b>Complexity</b>: Constant. | |
594 | void swap(set& x) | |
595 | BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value | |
596 | && boost::container::container_detail::is_nothrow_swappable<Compare>::value ); | |
597 | ||
598 | //! <b>Effects</b>: erase(a.begin(),a.end()). | |
599 | //! | |
600 | //! <b>Postcondition</b>: size() == 0. | |
601 | //! | |
602 | //! <b>Complexity</b>: linear in size(). | |
603 | void clear(); | |
604 | ||
605 | //! <b>Effects</b>: Returns the comparison object out | |
606 | //! of which a was constructed. | |
607 | //! | |
608 | //! <b>Complexity</b>: Constant. | |
609 | key_compare key_comp() const; | |
610 | ||
611 | //! <b>Effects</b>: Returns an object of value_compare constructed out | |
612 | //! of the comparison object. | |
613 | //! | |
614 | //! <b>Complexity</b>: Constant. | |
615 | value_compare value_comp() const; | |
616 | ||
617 | //! <b>Returns</b>: An iterator pointing to an element with the key | |
618 | //! equivalent to x, or end() if such an element is not found. | |
619 | //! | |
620 | //! <b>Complexity</b>: Logarithmic. | |
621 | iterator find(const key_type& x); | |
622 | ||
623 | //! <b>Returns</b>: A const_iterator pointing to an element with the key | |
624 | //! equivalent to x, or end() if such an element is not found. | |
625 | //! | |
626 | //! <b>Complexity</b>: Logarithmic. | |
627 | const_iterator find(const key_type& x) const; | |
628 | ||
629 | #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
630 | ||
631 | //! <b>Returns</b>: The number of elements with key equivalent to x. | |
632 | //! | |
633 | //! <b>Complexity</b>: log(size())+count(k) | |
634 | size_type count(const key_type& x) const | |
635 | { return static_cast<size_type>(this->base_t::find(x) != this->base_t::cend()); } | |
636 | ||
637 | //! <b>Returns</b>: The number of elements with key equivalent to x. | |
638 | //! | |
639 | //! <b>Complexity</b>: log(size())+count(k) | |
640 | size_type count(const key_type& x) | |
641 | { return static_cast<size_type>(this->base_t::find(x) != this->base_t::end()); } | |
642 | ||
643 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
644 | ||
645 | //! <b>Returns</b>: An iterator pointing to the first element with key not less | |
646 | //! than k, or a.end() if such an element is not found. | |
647 | //! | |
648 | //! <b>Complexity</b>: Logarithmic | |
649 | iterator lower_bound(const key_type& x); | |
650 | ||
651 | //! <b>Returns</b>: A const iterator pointing to the first element with key not | |
652 | //! less than k, or a.end() if such an element is not found. | |
653 | //! | |
654 | //! <b>Complexity</b>: Logarithmic | |
655 | const_iterator lower_bound(const key_type& x) const; | |
656 | ||
657 | //! <b>Returns</b>: An iterator pointing to the first element with key not less | |
658 | //! than x, or end() if such an element is not found. | |
659 | //! | |
660 | //! <b>Complexity</b>: Logarithmic | |
661 | iterator upper_bound(const key_type& x); | |
662 | ||
663 | //! <b>Returns</b>: A const iterator pointing to the first element with key not | |
664 | //! less than x, or end() if such an element is not found. | |
665 | //! | |
666 | //! <b>Complexity</b>: Logarithmic | |
667 | const_iterator upper_bound(const key_type& x) const; | |
668 | ||
669 | #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
670 | ||
671 | //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)). | |
672 | //! | |
673 | //! <b>Complexity</b>: Logarithmic | |
674 | std::pair<iterator,iterator> equal_range(const key_type& x) | |
675 | { return this->base_t::lower_bound_range(x); } | |
676 | ||
677 | //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)). | |
678 | //! | |
679 | //! <b>Complexity</b>: Logarithmic | |
680 | std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const | |
681 | { return this->base_t::lower_bound_range(x); } | |
682 | ||
683 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
684 | ||
685 | //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)). | |
686 | //! | |
687 | //! <b>Complexity</b>: Logarithmic | |
688 | std::pair<iterator,iterator> equal_range(const key_type& x); | |
689 | ||
690 | //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)). | |
691 | //! | |
692 | //! <b>Complexity</b>: Logarithmic | |
693 | std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const; | |
694 | ||
695 | //! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees. | |
696 | //! | |
697 | //! <b>Complexity</b>: Linear | |
698 | void rebalance(); | |
699 | ||
700 | //! <b>Effects</b>: Returns true if x and y are equal | |
701 | //! | |
702 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
703 | friend bool operator==(const set& x, const set& y); | |
704 | ||
705 | //! <b>Effects</b>: Returns true if x and y are unequal | |
706 | //! | |
707 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
708 | friend bool operator!=(const set& x, const set& y); | |
709 | ||
710 | //! <b>Effects</b>: Returns true if x is less than y | |
711 | //! | |
712 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
713 | friend bool operator<(const set& x, const set& y); | |
714 | ||
715 | //! <b>Effects</b>: Returns true if x is greater than y | |
716 | //! | |
717 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
718 | friend bool operator>(const set& x, const set& y); | |
719 | ||
720 | //! <b>Effects</b>: Returns true if x is equal or less than y | |
721 | //! | |
722 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
723 | friend bool operator<=(const set& x, const set& y); | |
724 | ||
725 | //! <b>Effects</b>: Returns true if x is equal or greater than y | |
726 | //! | |
727 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
728 | friend bool operator>=(const set& x, const set& y); | |
729 | ||
730 | //! <b>Effects</b>: x.swap(y) | |
731 | //! | |
732 | //! <b>Complexity</b>: Constant. | |
733 | friend void swap(set& x, set& y); | |
734 | ||
735 | #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
736 | ||
737 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
738 | private: | |
739 | template <class KeyType> | |
740 | std::pair<iterator, bool> priv_insert(BOOST_FWD_REF(KeyType) x) | |
741 | { return this->base_t::insert_unique(::boost::forward<KeyType>(x)); } | |
742 | ||
743 | template <class KeyType> | |
744 | iterator priv_insert(const_iterator p, BOOST_FWD_REF(KeyType) x) | |
745 | { return this->base_t::insert_unique(p, ::boost::forward<KeyType>(x)); } | |
746 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
747 | }; | |
748 | ||
749 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
750 | ||
751 | } //namespace container { | |
752 | ||
753 | //!has_trivial_destructor_after_move<> == true_type | |
754 | //!specialization for optimizations | |
755 | template <class Key, class Compare, class Options, class Allocator> | |
756 | struct has_trivial_destructor_after_move<boost::container::set<Key, Compare, Allocator, Options> > | |
757 | { | |
758 | typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer; | |
759 | static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value && | |
760 | ::boost::has_trivial_destructor_after_move<pointer>::value && | |
761 | ::boost::has_trivial_destructor_after_move<Compare>::value; | |
762 | }; | |
763 | ||
764 | namespace container { | |
765 | ||
766 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
767 | ||
768 | #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED | |
769 | ||
770 | //! A multiset is a kind of associative container that supports equivalent keys | |
771 | //! (possibly contains multiple copies of the same key value) and provides for | |
772 | //! fast retrieval of the keys themselves. Class multiset supports bidirectional iterators. | |
773 | //! | |
774 | //! A multiset satisfies all of the requirements of a container and of a reversible | |
775 | //! container, and of an associative container). multiset also provides most operations | |
776 | //! described for duplicate keys. | |
777 | //! | |
778 | //! \tparam Key is the type to be inserted in the set, which is also the key_type | |
779 | //! \tparam Compare is the comparison functor used to order keys | |
780 | //! \tparam Allocator is the allocator to be used to allocate memory for this container | |
781 | //! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options. | |
782 | template <class Key, class Compare = std::less<Key>, class Allocator = new_allocator<Key>, class Options = tree_assoc_defaults > | |
783 | #else | |
784 | template <class Key, class Compare, class Allocator, class Options> | |
785 | #endif | |
786 | class multiset | |
787 | /// @cond | |
788 | : public container_detail::tree | |
789 | <Key,container_detail::identity<Key>, Compare, Allocator, Options> | |
790 | /// @endcond | |
791 | { | |
792 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
793 | private: | |
794 | BOOST_COPYABLE_AND_MOVABLE(multiset) | |
795 | typedef container_detail::tree | |
796 | <Key,container_detail::identity<Key>, Compare, Allocator, Options> base_t; | |
797 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
798 | ||
799 | public: | |
800 | ||
801 | ////////////////////////////////////////////// | |
802 | // | |
803 | // types | |
804 | // | |
805 | ////////////////////////////////////////////// | |
806 | typedef Key key_type; | |
807 | typedef Key value_type; | |
808 | typedef Compare key_compare; | |
809 | typedef Compare value_compare; | |
810 | typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type; | |
811 | typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer; | |
812 | typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer; | |
813 | typedef typename ::boost::container::allocator_traits<Allocator>::reference reference; | |
814 | typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference; | |
815 | typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type; | |
816 | typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type; | |
817 | typedef Allocator allocator_type; | |
818 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type; | |
819 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator; | |
820 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator; | |
821 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator; | |
822 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator; | |
823 | typedef typename BOOST_CONTAINER_IMPDEF(base_t::node_type) node_type; | |
824 | ||
825 | ////////////////////////////////////////////// | |
826 | // | |
827 | // construct/copy/destroy | |
828 | // | |
829 | ////////////////////////////////////////////// | |
830 | ||
831 | //! @copydoc ::boost::container::set::set() | |
832 | multiset() BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value && | |
833 | container_detail::is_nothrow_default_constructible<Compare>::value) | |
834 | : base_t() | |
835 | {} | |
836 | ||
837 | //! @copydoc ::boost::container::set::set(const Compare&, const allocator_type&) | |
838 | explicit multiset(const Compare& comp, | |
839 | const allocator_type& a = allocator_type()) | |
840 | : base_t(comp, a) | |
841 | {} | |
842 | ||
843 | //! @copydoc ::boost::container::set::set(const allocator_type&) | |
844 | explicit multiset(const allocator_type& a) | |
845 | : base_t(a) | |
846 | {} | |
847 | ||
848 | //! @copydoc ::boost::container::set::set(InputIterator, InputIterator, const Compare& comp, const allocator_type&) | |
849 | template <class InputIterator> | |
850 | multiset(InputIterator first, InputIterator last, | |
851 | const Compare& comp = Compare(), | |
852 | const allocator_type& a = allocator_type()) | |
853 | : base_t(false, first, last, comp, a) | |
854 | {} | |
855 | ||
856 | //! @copydoc ::boost::container::set::set(InputIterator, InputIterator, const allocator_type&) | |
857 | template <class InputIterator> | |
858 | multiset(InputIterator first, InputIterator last, const allocator_type& a) | |
859 | : base_t(false, first, last, key_compare(), a) | |
860 | {} | |
861 | ||
862 | //! <b>Effects</b>: Constructs an empty multiset using the specified comparison object and | |
863 | //! allocator, and inserts elements from the ordered range [first ,last ). This function | |
864 | //! is more efficient than the normal range creation for ordered ranges. | |
865 | //! | |
866 | //! <b>Requires</b>: [first ,last) must be ordered according to the predicate. | |
867 | //! | |
868 | //! <b>Complexity</b>: Linear in N. | |
869 | //! | |
870 | //! <b>Note</b>: Non-standard extension. | |
871 | template <class InputIterator> | |
872 | multiset( ordered_range_t, InputIterator first, InputIterator last | |
873 | , const Compare& comp = Compare() | |
874 | , const allocator_type& a = allocator_type()) | |
875 | : base_t(ordered_range, first, last, comp, a) | |
876 | {} | |
877 | ||
878 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
879 | //! @copydoc ::boost::container::set::set(std::initializer_list<value_type>, const Compare& comp, const allocator_type&) | |
880 | multiset(std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) | |
881 | : base_t(false, il.begin(), il.end(), comp, a) | |
882 | {} | |
883 | ||
884 | //! @copydoc ::boost::container::set::set(std::initializer_list<value_type>, const allocator_type&) | |
885 | multiset(std::initializer_list<value_type> il, const allocator_type& a) | |
886 | : base_t(false, il.begin(), il.end(), Compare(), a) | |
887 | {} | |
888 | ||
889 | //! @copydoc ::boost::container::set::set(ordered_unique_range_t, std::initializer_list<value_type>, const Compare& comp, const allocator_type&) | |
890 | multiset(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) | |
891 | : base_t(ordered_range, il.begin(), il.end(), comp, a) | |
892 | {} | |
893 | #endif | |
894 | ||
895 | //! @copydoc ::boost::container::set::set(const set &) | |
896 | multiset(const multiset& x) | |
897 | : base_t(static_cast<const base_t&>(x)) | |
898 | {} | |
899 | ||
900 | //! @copydoc ::boost::container::set::set(set &&) | |
901 | multiset(BOOST_RV_REF(multiset) x) | |
902 | BOOST_NOEXCEPT_IF(boost::container::container_detail::is_nothrow_move_constructible<Compare>::value) | |
903 | : base_t(BOOST_MOVE_BASE(base_t, x)) | |
904 | {} | |
905 | ||
906 | //! @copydoc ::boost::container::set::set(const set &, const allocator_type &) | |
907 | multiset(const multiset& x, const allocator_type &a) | |
908 | : base_t(static_cast<const base_t&>(x), a) | |
909 | {} | |
910 | ||
911 | //! @copydoc ::boost::container::set::set(set &&, const allocator_type &) | |
912 | multiset(BOOST_RV_REF(multiset) x, const allocator_type &a) | |
913 | : base_t(BOOST_MOVE_BASE(base_t, x), a) | |
914 | {} | |
915 | ||
916 | //! @copydoc ::boost::container::set::operator=(const set &) | |
917 | multiset& operator=(BOOST_COPY_ASSIGN_REF(multiset) x) | |
918 | { return static_cast<multiset&>(this->base_t::operator=(static_cast<const base_t&>(x))); } | |
919 | ||
920 | //! @copydoc ::boost::container::set::operator=(set &&) | |
921 | multiset& operator=(BOOST_RV_REF(multiset) x) | |
922 | BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value || | |
923 | allocator_traits_type::is_always_equal::value) && | |
924 | boost::container::container_detail::is_nothrow_move_assignable<Compare>::value) | |
925 | { return static_cast<multiset&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); } | |
926 | ||
927 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
928 | //! @copydoc ::boost::container::set::operator=(std::initializer_list<value_type>) | |
929 | multiset& operator=(std::initializer_list<value_type> il) | |
930 | { | |
931 | this->clear(); | |
932 | insert(il.begin(), il.end()); | |
933 | return *this; | |
934 | } | |
935 | #endif | |
936 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
937 | ||
938 | //! @copydoc ::boost::container::set::get_allocator() | |
939 | allocator_type get_allocator() const; | |
940 | ||
941 | //! @copydoc ::boost::container::set::get_stored_allocator() | |
942 | stored_allocator_type &get_stored_allocator(); | |
943 | ||
944 | //! @copydoc ::boost::container::set::get_stored_allocator() const | |
945 | const stored_allocator_type &get_stored_allocator() const; | |
946 | ||
947 | //! @copydoc ::boost::container::set::begin() | |
948 | iterator begin(); | |
949 | ||
950 | //! @copydoc ::boost::container::set::begin() const | |
951 | const_iterator begin() const; | |
952 | ||
953 | //! @copydoc ::boost::container::set::cbegin() const | |
954 | const_iterator cbegin() const; | |
955 | ||
956 | //! @copydoc ::boost::container::set::end() | |
957 | iterator end() BOOST_NOEXCEPT_OR_NOTHROW; | |
958 | ||
959 | //! @copydoc ::boost::container::set::end() const | |
960 | const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW; | |
961 | ||
962 | //! @copydoc ::boost::container::set::cend() const | |
963 | const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW; | |
964 | ||
965 | //! @copydoc ::boost::container::set::rbegin() | |
966 | reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW; | |
967 | ||
968 | //! @copydoc ::boost::container::set::rbegin() const | |
969 | const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW; | |
970 | ||
971 | //! @copydoc ::boost::container::set::crbegin() const | |
972 | const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW; | |
973 | ||
974 | //! @copydoc ::boost::container::set::rend() | |
975 | reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW; | |
976 | ||
977 | //! @copydoc ::boost::container::set::rend() const | |
978 | const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW; | |
979 | ||
980 | //! @copydoc ::boost::container::set::crend() const | |
981 | const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW; | |
982 | ||
983 | //! @copydoc ::boost::container::set::empty() const | |
984 | bool empty() const; | |
985 | ||
986 | //! @copydoc ::boost::container::set::size() const | |
987 | size_type size() const; | |
988 | ||
989 | //! @copydoc ::boost::container::set::max_size() const | |
990 | size_type max_size() const; | |
991 | ||
992 | #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
993 | ||
994 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
995 | ||
996 | //! <b>Effects</b>: Inserts an object of type Key constructed with | |
997 | //! std::forward<Args>(args)... and returns the iterator pointing to the | |
998 | //! newly inserted element. | |
999 | //! | |
1000 | //! <b>Complexity</b>: Logarithmic. | |
1001 | template <class... Args> | |
1002 | iterator emplace(BOOST_FWD_REF(Args)... args) | |
1003 | { return this->base_t::emplace_equal(boost::forward<Args>(args)...); } | |
1004 | ||
1005 | //! <b>Effects</b>: Inserts an object of type Key constructed with | |
1006 | //! std::forward<Args>(args)... | |
1007 | //! | |
1008 | //! <b>Returns</b>: An iterator pointing to the element with key equivalent | |
1009 | //! to the key of x. | |
1010 | //! | |
1011 | //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t | |
1012 | //! is inserted right before p. | |
1013 | template <class... Args> | |
1014 | iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args) | |
1015 | { return this->base_t::emplace_hint_equal(p, boost::forward<Args>(args)...); } | |
1016 | ||
1017 | #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
1018 | ||
1019 | #define BOOST_CONTAINER_MULTISET_EMPLACE_CODE(N) \ | |
1020 | BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ | |
1021 | iterator emplace(BOOST_MOVE_UREF##N)\ | |
1022 | { return this->base_t::emplace_equal(BOOST_MOVE_FWD##N); }\ | |
1023 | \ | |
1024 | BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ | |
1025 | iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ | |
1026 | { return this->base_t::emplace_hint_equal(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\ | |
1027 | // | |
1028 | BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_MULTISET_EMPLACE_CODE) | |
1029 | #undef BOOST_CONTAINER_MULTISET_EMPLACE_CODE | |
1030 | ||
1031 | #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
1032 | ||
1033 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
1034 | //! <b>Effects</b>: Inserts x and returns the iterator pointing to the | |
1035 | //! newly inserted element. | |
1036 | //! | |
1037 | //! <b>Complexity</b>: Logarithmic. | |
1038 | iterator insert(const value_type &x); | |
1039 | ||
1040 | //! <b>Effects</b>: Inserts a copy of x in the container. | |
1041 | //! | |
1042 | //! <b>Returns</b>: An iterator pointing to the element with key equivalent | |
1043 | //! to the key of x. | |
1044 | //! | |
1045 | //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t | |
1046 | //! is inserted right before p. | |
1047 | iterator insert(value_type &&x); | |
1048 | #else | |
1049 | BOOST_MOVE_CONVERSION_AWARE_CATCH(insert, value_type, iterator, this->priv_insert) | |
1050 | #endif | |
1051 | ||
1052 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
1053 | //! <b>Effects</b>: Inserts a copy of x in the container. | |
1054 | //! p is a hint pointing to where the insert should start to search. | |
1055 | //! | |
1056 | //! <b>Returns</b>: An iterator pointing to the element with key equivalent | |
1057 | //! to the key of x. | |
1058 | //! | |
1059 | //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t | |
1060 | //! is inserted right before p. | |
1061 | iterator insert(const_iterator p, const value_type &x); | |
1062 | ||
1063 | //! <b>Effects</b>: Inserts a value move constructed from x in the container. | |
1064 | //! p is a hint pointing to where the insert should start to search. | |
1065 | //! | |
1066 | //! <b>Returns</b>: An iterator pointing to the element with key equivalent | |
1067 | //! to the key of x. | |
1068 | //! | |
1069 | //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t | |
1070 | //! is inserted right before p. | |
1071 | iterator insert(const_iterator p, value_type &&x); | |
1072 | #else | |
1073 | BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, value_type, iterator, this->priv_insert, const_iterator, const_iterator) | |
1074 | #endif | |
1075 | ||
1076 | //! <b>Requires</b>: first, last are not iterators into *this. | |
1077 | //! | |
1078 | //! <b>Effects</b>: inserts each element from the range [first,last) . | |
1079 | //! | |
1080 | //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last) | |
1081 | template <class InputIterator> | |
1082 | void insert(InputIterator first, InputIterator last) | |
1083 | { this->base_t::insert_equal(first, last); } | |
1084 | ||
1085 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
1086 | //! @copydoc ::boost::container::set::insert(std::initializer_list<value_type>) | |
1087 | void insert(std::initializer_list<value_type> il) | |
1088 | { this->base_t::insert_equal(il.begin(), il.end()); } | |
1089 | #endif | |
1090 | ||
1091 | //! @copydoc ::boost::container::multimap::insert(node_type&&) | |
1092 | iterator insert(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh) | |
1093 | { return this->base_t::insert_equal_node(boost::move(nh)); } | |
1094 | ||
1095 | //! @copydoc ::boost::container::multimap::insert(const_iterator, node_type&&) | |
1096 | iterator insert(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh) | |
1097 | { return this->base_t::insert_equal_node(hint, boost::move(nh)); } | |
1098 | ||
1099 | //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&) | |
1100 | template<class C2> | |
1101 | BOOST_CONTAINER_FORCEINLINE void merge(multiset<Key, C2, Allocator, Options>& source) | |
1102 | { | |
1103 | typedef container_detail::tree | |
1104 | <Key, container_detail::identity<Key>, C2, Allocator, Options> base2_t; | |
1105 | this->base_t::merge_equal(static_cast<base2_t&>(source)); | |
1106 | } | |
1107 | ||
1108 | //! @copydoc ::boost::container::multiset::merge(multiset<Key, C2, Allocator, Options>&) | |
1109 | template<class C2> | |
1110 | BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG multiset<Key, C2, Allocator, Options> BOOST_RV_REF_END source) | |
1111 | { return this->merge(static_cast<multiset<Key, C2, Allocator, Options>&>(source)); } | |
1112 | ||
1113 | //! @copydoc ::boost::container::multimap::merge(map<Key, T, C2, Allocator, Options>&) | |
1114 | template<class C2> | |
1115 | BOOST_CONTAINER_FORCEINLINE void merge(set<Key, C2, Allocator, Options>& source) | |
1116 | { | |
1117 | typedef container_detail::tree | |
1118 | <Key, container_detail::identity<Key>, C2, Allocator, Options> base2_t; | |
1119 | this->base_t::merge_equal(static_cast<base2_t&>(source)); | |
1120 | } | |
1121 | ||
1122 | //! @copydoc ::boost::container::multiset::merge(set<Key, C2, Allocator, Options>&) | |
1123 | template<class C2> | |
1124 | BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG set<Key, C2, Allocator, Options> BOOST_RV_REF_END source) | |
1125 | { return this->merge(static_cast<set<Key, C2, Allocator, Options>&>(source)); } | |
1126 | ||
1127 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
1128 | ||
1129 | //! @copydoc ::boost::container::set::erase(const_iterator) | |
1130 | iterator erase(const_iterator p); | |
1131 | ||
1132 | //! @copydoc ::boost::container::set::erase(const key_type&) | |
1133 | size_type erase(const key_type& x); | |
1134 | ||
1135 | //! @copydoc ::boost::container::set::erase(const_iterator,const_iterator) | |
1136 | iterator erase(const_iterator first, const_iterator last); | |
1137 | ||
1138 | //! @copydoc ::boost::container::set::swap | |
1139 | void swap(multiset& x) | |
1140 | BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value | |
1141 | && boost::container::container_detail::is_nothrow_swappable<Compare>::value ); | |
1142 | ||
1143 | //! @copydoc ::boost::container::set::clear | |
1144 | void clear() BOOST_NOEXCEPT_OR_NOTHROW; | |
1145 | ||
1146 | //! @copydoc ::boost::container::set::key_comp | |
1147 | key_compare key_comp() const; | |
1148 | ||
1149 | //! @copydoc ::boost::container::set::value_comp | |
1150 | value_compare value_comp() const; | |
1151 | ||
1152 | //! @copydoc ::boost::container::set::find(const key_type& ) | |
1153 | iterator find(const key_type& x); | |
1154 | ||
1155 | //! @copydoc ::boost::container::set::find(const key_type& ) const | |
1156 | const_iterator find(const key_type& x) const; | |
1157 | ||
1158 | //! @copydoc ::boost::container::set::count(const key_type& ) const | |
1159 | size_type count(const key_type& x) const; | |
1160 | ||
1161 | //! @copydoc ::boost::container::set::lower_bound(const key_type& ) | |
1162 | iterator lower_bound(const key_type& x); | |
1163 | ||
1164 | //! @copydoc ::boost::container::set::lower_bound(const key_type& ) const | |
1165 | const_iterator lower_bound(const key_type& x) const; | |
1166 | ||
1167 | //! @copydoc ::boost::container::set::upper_bound(const key_type& ) | |
1168 | iterator upper_bound(const key_type& x); | |
1169 | ||
1170 | //! @copydoc ::boost::container::set::upper_bound(const key_type& ) const | |
1171 | const_iterator upper_bound(const key_type& x) const; | |
1172 | ||
1173 | //! @copydoc ::boost::container::set::equal_range(const key_type& ) const | |
1174 | std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const; | |
1175 | ||
1176 | //! @copydoc ::boost::container::set::equal_range(const key_type& ) | |
1177 | std::pair<iterator,iterator> equal_range(const key_type& x); | |
1178 | ||
1179 | //! @copydoc ::boost::container::set::rebalance() | |
1180 | void rebalance(); | |
1181 | ||
1182 | //! <b>Effects</b>: Returns true if x and y are equal | |
1183 | //! | |
1184 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1185 | friend bool operator==(const multiset& x, const multiset& y); | |
1186 | ||
1187 | //! <b>Effects</b>: Returns true if x and y are unequal | |
1188 | //! | |
1189 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1190 | friend bool operator!=(const multiset& x, const multiset& y); | |
1191 | ||
1192 | //! <b>Effects</b>: Returns true if x is less than y | |
1193 | //! | |
1194 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1195 | friend bool operator<(const multiset& x, const multiset& y); | |
1196 | ||
1197 | //! <b>Effects</b>: Returns true if x is greater than y | |
1198 | //! | |
1199 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1200 | friend bool operator>(const multiset& x, const multiset& y); | |
1201 | ||
1202 | //! <b>Effects</b>: Returns true if x is equal or less than y | |
1203 | //! | |
1204 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1205 | friend bool operator<=(const multiset& x, const multiset& y); | |
1206 | ||
1207 | //! <b>Effects</b>: Returns true if x is equal or greater than y | |
1208 | //! | |
1209 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1210 | friend bool operator>=(const multiset& x, const multiset& y); | |
1211 | ||
1212 | //! <b>Effects</b>: x.swap(y) | |
1213 | //! | |
1214 | //! <b>Complexity</b>: Constant. | |
1215 | friend void swap(multiset& x, multiset& y); | |
1216 | ||
1217 | #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
1218 | ||
1219 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1220 | private: | |
1221 | template <class KeyType> | |
1222 | iterator priv_insert(BOOST_FWD_REF(KeyType) x) | |
1223 | { return this->base_t::insert_equal(::boost::forward<KeyType>(x)); } | |
1224 | ||
1225 | template <class KeyType> | |
1226 | iterator priv_insert(const_iterator p, BOOST_FWD_REF(KeyType) x) | |
1227 | { return this->base_t::insert_equal(p, ::boost::forward<KeyType>(x)); } | |
1228 | ||
1229 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1230 | }; | |
1231 | ||
1232 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1233 | ||
1234 | } //namespace container { | |
1235 | ||
1236 | //!has_trivial_destructor_after_move<> == true_type | |
1237 | //!specialization for optimizations | |
1238 | template <class Key, class Compare, class Allocator, class Options> | |
1239 | struct has_trivial_destructor_after_move<boost::container::multiset<Key, Compare, Allocator, Options> > | |
1240 | { | |
1241 | typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer; | |
1242 | static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value && | |
1243 | ::boost::has_trivial_destructor_after_move<pointer>::value && | |
1244 | ::boost::has_trivial_destructor_after_move<Compare>::value; | |
1245 | }; | |
1246 | ||
1247 | namespace container { | |
1248 | ||
1249 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1250 | ||
1251 | }} | |
1252 | ||
1253 | #include <boost/container/detail/config_end.hpp> | |
1254 | ||
1255 | #endif // BOOST_CONTAINER_SET_HPP |