]>
Commit | Line | Data |
---|---|---|
42526146 PE |
1 | // Multiset implementation -*- C++ -*- |
2 | ||
83ffe9cd | 3 | // Copyright (C) 2001-2023 Free Software Foundation, Inc. |
42526146 PE |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
42526146 PE |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
42526146 | 19 | |
748086b7 JJ |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
42526146 | 24 | |
725dc051 BK |
25 | /* |
26 | * | |
27 | * Copyright (c) 1994 | |
28 | * Hewlett-Packard Company | |
29 | * | |
30 | * Permission to use, copy, modify, distribute and sell this software | |
31 | * and its documentation for any purpose is hereby granted without fee, | |
32 | * provided that the above copyright notice appear in all copies and | |
33 | * that both that copyright notice and this permission notice appear | |
34 | * in supporting documentation. Hewlett-Packard Company makes no | |
35 | * representations about the suitability of this software for any | |
36 | * purpose. It is provided "as is" without express or implied warranty. | |
37 | * | |
38 | * | |
39 | * Copyright (c) 1996 | |
40 | * Silicon Graphics Computer Systems, Inc. | |
41 | * | |
42 | * Permission to use, copy, modify, distribute and sell this software | |
43 | * and its documentation for any purpose is hereby granted without fee, | |
44 | * provided that the above copyright notice appear in all copies and | |
45 | * that both that copyright notice and this permission notice appear | |
46 | * in supporting documentation. Silicon Graphics makes no | |
47 | * representations about the suitability of this software for any | |
48 | * purpose. It is provided "as is" without express or implied warranty. | |
49 | */ | |
50 | ||
f910786b | 51 | /** @file bits/stl_multiset.h |
729e3d3f | 52 | * This is an internal header file, included by other library headers. |
f910786b | 53 | * Do not attempt to use it directly. @headername{set} |
725dc051 BK |
54 | */ |
55 | ||
046d30f4 PC |
56 | #ifndef _STL_MULTISET_H |
57 | #define _STL_MULTISET_H 1 | |
725dc051 | 58 | |
30a20a1e | 59 | #include <bits/concept_check.h> |
734f5023 | 60 | #if __cplusplus >= 201103L |
988499f4 | 61 | #include <initializer_list> |
a7d5d7e2 | 62 | #endif |
725dc051 | 63 | |
12ffa228 BK |
64 | namespace std _GLIBCXX_VISIBILITY(default) |
65 | { | |
4a15d842 | 66 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
12ffa228 | 67 | _GLIBCXX_BEGIN_NAMESPACE_CONTAINER |
725dc051 | 68 | |
2dbe56bd JW |
69 | template<typename _Key, typename _Compare, typename _Alloc> |
70 | class set; | |
71 | ||
ffcec5c8 JQ |
72 | /** |
73 | * @brief A standard container made up of elements, which can be retrieved | |
74 | * in logarithmic time. | |
75 | * | |
aac2878e | 76 | * @ingroup associative_containers |
ffcec5c8 | 77 | * |
d632488a BK |
78 | * |
79 | * @tparam _Key Type of key objects. | |
80 | * @tparam _Compare Comparison function object type, defaults to less<_Key>. | |
81 | * @tparam _Alloc Allocator type, defaults to allocator<_Key>. | |
82 | * | |
ffcec5c8 JQ |
83 | * Meets the requirements of a <a href="tables.html#65">container</a>, a |
84 | * <a href="tables.html#66">reversible container</a>, and an | |
85 | * <a href="tables.html#69">associative container</a> (using equivalent | |
86 | * keys). For a @c multiset<Key> the key_type and value_type are Key. | |
87 | * | |
88 | * Multisets support bidirectional iterators. | |
89 | * | |
ffcec5c8 JQ |
90 | * The private tree data is declared exactly the same way for set and |
91 | * multiset; the distinction is made entirely in how the tree functions are | |
92 | * called (*_unique versus *_equal, same as the standard). | |
ffcec5c8 | 93 | */ |
78b36b70 PC |
94 | template <typename _Key, typename _Compare = std::less<_Key>, |
95 | typename _Alloc = std::allocator<_Key> > | |
f6592a9e PC |
96 | class multiset |
97 | { | |
fe62dd04 | 98 | #ifdef _GLIBCXX_CONCEPT_CHECKS |
f6592a9e | 99 | // concept requirements |
fe62dd04 FD |
100 | typedef typename _Alloc::value_type _Alloc_value_type; |
101 | # if __cplusplus < 201103L | |
f6592a9e | 102 | __glibcxx_class_requires(_Key, _SGIAssignableConcept) |
fe62dd04 | 103 | # endif |
f6592a9e PC |
104 | __glibcxx_class_requires4(_Compare, bool, _Key, _Key, |
105 | _BinaryFunctionConcept) | |
fe62dd04 FD |
106 | __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept) |
107 | #endif | |
ed6814f7 | 108 | |
866e4d38 JW |
109 | #if __cplusplus >= 201103L |
110 | static_assert(is_same<typename remove_cv<_Key>::type, _Key>::value, | |
111 | "std::multiset must have a non-const, non-volatile value_type"); | |
ebaf3659 | 112 | # if __cplusplus > 201703L || defined __STRICT_ANSI__ |
866e4d38 JW |
113 | static_assert(is_same<typename _Alloc::value_type, _Key>::value, |
114 | "std::multiset must have the same value_type as its allocator"); | |
115 | # endif | |
116 | #endif | |
117 | ||
f6592a9e PC |
118 | public: |
119 | // typedefs: | |
120 | typedef _Key key_type; | |
121 | typedef _Key value_type; | |
122 | typedef _Compare key_compare; | |
123 | typedef _Compare value_compare; | |
4fd20a8f | 124 | typedef _Alloc allocator_type; |
ed6814f7 | 125 | |
f6592a9e | 126 | private: |
4312e020 | 127 | /// This turns a red-black tree into a [multi]set. |
ff90a89e JW |
128 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
129 | rebind<_Key>::other _Key_alloc_type; | |
4fd20a8f PC |
130 | |
131 | typedef _Rb_tree<key_type, value_type, _Identity<value_type>, | |
132 | key_compare, _Key_alloc_type> _Rep_type; | |
4312e020 | 133 | /// The actual tree structure. |
f6592a9e PC |
134 | _Rep_type _M_t; |
135 | ||
ff90a89e JW |
136 | typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits; |
137 | ||
f6592a9e | 138 | public: |
fe62dd04 FD |
139 | typedef typename _Alloc_traits::pointer pointer; |
140 | typedef typename _Alloc_traits::const_pointer const_pointer; | |
141 | typedef typename _Alloc_traits::reference reference; | |
142 | typedef typename _Alloc_traits::const_reference const_reference; | |
1d4eb925 PC |
143 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
144 | // DR 103. set::iterator is required to be modifiable, | |
145 | // but this allows modification of keys. | |
fe62dd04 FD |
146 | typedef typename _Rep_type::const_iterator iterator; |
147 | typedef typename _Rep_type::const_iterator const_iterator; | |
148 | typedef typename _Rep_type::const_reverse_iterator reverse_iterator; | |
e6a05448 | 149 | typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; |
fe62dd04 FD |
150 | typedef typename _Rep_type::size_type size_type; |
151 | typedef typename _Rep_type::difference_type difference_type; | |
4fd20a8f | 152 | |
2dbe56bd JW |
153 | #if __cplusplus > 201402L |
154 | using node_type = typename _Rep_type::node_type; | |
155 | #endif | |
156 | ||
4fd20a8f | 157 | // allocation/deallocation |
4fd20a8f PC |
158 | /** |
159 | * @brief Default constructor creates no elements. | |
160 | */ | |
d72c3f0a FD |
161 | #if __cplusplus < 201103L |
162 | multiset() : _M_t() { } | |
163 | #else | |
164 | multiset() = default; | |
165 | #endif | |
f6592a9e | 166 | |
78b36b70 PC |
167 | /** |
168 | * @brief Creates a %multiset with no elements. | |
93c66bc6 BK |
169 | * @param __comp Comparator to use. |
170 | * @param __a An allocator object. | |
78b36b70 | 171 | */ |
7c920151 PC |
172 | explicit |
173 | multiset(const _Compare& __comp, | |
174 | const allocator_type& __a = allocator_type()) | |
ff15f019 | 175 | : _M_t(__comp, _Key_alloc_type(__a)) { } |
f6592a9e PC |
176 | |
177 | /** | |
178 | * @brief Builds a %multiset from a range. | |
93c66bc6 BK |
179 | * @param __first An input iterator. |
180 | * @param __last An input iterator. | |
f6592a9e PC |
181 | * |
182 | * Create a %multiset consisting of copies of the elements from | |
183 | * [first,last). This is linear in N if the range is already sorted, | |
93c66bc6 | 184 | * and NlogN otherwise (where N is distance(__first,__last)). |
f6592a9e | 185 | */ |
78b36b70 | 186 | template<typename _InputIterator> |
fe62dd04 | 187 | multiset(_InputIterator __first, _InputIterator __last) |
78b36b70 | 188 | : _M_t() |
83a840a9 | 189 | { _M_t._M_insert_range_equal(__first, __last); } |
f6592a9e PC |
190 | |
191 | /** | |
192 | * @brief Builds a %multiset from a range. | |
93c66bc6 BK |
193 | * @param __first An input iterator. |
194 | * @param __last An input iterator. | |
195 | * @param __comp A comparison functor. | |
196 | * @param __a An allocator object. | |
f6592a9e PC |
197 | * |
198 | * Create a %multiset consisting of copies of the elements from | |
93c66bc6 BK |
199 | * [__first,__last). This is linear in N if the range is already sorted, |
200 | * and NlogN otherwise (where N is distance(__first,__last)). | |
f6592a9e | 201 | */ |
78b36b70 | 202 | template<typename _InputIterator> |
fe62dd04 | 203 | multiset(_InputIterator __first, _InputIterator __last, |
f6592a9e PC |
204 | const _Compare& __comp, |
205 | const allocator_type& __a = allocator_type()) | |
ff15f019 | 206 | : _M_t(__comp, _Key_alloc_type(__a)) |
83a840a9 | 207 | { _M_t._M_insert_range_equal(__first, __last); } |
f6592a9e PC |
208 | |
209 | /** | |
210 | * @brief %Multiset copy constructor. | |
f6592a9e | 211 | * |
a4dec0d6 | 212 | * Whether the allocator is copied depends on the allocator traits. |
f6592a9e | 213 | */ |
a4dec0d6 | 214 | #if __cplusplus < 201103L |
78b36b70 | 215 | multiset(const multiset& __x) |
f6592a9e | 216 | : _M_t(__x._M_t) { } |
a4dec0d6 FD |
217 | #else |
218 | multiset(const multiset&) = default; | |
f6592a9e | 219 | |
78b36b70 PC |
220 | /** |
221 | * @brief %Multiset move constructor. | |
78b36b70 | 222 | * |
a4dec0d6 FD |
223 | * The newly-created %multiset contains the exact contents of the |
224 | * moved instance. The moved instance is a valid, but unspecified | |
225 | * %multiset. | |
78b36b70 | 226 | */ |
a4dec0d6 | 227 | multiset(multiset&&) = default; |
988499f4 JM |
228 | |
229 | /** | |
230 | * @brief Builds a %multiset from an initializer_list. | |
93c66bc6 BK |
231 | * @param __l An initializer_list. |
232 | * @param __comp A comparison functor. | |
233 | * @param __a An allocator object. | |
988499f4 JM |
234 | * |
235 | * Create a %multiset consisting of copies of the elements from | |
236 | * the list. This is linear in N if the list is already sorted, | |
93c66bc6 | 237 | * and NlogN otherwise (where N is @a __l.size()). |
988499f4 JM |
238 | */ |
239 | multiset(initializer_list<value_type> __l, | |
240 | const _Compare& __comp = _Compare(), | |
241 | const allocator_type& __a = allocator_type()) | |
ff15f019 | 242 | : _M_t(__comp, _Key_alloc_type(__a)) |
83a840a9 | 243 | { _M_t._M_insert_range_equal(__l.begin(), __l.end()); } |
ff90a89e JW |
244 | |
245 | /// Allocator-extended default constructor. | |
246 | explicit | |
247 | multiset(const allocator_type& __a) | |
538a7cd0 | 248 | : _M_t(_Key_alloc_type(__a)) { } |
ff90a89e JW |
249 | |
250 | /// Allocator-extended copy constructor. | |
22d34a2a JW |
251 | multiset(const multiset& __m, |
252 | const __type_identity_t<allocator_type>& __a) | |
ff90a89e JW |
253 | : _M_t(__m._M_t, _Key_alloc_type(__a)) { } |
254 | ||
255 | /// Allocator-extended move constructor. | |
22d34a2a | 256 | multiset(multiset&& __m, const __type_identity_t<allocator_type>& __a) |
ff90a89e JW |
257 | noexcept(is_nothrow_copy_constructible<_Compare>::value |
258 | && _Alloc_traits::_S_always_equal()) | |
259 | : _M_t(std::move(__m._M_t), _Key_alloc_type(__a)) { } | |
260 | ||
261 | /// Allocator-extended initialier-list constructor. | |
262 | multiset(initializer_list<value_type> __l, const allocator_type& __a) | |
538a7cd0 | 263 | : _M_t(_Key_alloc_type(__a)) |
83a840a9 | 264 | { _M_t._M_insert_range_equal(__l.begin(), __l.end()); } |
ff90a89e JW |
265 | |
266 | /// Allocator-extended range constructor. | |
267 | template<typename _InputIterator> | |
fe62dd04 | 268 | multiset(_InputIterator __first, _InputIterator __last, |
ff90a89e | 269 | const allocator_type& __a) |
538a7cd0 | 270 | : _M_t(_Key_alloc_type(__a)) |
83a840a9 | 271 | { _M_t._M_insert_range_equal(__first, __last); } |
a4dec0d6 FD |
272 | |
273 | /** | |
274 | * The dtor only erases the elements, and note that if the elements | |
275 | * themselves are pointers, the pointed-to memory is not touched in any | |
276 | * way. Managing the pointer is the user's responsibility. | |
277 | */ | |
278 | ~multiset() = default; | |
78b36b70 PC |
279 | #endif |
280 | ||
f6592a9e PC |
281 | /** |
282 | * @brief %Multiset assignment operator. | |
0a2bf188 JW |
283 | * |
284 | * Whether the allocator is copied depends on the allocator traits. | |
f6592a9e | 285 | */ |
a4dec0d6 | 286 | #if __cplusplus < 201103L |
78b36b70 PC |
287 | multiset& |
288 | operator=(const multiset& __x) | |
f6592a9e | 289 | { |
ed6814f7 | 290 | _M_t = __x._M_t; |
f6592a9e PC |
291 | return *this; |
292 | } | |
a4dec0d6 FD |
293 | #else |
294 | multiset& | |
295 | operator=(const multiset&) = default; | |
ed6814f7 | 296 | |
c6195f58 | 297 | /// Move assignment operator. |
78b36b70 | 298 | multiset& |
c6195f58 | 299 | operator=(multiset&&) = default; |
988499f4 JM |
300 | |
301 | /** | |
302 | * @brief %Multiset list assignment operator. | |
93c66bc6 | 303 | * @param __l An initializer_list. |
988499f4 JM |
304 | * |
305 | * This function fills a %multiset with copies of the elements in the | |
93c66bc6 | 306 | * initializer list @a __l. |
988499f4 JM |
307 | * |
308 | * Note that the assignment completely changes the %multiset and | |
309 | * that the resulting %multiset's size is the same as the number | |
0a2bf188 | 310 | * of elements assigned. |
988499f4 JM |
311 | */ |
312 | multiset& | |
313 | operator=(initializer_list<value_type> __l) | |
314 | { | |
c6195f58 | 315 | _M_t._M_assign_equal(__l.begin(), __l.end()); |
988499f4 JM |
316 | return *this; |
317 | } | |
78b36b70 PC |
318 | #endif |
319 | ||
f6592a9e | 320 | // accessors: |
ed6814f7 | 321 | |
f6592a9e PC |
322 | /// Returns the comparison object. |
323 | key_compare | |
324 | key_comp() const | |
325 | { return _M_t.key_comp(); } | |
326 | /// Returns the comparison object. | |
327 | value_compare | |
328 | value_comp() const | |
329 | { return _M_t.key_comp(); } | |
330 | /// Returns the memory allocation object. | |
331 | allocator_type | |
d3677132 | 332 | get_allocator() const _GLIBCXX_NOEXCEPT |
ff15f019 | 333 | { return allocator_type(_M_t.get_allocator()); } |
ed6814f7 | 334 | |
f6592a9e | 335 | /** |
0cd50f89 PC |
336 | * Returns a read-only (constant) iterator that points to the first |
337 | * element in the %multiset. Iteration is done in ascending order | |
338 | * according to the keys. | |
f6592a9e PC |
339 | */ |
340 | iterator | |
d3677132 | 341 | begin() const _GLIBCXX_NOEXCEPT |
f6592a9e PC |
342 | { return _M_t.begin(); } |
343 | ||
344 | /** | |
0cd50f89 PC |
345 | * Returns a read-only (constant) iterator that points one past the last |
346 | * element in the %multiset. Iteration is done in ascending order | |
347 | * according to the keys. | |
f6592a9e PC |
348 | */ |
349 | iterator | |
d3677132 | 350 | end() const _GLIBCXX_NOEXCEPT |
f6592a9e | 351 | { return _M_t.end(); } |
ed6814f7 | 352 | |
f6592a9e | 353 | /** |
0cd50f89 PC |
354 | * Returns a read-only (constant) reverse iterator that points to the |
355 | * last element in the %multiset. Iteration is done in descending order | |
356 | * according to the keys. | |
f6592a9e PC |
357 | */ |
358 | reverse_iterator | |
d3677132 | 359 | rbegin() const _GLIBCXX_NOEXCEPT |
ed6814f7 BI |
360 | { return _M_t.rbegin(); } |
361 | ||
f6592a9e | 362 | /** |
0cd50f89 PC |
363 | * Returns a read-only (constant) reverse iterator that points to the |
364 | * last element in the %multiset. Iteration is done in descending order | |
365 | * according to the keys. | |
f6592a9e PC |
366 | */ |
367 | reverse_iterator | |
d3677132 | 368 | rend() const _GLIBCXX_NOEXCEPT |
f6592a9e | 369 | { return _M_t.rend(); } |
ed6814f7 | 370 | |
734f5023 | 371 | #if __cplusplus >= 201103L |
0cd50f89 PC |
372 | /** |
373 | * Returns a read-only (constant) iterator that points to the first | |
374 | * element in the %multiset. Iteration is done in ascending order | |
375 | * according to the keys. | |
376 | */ | |
377 | iterator | |
d3677132 | 378 | cbegin() const noexcept |
0cd50f89 PC |
379 | { return _M_t.begin(); } |
380 | ||
381 | /** | |
382 | * Returns a read-only (constant) iterator that points one past the last | |
383 | * element in the %multiset. Iteration is done in ascending order | |
384 | * according to the keys. | |
385 | */ | |
386 | iterator | |
d3677132 | 387 | cend() const noexcept |
0cd50f89 PC |
388 | { return _M_t.end(); } |
389 | ||
390 | /** | |
391 | * Returns a read-only (constant) reverse iterator that points to the | |
392 | * last element in the %multiset. Iteration is done in descending order | |
393 | * according to the keys. | |
394 | */ | |
395 | reverse_iterator | |
d3677132 | 396 | crbegin() const noexcept |
0cd50f89 PC |
397 | { return _M_t.rbegin(); } |
398 | ||
399 | /** | |
400 | * Returns a read-only (constant) reverse iterator that points to the | |
401 | * last element in the %multiset. Iteration is done in descending order | |
402 | * according to the keys. | |
403 | */ | |
404 | reverse_iterator | |
d3677132 | 405 | crend() const noexcept |
0cd50f89 PC |
406 | { return _M_t.rend(); } |
407 | #endif | |
408 | ||
f6592a9e | 409 | /// Returns true if the %set is empty. |
d715f554 | 410 | _GLIBCXX_NODISCARD bool |
d3677132 | 411 | empty() const _GLIBCXX_NOEXCEPT |
f6592a9e | 412 | { return _M_t.empty(); } |
ed6814f7 | 413 | |
f6592a9e PC |
414 | /// Returns the size of the %set. |
415 | size_type | |
d3677132 | 416 | size() const _GLIBCXX_NOEXCEPT |
f6592a9e | 417 | { return _M_t.size(); } |
ed6814f7 | 418 | |
f6592a9e PC |
419 | /// Returns the maximum size of the %set. |
420 | size_type | |
d3677132 | 421 | max_size() const _GLIBCXX_NOEXCEPT |
f6592a9e | 422 | { return _M_t.max_size(); } |
ed6814f7 | 423 | |
f6592a9e PC |
424 | /** |
425 | * @brief Swaps data with another %multiset. | |
93c66bc6 | 426 | * @param __x A %multiset of the same element and allocator types. |
f6592a9e PC |
427 | * |
428 | * This exchanges the elements between two multisets in constant time. | |
429 | * (It is only swapping a pointer, an integer, and an instance of the @c | |
430 | * Compare type (which itself is often stateless and empty), so it should | |
431 | * be quite fast.) | |
432 | * Note that the global std::swap() function is specialized such that | |
433 | * std::swap(s1,s2) will feed to this function. | |
0a2bf188 JW |
434 | * |
435 | * Whether the allocators are swapped depends on the allocator traits. | |
f6592a9e PC |
436 | */ |
437 | void | |
78b36b70 | 438 | swap(multiset& __x) |
c5d9ec56 | 439 | _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value) |
f6592a9e | 440 | { _M_t.swap(__x._M_t); } |
ed6814f7 | 441 | |
f6592a9e | 442 | // insert/erase |
734f5023 | 443 | #if __cplusplus >= 201103L |
55826ab6 FD |
444 | /** |
445 | * @brief Builds and inserts an element into the %multiset. | |
446 | * @param __args Arguments used to generate the element instance to be | |
447 | * inserted. | |
448 | * @return An iterator that points to the inserted element. | |
449 | * | |
450 | * This function inserts an element into the %multiset. Contrary | |
451 | * to a std::set the %multiset does not rely on unique keys and thus | |
452 | * multiple copies of the same element can be inserted. | |
453 | * | |
454 | * Insertion requires logarithmic time. | |
455 | */ | |
456 | template<typename... _Args> | |
457 | iterator | |
458 | emplace(_Args&&... __args) | |
459 | { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); } | |
460 | ||
461 | /** | |
462 | * @brief Builds and inserts an element into the %multiset. | |
463 | * @param __pos An iterator that serves as a hint as to where the | |
464 | * element should be inserted. | |
465 | * @param __args Arguments used to generate the element instance to be | |
466 | * inserted. | |
467 | * @return An iterator that points to the inserted element. | |
468 | * | |
469 | * This function inserts an element into the %multiset. Contrary | |
470 | * to a std::set the %multiset does not rely on unique keys and thus | |
471 | * multiple copies of the same element can be inserted. | |
472 | * | |
473 | * Note that the first parameter is only a hint and can potentially | |
474 | * improve the performance of the insertion process. A bad hint would | |
475 | * cause no gains in efficiency. | |
476 | * | |
10d43d2f | 477 | * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints |
55826ab6 FD |
478 | * for more on @a hinting. |
479 | * | |
480 | * Insertion requires logarithmic time (if the hint is not taken). | |
481 | */ | |
482 | template<typename... _Args> | |
483 | iterator | |
484 | emplace_hint(const_iterator __pos, _Args&&... __args) | |
485 | { | |
486 | return _M_t._M_emplace_hint_equal(__pos, | |
487 | std::forward<_Args>(__args)...); | |
488 | } | |
489 | #endif | |
490 | ||
f6592a9e PC |
491 | /** |
492 | * @brief Inserts an element into the %multiset. | |
93c66bc6 | 493 | * @param __x Element to be inserted. |
f6592a9e PC |
494 | * @return An iterator that points to the inserted element. |
495 | * | |
496 | * This function inserts an element into the %multiset. Contrary | |
497 | * to a std::set the %multiset does not rely on unique keys and thus | |
498 | * multiple copies of the same element can be inserted. | |
499 | * | |
500 | * Insertion requires logarithmic time. | |
501 | */ | |
502 | iterator | |
503 | insert(const value_type& __x) | |
42a27024 | 504 | { return _M_t._M_insert_equal(__x); } |
ed6814f7 | 505 | |
734f5023 | 506 | #if __cplusplus >= 201103L |
e6a05448 PC |
507 | iterator |
508 | insert(value_type&& __x) | |
509 | { return _M_t._M_insert_equal(std::move(__x)); } | |
510 | #endif | |
511 | ||
f6592a9e PC |
512 | /** |
513 | * @brief Inserts an element into the %multiset. | |
93c66bc6 | 514 | * @param __position An iterator that serves as a hint as to where the |
f6592a9e | 515 | * element should be inserted. |
93c66bc6 | 516 | * @param __x Element to be inserted. |
f6592a9e PC |
517 | * @return An iterator that points to the inserted element. |
518 | * | |
519 | * This function inserts an element into the %multiset. Contrary | |
520 | * to a std::set the %multiset does not rely on unique keys and thus | |
521 | * multiple copies of the same element can be inserted. | |
522 | * | |
523 | * Note that the first parameter is only a hint and can potentially | |
524 | * improve the performance of the insertion process. A bad hint would | |
525 | * cause no gains in efficiency. | |
526 | * | |
10d43d2f | 527 | * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints |
2a60a9f6 | 528 | * for more on @a hinting. |
f6592a9e PC |
529 | * |
530 | * Insertion requires logarithmic time (if the hint is not taken). | |
531 | */ | |
532 | iterator | |
7606bd11 | 533 | insert(const_iterator __position, const value_type& __x) |
dc4871cb | 534 | { return _M_t._M_insert_equal_(__position, __x); } |
f6592a9e | 535 | |
734f5023 | 536 | #if __cplusplus >= 201103L |
e6a05448 PC |
537 | iterator |
538 | insert(const_iterator __position, value_type&& __x) | |
539 | { return _M_t._M_insert_equal_(__position, std::move(__x)); } | |
540 | #endif | |
541 | ||
f6592a9e | 542 | /** |
2a60a9f6 | 543 | * @brief A template function that tries to insert a range of elements. |
93c66bc6 BK |
544 | * @param __first Iterator pointing to the start of the range to be |
545 | * inserted. | |
546 | * @param __last Iterator pointing to the end of the range. | |
f6592a9e PC |
547 | * |
548 | * Complexity similar to that of the range constructor. | |
549 | */ | |
78b36b70 | 550 | template<typename _InputIterator> |
fe62dd04 FD |
551 | void |
552 | insert(_InputIterator __first, _InputIterator __last) | |
83a840a9 | 553 | { _M_t._M_insert_range_equal(__first, __last); } |
f6592a9e | 554 | |
734f5023 | 555 | #if __cplusplus >= 201103L |
988499f4 JM |
556 | /** |
557 | * @brief Attempts to insert a list of elements into the %multiset. | |
93c66bc6 BK |
558 | * @param __l A std::initializer_list<value_type> of elements |
559 | * to be inserted. | |
988499f4 JM |
560 | * |
561 | * Complexity similar to that of the range constructor. | |
562 | */ | |
563 | void | |
564 | insert(initializer_list<value_type> __l) | |
565 | { this->insert(__l.begin(), __l.end()); } | |
566 | #endif | |
567 | ||
2dbe56bd JW |
568 | #if __cplusplus > 201402L |
569 | /// Extract a node. | |
570 | node_type | |
571 | extract(const_iterator __pos) | |
976160b9 JW |
572 | { |
573 | __glibcxx_assert(__pos != end()); | |
574 | return _M_t.extract(__pos); | |
575 | } | |
2dbe56bd JW |
576 | |
577 | /// Extract a node. | |
578 | node_type | |
579 | extract(const key_type& __x) | |
580 | { return _M_t.extract(__x); } | |
581 | ||
582 | /// Re-insert an extracted node. | |
583 | iterator | |
584 | insert(node_type&& __nh) | |
585 | { return _M_t._M_reinsert_node_equal(std::move(__nh)); } | |
586 | ||
587 | /// Re-insert an extracted node. | |
588 | iterator | |
589 | insert(const_iterator __hint, node_type&& __nh) | |
590 | { return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); } | |
591 | ||
592 | template<typename, typename> | |
0e5abeb0 | 593 | friend struct std::_Rb_tree_merge_helper; |
2dbe56bd JW |
594 | |
595 | template<typename _Compare1> | |
596 | void | |
597 | merge(multiset<_Key, _Compare1, _Alloc>& __source) | |
598 | { | |
599 | using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>; | |
600 | _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source)); | |
601 | } | |
602 | ||
603 | template<typename _Compare1> | |
604 | void | |
605 | merge(multiset<_Key, _Compare1, _Alloc>&& __source) | |
606 | { merge(__source); } | |
607 | ||
608 | template<typename _Compare1> | |
609 | void | |
610 | merge(set<_Key, _Compare1, _Alloc>& __source) | |
611 | { | |
612 | using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>; | |
613 | _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source)); | |
614 | } | |
615 | ||
616 | template<typename _Compare1> | |
617 | void | |
618 | merge(set<_Key, _Compare1, _Alloc>&& __source) | |
619 | { merge(__source); } | |
620 | #endif // C++17 | |
621 | ||
734f5023 | 622 | #if __cplusplus >= 201103L |
c105751c ESR |
623 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
624 | // DR 130. Associative erase should return an iterator. | |
625 | /** | |
626 | * @brief Erases an element from a %multiset. | |
93c66bc6 | 627 | * @param __position An iterator pointing to the element to be erased. |
c105751c | 628 | * @return An iterator pointing to the element immediately following |
fe62dd04 | 629 | * @a position prior to the element being erased. If no such |
c105751c ESR |
630 | * element exists, end() is returned. |
631 | * | |
632 | * This function erases an element, pointed to by the given iterator, | |
633 | * from a %multiset. Note that this function only erases the element, | |
634 | * and that if the element is itself a pointer, the pointed-to memory is | |
635 | * not touched in any way. Managing the pointer is the user's | |
636 | * responsibility. | |
637 | */ | |
3b31a727 | 638 | _GLIBCXX_ABI_TAG_CXX11 |
c105751c | 639 | iterator |
7606bd11 | 640 | erase(const_iterator __position) |
c105751c ESR |
641 | { return _M_t.erase(__position); } |
642 | #else | |
f6592a9e PC |
643 | /** |
644 | * @brief Erases an element from a %multiset. | |
93c66bc6 | 645 | * @param __position An iterator pointing to the element to be erased. |
f6592a9e PC |
646 | * |
647 | * This function erases an element, pointed to by the given iterator, | |
648 | * from a %multiset. Note that this function only erases the element, | |
649 | * and that if the element is itself a pointer, the pointed-to memory is | |
650 | * not touched in any way. Managing the pointer is the user's | |
28dac70a | 651 | * responsibility. |
f6592a9e PC |
652 | */ |
653 | void | |
654 | erase(iterator __position) | |
d5e07b79 | 655 | { _M_t.erase(__position); } |
c105751c | 656 | #endif |
ed6814f7 | 657 | |
f6592a9e PC |
658 | /** |
659 | * @brief Erases elements according to the provided key. | |
93c66bc6 | 660 | * @param __x Key of element to be erased. |
f6592a9e PC |
661 | * @return The number of elements erased. |
662 | * | |
663 | * This function erases all elements located by the given key from a | |
664 | * %multiset. | |
665 | * Note that this function only erases the element, and that if | |
666 | * the element is itself a pointer, the pointed-to memory is not touched | |
28dac70a | 667 | * in any way. Managing the pointer is the user's responsibility. |
f6592a9e PC |
668 | */ |
669 | size_type | |
670 | erase(const key_type& __x) | |
671 | { return _M_t.erase(__x); } | |
ed6814f7 | 672 | |
734f5023 | 673 | #if __cplusplus >= 201103L |
c105751c ESR |
674 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
675 | // DR 130. Associative erase should return an iterator. | |
676 | /** | |
677 | * @brief Erases a [first,last) range of elements from a %multiset. | |
93c66bc6 BK |
678 | * @param __first Iterator pointing to the start of the range to be |
679 | * erased. | |
680 | * @param __last Iterator pointing to the end of the range to | |
681 | * be erased. | |
c105751c ESR |
682 | * @return The iterator @a last. |
683 | * | |
684 | * This function erases a sequence of elements from a %multiset. | |
685 | * Note that this function only erases the elements, and that if | |
686 | * the elements themselves are pointers, the pointed-to memory is not | |
7606bd11 PC |
687 | * touched in any way. Managing the pointer is the user's |
688 | * responsibility. | |
c105751c | 689 | */ |
3b31a727 | 690 | _GLIBCXX_ABI_TAG_CXX11 |
c105751c | 691 | iterator |
7606bd11 | 692 | erase(const_iterator __first, const_iterator __last) |
c105751c ESR |
693 | { return _M_t.erase(__first, __last); } |
694 | #else | |
f6592a9e PC |
695 | /** |
696 | * @brief Erases a [first,last) range of elements from a %multiset. | |
697 | * @param first Iterator pointing to the start of the range to be | |
698 | * erased. | |
699 | * @param last Iterator pointing to the end of the range to be erased. | |
700 | * | |
701 | * This function erases a sequence of elements from a %multiset. | |
702 | * Note that this function only erases the elements, and that if | |
703 | * the elements themselves are pointers, the pointed-to memory is not | |
7606bd11 PC |
704 | * touched in any way. Managing the pointer is the user's |
705 | * responsibility. | |
f6592a9e PC |
706 | */ |
707 | void | |
708 | erase(iterator __first, iterator __last) | |
d5e07b79 | 709 | { _M_t.erase(__first, __last); } |
c105751c | 710 | #endif |
ed6814f7 | 711 | |
f6592a9e PC |
712 | /** |
713 | * Erases all elements in a %multiset. Note that this function only | |
714 | * erases the elements, and that if the elements themselves are pointers, | |
715 | * the pointed-to memory is not touched in any way. Managing the pointer | |
28dac70a | 716 | * is the user's responsibility. |
f6592a9e PC |
717 | */ |
718 | void | |
d3677132 | 719 | clear() _GLIBCXX_NOEXCEPT |
f6592a9e | 720 | { _M_t.clear(); } |
ed6814f7 | 721 | |
f6592a9e | 722 | // multiset operations: |
ed6814f7 | 723 | |
f0b88346 | 724 | ///@{ |
f6592a9e PC |
725 | /** |
726 | * @brief Finds the number of elements with given key. | |
93c66bc6 | 727 | * @param __x Key of elements to be located. |
f6592a9e PC |
728 | * @return Number of elements with specified key. |
729 | */ | |
730 | size_type | |
731 | count(const key_type& __x) const | |
732 | { return _M_t.count(__x); } | |
ed6814f7 | 733 | |
91c78ea5 JW |
734 | #if __cplusplus > 201103L |
735 | template<typename _Kt> | |
736 | auto | |
737 | count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) | |
738 | { return _M_t._M_count_tr(__x); } | |
739 | #endif | |
f0b88346 | 740 | ///@} |
91c78ea5 | 741 | |
3adea09e | 742 | #if __cplusplus > 201703L |
f0b88346 | 743 | ///@{ |
3adea09e JW |
744 | /** |
745 | * @brief Finds whether an element with the given key exists. | |
746 | * @param __x Key of elements to be located. | |
747 | * @return True if there is any element with the specified key. | |
748 | */ | |
749 | bool | |
750 | contains(const key_type& __x) const | |
751 | { return _M_t.find(__x) != _M_t.end(); } | |
752 | ||
753 | template<typename _Kt> | |
754 | auto | |
755 | contains(const _Kt& __x) const | |
756 | -> decltype(_M_t._M_find_tr(__x), void(), true) | |
757 | { return _M_t._M_find_tr(__x) != _M_t.end(); } | |
f0b88346 | 758 | ///@} |
3adea09e JW |
759 | #endif |
760 | ||
f6592a9e PC |
761 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
762 | // 214. set::find() missing const overload | |
f0b88346 | 763 | ///@{ |
f6592a9e PC |
764 | /** |
765 | * @brief Tries to locate an element in a %set. | |
93c66bc6 | 766 | * @param __x Element to be located. |
f6592a9e PC |
767 | * @return Iterator pointing to sought-after element, or end() if not |
768 | * found. | |
769 | * | |
770 | * This function takes a key and tries to locate the element with which | |
771 | * the key matches. If successful the function returns an iterator | |
772 | * pointing to the sought after element. If unsuccessful it returns the | |
773 | * past-the-end ( @c end() ) iterator. | |
774 | */ | |
775 | iterator | |
776 | find(const key_type& __x) | |
777 | { return _M_t.find(__x); } | |
ed6814f7 | 778 | |
f6592a9e PC |
779 | const_iterator |
780 | find(const key_type& __x) const | |
781 | { return _M_t.find(__x); } | |
91c78ea5 JW |
782 | |
783 | #if __cplusplus > 201103L | |
784 | template<typename _Kt> | |
785 | auto | |
d4a9dffb JW |
786 | find(const _Kt& __x) |
787 | -> decltype(iterator{_M_t._M_find_tr(__x)}) | |
788 | { return iterator{_M_t._M_find_tr(__x)}; } | |
91c78ea5 JW |
789 | |
790 | template<typename _Kt> | |
791 | auto | |
d4a9dffb JW |
792 | find(const _Kt& __x) const |
793 | -> decltype(const_iterator{_M_t._M_find_tr(__x)}) | |
794 | { return const_iterator{_M_t._M_find_tr(__x)}; } | |
91c78ea5 | 795 | #endif |
f0b88346 | 796 | ///@} |
ed6814f7 | 797 | |
f0b88346 | 798 | ///@{ |
f6592a9e PC |
799 | /** |
800 | * @brief Finds the beginning of a subsequence matching given key. | |
93c66bc6 | 801 | * @param __x Key to be located. |
f6592a9e PC |
802 | * @return Iterator pointing to first element equal to or greater |
803 | * than key, or end(). | |
804 | * | |
805 | * This function returns the first element of a subsequence of elements | |
806 | * that matches the given key. If unsuccessful it returns an iterator | |
807 | * pointing to the first element that has a greater value than given key | |
808 | * or end() if no such element exists. | |
809 | */ | |
810 | iterator | |
811 | lower_bound(const key_type& __x) | |
812 | { return _M_t.lower_bound(__x); } | |
ed6814f7 | 813 | |
f6592a9e PC |
814 | const_iterator |
815 | lower_bound(const key_type& __x) const | |
816 | { return _M_t.lower_bound(__x); } | |
91c78ea5 JW |
817 | |
818 | #if __cplusplus > 201103L | |
819 | template<typename _Kt> | |
820 | auto | |
821 | lower_bound(const _Kt& __x) | |
b744bf4e JW |
822 | -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) |
823 | { return iterator(_M_t._M_lower_bound_tr(__x)); } | |
91c78ea5 JW |
824 | |
825 | template<typename _Kt> | |
826 | auto | |
827 | lower_bound(const _Kt& __x) const | |
b744bf4e JW |
828 | -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) |
829 | { return iterator(_M_t._M_lower_bound_tr(__x)); } | |
91c78ea5 | 830 | #endif |
f0b88346 | 831 | ///@} |
ed6814f7 | 832 | |
f0b88346 | 833 | ///@{ |
f6592a9e PC |
834 | /** |
835 | * @brief Finds the end of a subsequence matching given key. | |
93c66bc6 | 836 | * @param __x Key to be located. |
f6592a9e PC |
837 | * @return Iterator pointing to the first element |
838 | * greater than key, or end(). | |
839 | */ | |
840 | iterator | |
841 | upper_bound(const key_type& __x) | |
842 | { return _M_t.upper_bound(__x); } | |
ed6814f7 | 843 | |
f6592a9e PC |
844 | const_iterator |
845 | upper_bound(const key_type& __x) const | |
846 | { return _M_t.upper_bound(__x); } | |
91c78ea5 JW |
847 | |
848 | #if __cplusplus > 201103L | |
849 | template<typename _Kt> | |
850 | auto | |
851 | upper_bound(const _Kt& __x) | |
b744bf4e JW |
852 | -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) |
853 | { return iterator(_M_t._M_upper_bound_tr(__x)); } | |
91c78ea5 JW |
854 | |
855 | template<typename _Kt> | |
856 | auto | |
857 | upper_bound(const _Kt& __x) const | |
b744bf4e JW |
858 | -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) |
859 | { return iterator(_M_t._M_upper_bound_tr(__x)); } | |
91c78ea5 | 860 | #endif |
f0b88346 | 861 | ///@} |
ed6814f7 | 862 | |
f0b88346 | 863 | ///@{ |
f6592a9e PC |
864 | /** |
865 | * @brief Finds a subsequence matching given key. | |
93c66bc6 | 866 | * @param __x Key to be located. |
f6592a9e PC |
867 | * @return Pair of iterators that possibly points to the subsequence |
868 | * matching given key. | |
869 | * | |
870 | * This function is equivalent to | |
871 | * @code | |
872 | * std::make_pair(c.lower_bound(val), | |
873 | * c.upper_bound(val)) | |
874 | * @endcode | |
875 | * (but is faster than making the calls separately). | |
876 | * | |
877 | * This function probably only makes sense for multisets. | |
878 | */ | |
4fd20a8f | 879 | std::pair<iterator, iterator> |
f6592a9e PC |
880 | equal_range(const key_type& __x) |
881 | { return _M_t.equal_range(__x); } | |
ed6814f7 | 882 | |
4fd20a8f | 883 | std::pair<const_iterator, const_iterator> |
f6592a9e PC |
884 | equal_range(const key_type& __x) const |
885 | { return _M_t.equal_range(__x); } | |
91c78ea5 JW |
886 | |
887 | #if __cplusplus > 201103L | |
888 | template<typename _Kt> | |
889 | auto | |
890 | equal_range(const _Kt& __x) | |
b744bf4e JW |
891 | -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x))) |
892 | { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); } | |
91c78ea5 JW |
893 | |
894 | template<typename _Kt> | |
895 | auto | |
896 | equal_range(const _Kt& __x) const | |
b744bf4e JW |
897 | -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x))) |
898 | { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); } | |
91c78ea5 | 899 | #endif |
f0b88346 | 900 | ///@} |
ed6814f7 | 901 | |
78b36b70 | 902 | template<typename _K1, typename _C1, typename _A1> |
fe62dd04 FD |
903 | friend bool |
904 | operator==(const multiset<_K1, _C1, _A1>&, | |
78b36b70 | 905 | const multiset<_K1, _C1, _A1>&); |
f6592a9e | 906 | |
93843da6 JW |
907 | #if __cpp_lib_three_way_comparison |
908 | template<typename _K1, typename _C1, typename _A1> | |
909 | friend __detail::__synth3way_t<_K1> | |
910 | operator<=>(const multiset<_K1, _C1, _A1>&, | |
911 | const multiset<_K1, _C1, _A1>&); | |
912 | #else | |
78b36b70 | 913 | template<typename _K1, typename _C1, typename _A1> |
fe62dd04 FD |
914 | friend bool |
915 | operator< (const multiset<_K1, _C1, _A1>&, | |
4fd20a8f | 916 | const multiset<_K1, _C1, _A1>&); |
93843da6 | 917 | #endif |
f6592a9e | 918 | }; |
ffcec5c8 | 919 | |
957f5fea VV |
920 | #if __cpp_deduction_guides >= 201606 |
921 | ||
922 | template<typename _InputIterator, | |
923 | typename _Compare = | |
924 | less<typename iterator_traits<_InputIterator>::value_type>, | |
925 | typename _Allocator = | |
926 | allocator<typename iterator_traits<_InputIterator>::value_type>, | |
927 | typename = _RequireInputIter<_InputIterator>, | |
08abbdda | 928 | typename = _RequireNotAllocator<_Compare>, |
957f5fea | 929 | typename = _RequireAllocator<_Allocator>> |
08abbdda JW |
930 | multiset(_InputIterator, _InputIterator, |
931 | _Compare = _Compare(), _Allocator = _Allocator()) | |
932 | -> multiset<typename iterator_traits<_InputIterator>::value_type, | |
933 | _Compare, _Allocator>; | |
934 | ||
935 | template<typename _Key, | |
936 | typename _Compare = less<_Key>, | |
937 | typename _Allocator = allocator<_Key>, | |
938 | typename = _RequireNotAllocator<_Compare>, | |
939 | typename = _RequireAllocator<_Allocator>> | |
940 | multiset(initializer_list<_Key>, | |
941 | _Compare = _Compare(), _Allocator = _Allocator()) | |
942 | -> multiset<_Key, _Compare, _Allocator>; | |
943 | ||
944 | template<typename _InputIterator, typename _Allocator, | |
945 | typename = _RequireInputIter<_InputIterator>, | |
946 | typename = _RequireAllocator<_Allocator>> | |
947 | multiset(_InputIterator, _InputIterator, _Allocator) | |
948 | -> multiset<typename iterator_traits<_InputIterator>::value_type, | |
949 | less<typename iterator_traits<_InputIterator>::value_type>, | |
950 | _Allocator>; | |
951 | ||
952 | template<typename _Key, typename _Allocator, | |
953 | typename = _RequireAllocator<_Allocator>> | |
954 | multiset(initializer_list<_Key>, _Allocator) | |
955 | -> multiset<_Key, less<_Key>, _Allocator>; | |
957f5fea | 956 | |
93843da6 | 957 | #endif // deduction guides |
957f5fea | 958 | |
ffcec5c8 JQ |
959 | /** |
960 | * @brief Multiset equality comparison. | |
93c66bc6 BK |
961 | * @param __x A %multiset. |
962 | * @param __y A %multiset of the same type as @a __x. | |
ffcec5c8 JQ |
963 | * @return True iff the size and elements of the multisets are equal. |
964 | * | |
f6592a9e PC |
965 | * This is an equivalence relation. It is linear in the size of the |
966 | * multisets. | |
ffcec5c8 JQ |
967 | * Multisets are considered equivalent if their sizes are equal, and if |
968 | * corresponding elements compare equal. | |
969 | */ | |
78b36b70 | 970 | template<typename _Key, typename _Compare, typename _Alloc> |
ffcec5c8 | 971 | inline bool |
4fd20a8f PC |
972 | operator==(const multiset<_Key, _Compare, _Alloc>& __x, |
973 | const multiset<_Key, _Compare, _Alloc>& __y) | |
f6592a9e | 974 | { return __x._M_t == __y._M_t; } |
ed6814f7 | 975 | |
93843da6 JW |
976 | #if __cpp_lib_three_way_comparison |
977 | /** | |
978 | * @brief Multiset ordering relation. | |
979 | * @param __x A `multiset`. | |
980 | * @param __y A `multiset` of the same type as `x`. | |
981 | * @return A value indicating whether `__x` is less than, equal to, | |
982 | * greater than, or incomparable with `__y`. | |
983 | * | |
984 | * This is a total ordering relation. It is linear in the size of the | |
985 | * maps. The elements must be comparable with @c <. | |
986 | * | |
987 | * See `std::lexicographical_compare_three_way()` for how the determination | |
988 | * is made. This operator is used to synthesize relational operators like | |
989 | * `<` and `>=` etc. | |
990 | */ | |
991 | template<typename _Key, typename _Compare, typename _Alloc> | |
992 | inline __detail::__synth3way_t<_Key> | |
993 | operator<=>(const multiset<_Key, _Compare, _Alloc>& __x, | |
994 | const multiset<_Key, _Compare, _Alloc>& __y) | |
995 | { return __x._M_t <=> __y._M_t; } | |
996 | #else | |
ffcec5c8 JQ |
997 | /** |
998 | * @brief Multiset ordering relation. | |
93c66bc6 BK |
999 | * @param __x A %multiset. |
1000 | * @param __y A %multiset of the same type as @a __x. | |
1001 | * @return True iff @a __x is lexicographically less than @a __y. | |
ffcec5c8 JQ |
1002 | * |
1003 | * This is a total ordering relation. It is linear in the size of the | |
ff90a89e | 1004 | * sets. The elements must be comparable with @c <. |
ffcec5c8 JQ |
1005 | * |
1006 | * See std::lexicographical_compare() for how the determination is made. | |
1007 | */ | |
78b36b70 | 1008 | template<typename _Key, typename _Compare, typename _Alloc> |
ffcec5c8 | 1009 | inline bool |
4fd20a8f PC |
1010 | operator<(const multiset<_Key, _Compare, _Alloc>& __x, |
1011 | const multiset<_Key, _Compare, _Alloc>& __y) | |
f6592a9e | 1012 | { return __x._M_t < __y._M_t; } |
ffcec5c8 JQ |
1013 | |
1014 | /// Returns !(x == y). | |
78b36b70 | 1015 | template<typename _Key, typename _Compare, typename _Alloc> |
ffcec5c8 | 1016 | inline bool |
4fd20a8f PC |
1017 | operator!=(const multiset<_Key, _Compare, _Alloc>& __x, |
1018 | const multiset<_Key, _Compare, _Alloc>& __y) | |
f6592a9e | 1019 | { return !(__x == __y); } |
ffcec5c8 JQ |
1020 | |
1021 | /// Returns y < x. | |
78b36b70 | 1022 | template<typename _Key, typename _Compare, typename _Alloc> |
ffcec5c8 | 1023 | inline bool |
ed6814f7 | 1024 | operator>(const multiset<_Key,_Compare,_Alloc>& __x, |
ffcec5c8 | 1025 | const multiset<_Key,_Compare,_Alloc>& __y) |
f6592a9e | 1026 | { return __y < __x; } |
ffcec5c8 JQ |
1027 | |
1028 | /// Returns !(y < x) | |
78b36b70 | 1029 | template<typename _Key, typename _Compare, typename _Alloc> |
ffcec5c8 | 1030 | inline bool |
4fd20a8f PC |
1031 | operator<=(const multiset<_Key, _Compare, _Alloc>& __x, |
1032 | const multiset<_Key, _Compare, _Alloc>& __y) | |
f6592a9e | 1033 | { return !(__y < __x); } |
ffcec5c8 JQ |
1034 | |
1035 | /// Returns !(x < y) | |
78b36b70 | 1036 | template<typename _Key, typename _Compare, typename _Alloc> |
ffcec5c8 | 1037 | inline bool |
4fd20a8f PC |
1038 | operator>=(const multiset<_Key, _Compare, _Alloc>& __x, |
1039 | const multiset<_Key, _Compare, _Alloc>& __y) | |
f6592a9e | 1040 | { return !(__x < __y); } |
93843da6 | 1041 | #endif // three-way comparison |
ffcec5c8 JQ |
1042 | |
1043 | /// See std::multiset::swap(). | |
78b36b70 | 1044 | template<typename _Key, typename _Compare, typename _Alloc> |
ffcec5c8 | 1045 | inline void |
4fd20a8f PC |
1046 | swap(multiset<_Key, _Compare, _Alloc>& __x, |
1047 | multiset<_Key, _Compare, _Alloc>& __y) | |
c5d9ec56 | 1048 | _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y))) |
f6592a9e | 1049 | { __x.swap(__y); } |
725dc051 | 1050 | |
12ffa228 | 1051 | _GLIBCXX_END_NAMESPACE_CONTAINER |
2dbe56bd JW |
1052 | |
1053 | #if __cplusplus > 201402L | |
2dbe56bd JW |
1054 | // Allow std::multiset access to internals of compatible sets. |
1055 | template<typename _Val, typename _Cmp1, typename _Alloc, typename _Cmp2> | |
1056 | struct | |
1057 | _Rb_tree_merge_helper<_GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>, | |
1058 | _Cmp2> | |
1059 | { | |
1060 | private: | |
1061 | friend class _GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>; | |
1062 | ||
1063 | static auto& | |
1064 | _S_get_tree(_GLIBCXX_STD_C::set<_Val, _Cmp2, _Alloc>& __set) | |
1065 | { return __set._M_t; } | |
1066 | ||
1067 | static auto& | |
1068 | _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set) | |
1069 | { return __set._M_t; } | |
1070 | }; | |
2dbe56bd JW |
1071 | #endif // C++17 |
1072 | ||
4a15d842 | 1073 | _GLIBCXX_END_NAMESPACE_VERSION |
12ffa228 | 1074 | } // namespace std |
725dc051 | 1075 | |
046d30f4 | 1076 | #endif /* _STL_MULTISET_H */ |