libstdc++
map.h
Go to the documentation of this file.
1// Debugging map implementation -*- C++ -*-
2
3// Copyright (C) 2003-2026 Free Software Foundation, Inc.
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
8// Free Software Foundation; either version 3, or (at your option)
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
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.
19
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/>.
24
25/** @file debug/map.h
26 * This file is a GNU debug extension to the Standard C++ Library.
27 */
28
29#ifndef _GLIBCXX_DEBUG_MAP_H
30#define _GLIBCXX_DEBUG_MAP_H 1
31
32#include <debug/safe_sequence.h>
34#include <debug/safe_iterator.h>
35#include <bits/stl_pair.h>
36
37namespace std _GLIBCXX_VISIBILITY(default)
38{
39namespace __debug
40{
41 /// Class std::map with safety/checking/debug instrumentation.
42 template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
43 typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
44 class map
46 map<_Key, _Tp, _Compare, _Allocator>, _Allocator,
47 __gnu_debug::_Safe_node_sequence>,
48 public _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Allocator>
49 {
50 typedef _GLIBCXX_STD_C::map<
51 _Key, _Tp, _Compare, _Allocator> _Base;
53 map, _Allocator, __gnu_debug::_Safe_node_sequence> _Safe;
54
55 typedef typename _Base::const_iterator _Base_const_iterator;
56 typedef typename _Base::iterator _Base_iterator;
58
59 template<typename _ItT, typename _SeqT, typename _CatT>
60 friend class ::__gnu_debug::_Safe_iterator;
61
62 // Reference wrapper for base class. Disambiguates map(const _Base&)
63 // from copy constructor by requiring a user-defined conversion.
64 // See PR libstdc++/90102.
65 struct _Base_ref
66 {
67 _Base_ref(const _Base& __r) : _M_ref(__r) { }
68
69 const _Base& _M_ref;
70 };
71
72 public:
73 // types:
74 typedef _Key key_type;
75 typedef _Tp mapped_type;
76 typedef std::pair<const _Key, _Tp> value_type;
77 typedef _Compare key_compare;
78 typedef _Allocator allocator_type;
79 typedef typename _Base::reference reference;
80 typedef typename _Base::const_reference const_reference;
81
83 iterator;
85 const_iterator;
86
87 typedef typename _Base::size_type size_type;
88 typedef typename _Base::difference_type difference_type;
89 typedef typename _Base::pointer pointer;
90 typedef typename _Base::const_pointer const_pointer;
91 typedef std::reverse_iterator<iterator> reverse_iterator;
92 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
93
94 // 23.3.1.1 construct/copy/destroy:
95
96#if __cplusplus < 201103L
97 map() : _Base() { }
98
99 map(const map& __x)
100 : _Base(__x) { }
101
102 ~map() { }
103#else
104 map() = default;
105 map(const map&) = default;
106 map(map&&) = default;
107
109 const _Compare& __c = _Compare(),
110 const allocator_type& __a = allocator_type())
111 : _Base(__l, __c, __a) { }
112
113 explicit
114 map(const allocator_type& __a)
115 : _Base(__a) { }
116
117 map(const map& __m, const __type_identity_t<allocator_type>& __a)
118 : _Base(__m, __a) { }
119
120 map(map&& __m, const __type_identity_t<allocator_type>& __a)
121 noexcept( noexcept(_Base(std::move(__m), __a)) )
122 : _Safe(std::move(__m), __a),
123 _Base(std::move(__m), __a) { }
124
125 map(initializer_list<value_type> __l, const allocator_type& __a)
126 : _Base(__l, __a) { }
127
128 template<typename _InputIterator>
129 map(_InputIterator __first, _InputIterator __last,
130 const allocator_type& __a)
131 : _Base(__gnu_debug::__base(
132 __glibcxx_check_valid_constructor_range(__first, __last)),
133 __gnu_debug::__base(__last), __a)
134 { }
135
136#if __glibcxx_containers_ranges // C++ >= 23
137 /**
138 * @brief Construct a map from a range.
139 * @since C++23
140 */
141 template<std::__detail::__container_compatible_range<value_type> _Rg>
142 map(std::from_range_t __t, _Rg&& __rg,
143 const _Compare& __c,
144 const allocator_type& __a = allocator_type())
145 : _Base(__t, std::forward<_Rg>(__rg), __c, __a)
146 { }
147
148 template<std::__detail::__container_compatible_range<value_type> _Rg>
149 map(std::from_range_t __t, _Rg&& __rg,
150 const allocator_type& __a = allocator_type())
151 : _Base(__t, std::forward<_Rg>(__rg), __a)
152 { }
153#endif
154
155 ~map() = default;
156#endif
157
158 map(_Base_ref __x)
159 : _Base(__x._M_ref) { }
160
161 explicit map(const _Compare& __comp,
162 const _Allocator& __a = _Allocator())
163 : _Base(__comp, __a) { }
164
165 template<typename _InputIterator>
166 map(_InputIterator __first, _InputIterator __last,
167 const _Compare& __comp = _Compare(),
168 const _Allocator& __a = _Allocator())
169 : _Base(__gnu_debug::__base(
170 __glibcxx_check_valid_constructor_range(__first, __last)),
171 __gnu_debug::__base(__last),
172 __comp, __a) { }
173
174#if __cplusplus >= 201103L
175 map&
176 operator=(const map&) = default;
177
178 map&
179 operator=(map&&) = default;
180
181 map&
182 operator=(initializer_list<value_type> __l)
183 {
184 _Base::operator=(__l);
185 this->_M_invalidate_all();
186 return *this;
187 }
188#endif
189
190 // _GLIBCXX_RESOLVE_LIB_DEFECTS
191 // 133. map missing get_allocator()
192 using _Base::get_allocator;
193
194 // iterators:
195 iterator
196 begin() _GLIBCXX_NOEXCEPT
197 { return iterator(_Base::begin(), this); }
198
199 const_iterator
200 begin() const _GLIBCXX_NOEXCEPT
201 { return const_iterator(_Base::begin(), this); }
202
203 iterator
204 end() _GLIBCXX_NOEXCEPT
205 { return iterator(_Base::end(), this); }
206
207 const_iterator
208 end() const _GLIBCXX_NOEXCEPT
209 { return const_iterator(_Base::end(), this); }
210
211 reverse_iterator
212 rbegin() _GLIBCXX_NOEXCEPT
213 { return reverse_iterator(end()); }
214
215 const_reverse_iterator
216 rbegin() const _GLIBCXX_NOEXCEPT
217 { return const_reverse_iterator(end()); }
218
219 reverse_iterator
220 rend() _GLIBCXX_NOEXCEPT
221 { return reverse_iterator(begin()); }
222
223 const_reverse_iterator
224 rend() const _GLIBCXX_NOEXCEPT
225 { return const_reverse_iterator(begin()); }
226
227#if __cplusplus >= 201103L
228 const_iterator
229 cbegin() const noexcept
230 { return const_iterator(_Base::begin(), this); }
231
232 const_iterator
233 cend() const noexcept
234 { return const_iterator(_Base::end(), this); }
235
236 const_reverse_iterator
237 crbegin() const noexcept
238 { return const_reverse_iterator(end()); }
239
240 const_reverse_iterator
241 crend() const noexcept
242 { return const_reverse_iterator(begin()); }
243#endif
244
245 // capacity:
246 using _Base::empty;
247 using _Base::size;
248 using _Base::max_size;
249
250 // 23.3.1.2 element access:
251 using _Base::operator[];
252
253 // _GLIBCXX_RESOLVE_LIB_DEFECTS
254 // DR 464. Suggestion for new member functions in standard containers.
255 using _Base::at;
256
257 // modifiers:
258#if __cplusplus >= 201103L
259 template<typename... _Args>
261 emplace(_Args&&... __args)
262 {
263 auto __res = _Base::emplace(std::forward<_Args>(__args)...);
264 return { { __res.first, this }, __res.second };
265 }
266
267 template<typename... _Args>
268 iterator
269 emplace_hint(const_iterator __pos, _Args&&... __args)
270 {
272 return
273 {
274 _Base::emplace_hint(__pos.base(), std::forward<_Args>(__args)...),
275 this
276 };
277 }
278#endif
279
281 insert(const value_type& __x)
282 {
283 std::pair<_Base_iterator, bool> __res = _Base::insert(__x);
284 return std::pair<iterator, bool>(iterator(__res.first, this),
285 __res.second);
286 }
287
288#if __cplusplus >= 201103L
289 // _GLIBCXX_RESOLVE_LIB_DEFECTS
290 // 2354. Unnecessary copying when inserting into maps with braced-init
292 insert(value_type&& __x)
293 {
294 auto __res = _Base::insert(std::move(__x));
295 return { { __res.first, this }, __res.second };
296 }
297
298 template<typename _Pair, typename = typename
300 _Pair&&>::value>::type>
302 insert(_Pair&& __x)
303 {
304 auto __res = _Base::insert(std::forward<_Pair>(__x));
305 return { { __res.first, this }, __res.second };
306 }
307#endif
308
309#if __cplusplus >= 201103L
310 void
312 { _Base::insert(__list); }
313#endif
314
315 iterator
316#if __cplusplus >= 201103L
317 insert(const_iterator __position, const value_type& __x)
318#else
319 insert(iterator __position, const value_type& __x)
320#endif
321 {
322 __glibcxx_check_insert(__position);
323 return iterator(_Base::insert(__position.base(), __x), this);
324 }
325
326#if __cplusplus >= 201103L
327 // _GLIBCXX_RESOLVE_LIB_DEFECTS
328 // 2354. Unnecessary copying when inserting into maps with braced-init
329 iterator
330 insert(const_iterator __position, value_type&& __x)
331 {
332 __glibcxx_check_insert(__position);
333 return { _Base::insert(__position.base(), std::move(__x)), this };
334 }
335
336 template<typename _Pair, typename = typename
338 _Pair&&>::value>::type>
339 iterator
340 insert(const_iterator __position, _Pair&& __x)
341 {
342 __glibcxx_check_insert(__position);
343 return
344 {
345 _Base::insert(__position.base(), std::forward<_Pair>(__x)),
346 this
347 };
348 }
349#endif
350
351 template<typename _InputIterator>
352 void
353 insert(_InputIterator __first, _InputIterator __last)
354 {
355 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
356 __glibcxx_check_valid_range2(__first, __last, __dist);
357
358 if (__dist.second >= __gnu_debug::__dp_sign)
359 _Base::insert(__gnu_debug::__unsafe(__first),
360 __gnu_debug::__unsafe(__last));
361 else
362 _Base::insert(__first, __last);
363 }
364
365
366#ifdef __glibcxx_map_try_emplace // C++ >= 17 && HOSTED
367 template <typename... _Args>
369 try_emplace(const key_type& __k, _Args&&... __args)
370 {
371 auto __res = _Base::try_emplace(__k,
372 std::forward<_Args>(__args)...);
373 return { { __res.first, this }, __res.second };
374 }
375
376 template <typename... _Args>
378 try_emplace(key_type&& __k, _Args&&... __args)
379 {
380 auto __res = _Base::try_emplace(std::move(__k),
381 std::forward<_Args>(__args)...);
382 return { { __res.first, this }, __res.second };
383 }
384
385 template <typename... _Args>
386 iterator
387 try_emplace(const_iterator __hint, const key_type& __k,
388 _Args&&... __args)
389 {
391 return
392 {
393 _Base::try_emplace(__hint.base(), __k,
394 std::forward<_Args>(__args)...),
395 this
396 };
397 }
398
399 template <typename... _Args>
400 iterator
401 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
402 {
404 return
405 {
406 _Base::try_emplace(__hint.base(), std::move(__k),
407 std::forward<_Args>(__args)...),
408 this
409 };
410 }
411
412 template <typename _Obj>
414 insert_or_assign(const key_type& __k, _Obj&& __obj)
415 {
416 auto __res = _Base::insert_or_assign(__k,
417 std::forward<_Obj>(__obj));
418 return { { __res.first, this }, __res.second };
419 }
420
421 template <typename _Obj>
423 insert_or_assign(key_type&& __k, _Obj&& __obj)
424 {
425 auto __res = _Base::insert_or_assign(std::move(__k),
426 std::forward<_Obj>(__obj));
427 return { { __res.first, this }, __res.second };
428 }
429
430 template <typename _Obj>
431 iterator
432 insert_or_assign(const_iterator __hint,
433 const key_type& __k, _Obj&& __obj)
434 {
436 return
437 {
438 _Base::insert_or_assign(__hint.base(), __k,
439 std::forward<_Obj>(__obj)),
440 this
441 };
442 }
443
444 template <typename _Obj>
445 iterator
446 insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
447 {
449 return
450 {
451 _Base::insert_or_assign(__hint.base(), std::move(__k),
452 std::forward<_Obj>(__obj)),
453 this
454 };
455 }
456#endif // C++17
457
458#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
459 using node_type = typename _Base::node_type;
460 using insert_return_type = _Node_insert_return<iterator, node_type>;
461
462 node_type
463 extract(const_iterator __position)
464 {
465 __glibcxx_check_erase(__position);
466 this->_M_invalidate_if(_Equal(__position.base()));
467 return _Base::extract(__position.base());
468 }
469
470 node_type
471 extract(const key_type& __key)
472 {
473 const auto __position = find(__key);
474 if (__position != end())
475 return extract(__position);
476 return {};
477 }
478
479# ifdef __glibcxx_associative_heterogeneous_erasure
480 template <__heterogeneous_tree_key<map> _Kt>
481 node_type
482 extract(_Kt&& __key)
483 {
484 const auto __position = find(__key);
485 if (__position != end())
486 return extract(__position);
487 return {};
488 }
489# endif
490
491 insert_return_type
492 insert(node_type&& __nh)
493 {
494 auto __ret = _Base::insert(std::move(__nh));
495 return
496 { { __ret.position, this }, __ret.inserted, std::move(__ret.node) };
497 }
498
499 iterator
500 insert(const_iterator __hint, node_type&& __nh)
501 {
503 return { _Base::insert(__hint.base(), std::move(__nh)), this };
504 }
505
506 using _Base::merge;
507#endif // C++17
508
509#if __cplusplus >= 201103L
510 iterator
511 erase(const_iterator __position)
512 {
513 __glibcxx_check_erase(__position);
514 return { erase(__position.base()), this };
515 }
516
517 _Base_iterator
518 erase(_Base_const_iterator __position)
519 {
520 __glibcxx_check_erase2(__position);
521 this->_M_invalidate_if(_Equal(__position));
522 return _Base::erase(__position);
523 }
524
525 _GLIBCXX_ABI_TAG_CXX11
526 iterator
527 erase(iterator __position)
528 { return erase(const_iterator(__position)); }
529#else
530 void
531 erase(iterator __position)
532 {
533 __glibcxx_check_erase(__position);
534 this->_M_invalidate_if(_Equal(__position.base()));
535 _Base::erase(__position.base());
536 }
537#endif
538
539 size_type
540 erase(const key_type& __x)
541 {
542 _Base_iterator __victim = _Base::find(__x);
543 if (__victim == _Base::end())
544 return 0;
545 else
546 {
547 this->_M_invalidate_if(_Equal(__victim));
548 _Base::erase(__victim);
549 return 1;
550 }
551 }
552
553# ifdef __glibcxx_associative_heterogeneous_erasure
554 // Note that for some types _Kt this may erase more than
555 // one element, such as if _Kt::operator< checks only part
556 // of the key.
557 template <__heterogeneous_tree_key<map> _Kt>
558 size_type
559 erase(_Kt&& __x)
560 {
561 auto __victims = _Base::equal_range(__x);
562 size_type __count = 0;
563 for (auto __victim = __victims.first; __victim != __victims.second;)
564 {
565 this->_M_invalidate_if(_Equal(__victim));
566 _Base::erase(__victim++);
567 ++__count;
568 }
569 return __count;
570 }
571# endif
572
573#if __cplusplus >= 201103L
574 iterator
575 erase(const_iterator __first, const_iterator __last)
576 {
577 // _GLIBCXX_RESOLVE_LIB_DEFECTS
578 // 151. can't currently clear() empty container
579 __glibcxx_check_erase_range(__first, __last);
580 for (_Base_const_iterator __victim = __first.base();
581 __victim != __last.base(); ++__victim)
582 {
583 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
584 _M_message(__gnu_debug::__msg_valid_range)
585 ._M_iterator(__first, "first")
586 ._M_iterator(__last, "last"));
587 this->_M_invalidate_if(_Equal(__victim));
588 }
589
590 return { _Base::erase(__first.base(), __last.base()), this };
591 }
592#else
593 void
594 erase(iterator __first, iterator __last)
595 {
596 // _GLIBCXX_RESOLVE_LIB_DEFECTS
597 // 151. can't currently clear() empty container
598 __glibcxx_check_erase_range(__first, __last);
599 for (_Base_iterator __victim = __first.base();
600 __victim != __last.base(); ++__victim)
601 {
602 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
603 _M_message(__gnu_debug::__msg_valid_range)
604 ._M_iterator(__first, "first")
605 ._M_iterator(__last, "last"));
606 this->_M_invalidate_if(_Equal(__victim));
607 }
608 _Base::erase(__first.base(), __last.base());
609 }
610#endif
611
612 void
613 swap(map& __x)
614 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
615 {
616 _Safe::_M_swap(__x);
617 _Base::swap(__x);
618 }
619
620 void
621 clear() _GLIBCXX_NOEXCEPT
622 {
623 this->_M_invalidate_all();
624 _Base::clear();
625 }
626
627 // observers:
628 using _Base::key_comp;
629 using _Base::value_comp;
630
631 // 23.3.1.3 map operations:
632 iterator
633 find(const key_type& __x)
634 { return iterator(_Base::find(__x), this); }
635
636#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
637 template<typename _Kt,
638 typename _Req =
639 typename __has_is_transparent<_Compare, _Kt>::type>
640 iterator
641 find(const _Kt& __x)
642 { return { _Base::find(__x), this }; }
643#endif
644
645 const_iterator
646 find(const key_type& __x) const
647 { return const_iterator(_Base::find(__x), this); }
648
649#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
650 template<typename _Kt,
651 typename _Req =
652 typename __has_is_transparent<_Compare, _Kt>::type>
653 const_iterator
654 find(const _Kt& __x) const
655 { return { _Base::find(__x), this }; }
656#endif
657
658 using _Base::count;
659
660 iterator
661 lower_bound(const key_type& __x)
662 { return iterator(_Base::lower_bound(__x), this); }
663
664#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
665 template<typename _Kt,
666 typename _Req =
667 typename __has_is_transparent<_Compare, _Kt>::type>
668 iterator
669 lower_bound(const _Kt& __x)
670 { return { _Base::lower_bound(__x), this }; }
671#endif
672
673 const_iterator
674 lower_bound(const key_type& __x) const
675 { return const_iterator(_Base::lower_bound(__x), this); }
676
677#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
678 template<typename _Kt,
679 typename _Req =
680 typename __has_is_transparent<_Compare, _Kt>::type>
681 const_iterator
682 lower_bound(const _Kt& __x) const
683 { return { _Base::lower_bound(__x), this }; }
684#endif
685
686 iterator
687 upper_bound(const key_type& __x)
688 { return iterator(_Base::upper_bound(__x), this); }
689
690#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
691 template<typename _Kt,
692 typename _Req =
693 typename __has_is_transparent<_Compare, _Kt>::type>
694 iterator
695 upper_bound(const _Kt& __x)
696 { return { _Base::upper_bound(__x), this }; }
697#endif
698
699 const_iterator
700 upper_bound(const key_type& __x) const
701 { return const_iterator(_Base::upper_bound(__x), this); }
702
703#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
704 template<typename _Kt,
705 typename _Req =
706 typename __has_is_transparent<_Compare, _Kt>::type>
707 const_iterator
708 upper_bound(const _Kt& __x) const
709 { return { _Base::upper_bound(__x), this }; }
710#endif
711
713 equal_range(const key_type& __x)
714 {
716 _Base::equal_range(__x);
717 return std::make_pair(iterator(__res.first, this),
718 iterator(__res.second, this));
719 }
720
721#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
722 template<typename _Kt,
723 typename _Req =
724 typename __has_is_transparent<_Compare, _Kt>::type>
726 equal_range(const _Kt& __x)
727 {
728 auto __res = _Base::equal_range(__x);
729 return { { __res.first, this }, { __res.second, this } };
730 }
731#endif
732
734 equal_range(const key_type& __x) const
735 {
737 _Base::equal_range(__x);
738 return std::make_pair(const_iterator(__res.first, this),
739 const_iterator(__res.second, this));
740 }
741
742#ifdef __glibcxx_generic_associative_lookup // C++ >= 14
743 template<typename _Kt,
744 typename _Req =
745 typename __has_is_transparent<_Compare, _Kt>::type>
747 equal_range(const _Kt& __x) const
748 {
749 auto __res = _Base::equal_range(__x);
750 return { { __res.first, this }, { __res.second, this } };
751 }
752#endif
753
754 _Base&
755 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
756
757 const _Base&
758 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
759 };
760
761#if __cpp_deduction_guides >= 201606
762
763 template<typename _InputIterator,
764 typename _Compare = less<__iter_key_t<_InputIterator>>,
765 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
766 typename = _RequireInputIter<_InputIterator>,
767 typename = _RequireNotAllocator<_Compare>,
768 typename = _RequireAllocator<_Allocator>>
769 map(_InputIterator, _InputIterator,
770 _Compare = _Compare(), _Allocator = _Allocator())
771 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
772 _Compare, _Allocator>;
773
774 template<typename _Key, typename _Tp, typename _Compare = less<_Key>,
775 typename _Allocator = allocator<pair<const _Key, _Tp>>,
776 typename = _RequireNotAllocator<_Compare>,
777 typename = _RequireAllocator<_Allocator>>
779 _Compare = _Compare(), _Allocator = _Allocator())
781
782 template <typename _InputIterator, typename _Allocator,
783 typename = _RequireInputIter<_InputIterator>,
784 typename = _RequireAllocator<_Allocator>>
785 map(_InputIterator, _InputIterator, _Allocator)
786 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
788
789 template<typename _Key, typename _Tp, typename _Allocator,
790 typename = _RequireAllocator<_Allocator>>
792 -> map<_Key, _Tp, less<_Key>, _Allocator>;
793
794#if __glibcxx_containers_ranges // C++ >= 23
795 template<ranges::input_range _Rg,
796 __not_allocator_like _Compare = less<__detail::__range_key_type<_Rg>>,
797 __allocator_like _Alloc =
799 map(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
801 __detail::__range_mapped_type<_Rg>,
802 _Compare, _Alloc>;
803
804 template<ranges::input_range _Rg, __allocator_like _Alloc>
805 map(from_range_t, _Rg&&, _Alloc)
807 __detail::__range_mapped_type<_Rg>,
809 _Alloc>;
810#endif
811#endif // deduction guides
812
813 template<typename _Key, typename _Tp,
814 typename _Compare, typename _Allocator>
815 inline bool
816 operator==(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
818 { return __lhs._M_base() == __rhs._M_base(); }
819
820#if __cpp_lib_three_way_comparison
821 template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
822 inline __detail::__synth3way_t<pair<const _Key, _Tp>>
823 operator<=>(const map<_Key, _Tp, _Compare, _Alloc>& __lhs,
825 { return __lhs._M_base() <=> __rhs._M_base(); }
826#else
827 template<typename _Key, typename _Tp,
828 typename _Compare, typename _Allocator>
829 inline bool
830 operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
831 const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
832 { return __lhs._M_base() != __rhs._M_base(); }
833
834 template<typename _Key, typename _Tp,
835 typename _Compare, typename _Allocator>
836 inline bool
839 { return __lhs._M_base() < __rhs._M_base(); }
840
841 template<typename _Key, typename _Tp,
842 typename _Compare, typename _Allocator>
843 inline bool
846 { return __lhs._M_base() <= __rhs._M_base(); }
847
848 template<typename _Key, typename _Tp,
849 typename _Compare, typename _Allocator>
850 inline bool
853 { return __lhs._M_base() >= __rhs._M_base(); }
854
855 template<typename _Key, typename _Tp,
856 typename _Compare, typename _Allocator>
857 inline bool
860 { return __lhs._M_base() > __rhs._M_base(); }
861#endif // three-way comparison
862
863 template<typename _Key, typename _Tp,
864 typename _Compare, typename _Allocator>
865 inline void
868 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
869 { __lhs.swap(__rhs); }
870
871} // namespace __debug
872} // namespace std
873
874#endif
#define __glibcxx_check_insert(_Position)
Definition macros.h:143
#define __glibcxx_check_erase_range(_First, _Last)
Definition macros.h:245
#define __glibcxx_check_erase(_Position)
Definition macros.h:209
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:859
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:873
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:826
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:866
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
Definition stl_pair.h:1166
auto declval() noexcept -> decltype(__declval< _Tp >(0))
Definition type_traits:2714
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition move.h:138
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Definition move.h:72
ISO C++ entities toplevel namespace is std.
constexpr _Iterator __base(_Iterator __it)
GNU debug code, replaces standard behavior with debug behavior.
initializer_list
Define a member typedef type only if a boolean constant is true.
Definition type_traits:137
is_constructible
Definition type_traits:1238
The standard allocator, as per C++03 [20.4.1].
Definition allocator.h:134
Safe iterator wrapper.
constexpr _Iterator & base() noexcept
Return the underlying iterator.
One of the comparison functors.
Struct holding two objects of arbitrary type.
Definition stl_pair.h:304
_T1 first
The first member.
Definition stl_pair.h:308
_T2 second
The second member.
Definition stl_pair.h:309
A standard container made up of (key,value) pairs, which can be retrieved based on a key,...
Definition stl_map.h:107
Class std::map with safety/checking/debug instrumentation.
Definition map.h:49
Safe class dealing with some allocator dependent operations.
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
A range for which ranges::begin returns an input iterator.