1// <flat_map> -*- C++ -*-
3// Copyright The GNU Toolchain Authors.
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)
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.
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.
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/>.
25/** @file include/flat_map
26 * This is a Standard C++ Library header.
29#ifndef _GLIBCXX_FLAT_MAP
30#define _GLIBCXX_FLAT_MAP 1
33#pragma GCC system_header
36#define __glibcxx_want_flat_map
37#include <bits/version.h>
39#ifdef __cpp_lib_flat_map // >= C++23
42#include <initializer_list>
45#include <functional> // not_fn
47#include <ranges> // views::zip
50#include <bits/functexcept.h>
51#include <bits/stl_algo.h>
52#include <bits/stl_function.h> // less
53#include <bits/stl_pair.h>
54#include <bits/uses_allocator_args.h> // make_obj_using_allocator
55#include <bits/ranges_algo.h>
57namespace std _GLIBCXX_VISIBILITY(default)
59_GLIBCXX_BEGIN_NAMESPACE_VERSION
61 template<typename _Key, typename _Tp, typename _Compare,
62 typename _KeyContainer, typename _MappedContainer>
65 template<typename _Key, typename _Tp, typename _Compare,
66 typename _KeyContainer, typename _MappedContainer>
69 template<typename _Key, typename _Tp, typename _Compare,
70 typename _KeyContainer, typename _MappedContainer, bool _Multi>
73 static_assert(is_same_v<_Key, typename _KeyContainer::value_type>);
74 static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>);
76 static_assert(is_nothrow_swappable_v<_KeyContainer>);
77 static_assert(is_nothrow_swappable_v<_MappedContainer>);
79 using _Derived = __conditional_t<_Multi,
80 flat_multimap<_Key, _Tp, _Compare,
81 _KeyContainer, _MappedContainer>,
82 flat_map<_Key, _Tp, _Compare,
83 _KeyContainer, _MappedContainer>>;
84 using __sorted_t = __conditional_t<_Multi, sorted_equivalent_t, sorted_unique_t>;
87 template<bool _Const> struct _Iterator;
89 using key_type = _Key;
90 using mapped_type = _Tp;
91 using value_type = pair<key_type, mapped_type>;
92 using key_compare = _Compare;
93 using reference = pair<const key_type&, mapped_type&>;
94 using const_reference = pair<const key_type&, const mapped_type&>;
95 using size_type = size_t;
96 using difference_type = ptrdiff_t;
97 using iterator = _Iterator<false>;
98 using const_iterator = _Iterator<true>;
99 using reverse_iterator = std::reverse_iterator<iterator>;
100 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
101 using key_container_type = _KeyContainer;
102 using mapped_container_type = _MappedContainer;
105 using __emplace_result_t = __conditional_t<_Multi, iterator, pair<iterator, bool>>;
110 [[no_unique_address]] key_compare _M_comp;
111 value_compare(key_compare __c) : _M_comp(__c) { }
115 operator()(const_reference __x, const_reference __y) const
116 { return _M_comp(__x.first, __y.first); }
118 friend _Flat_map_impl;
123 key_container_type keys;
124 mapped_container_type values;
132 _ClearGuard(containers& __cont)
133 : _M_cont(std::__addressof(__cont))
140 _M_cont->keys.clear();
141 _M_cont->values.clear();
147 { _M_cont = nullptr; }
151 _M_make_clear_guard()
152 { return _ClearGuard{this->_M_cont}; }
156 _Flat_map_impl() : _Flat_map_impl(key_compare()) { }
159 _Flat_map_impl(const key_compare& __comp)
160 : _M_cont(), _M_comp(__comp)
163 _Flat_map_impl(key_container_type __key_cont,
164 mapped_container_type __mapped_cont,
165 const key_compare& __comp = key_compare())
166 : _M_cont(std::move(__key_cont), std::move(__mapped_cont)), _M_comp(__comp)
168 __glibcxx_assert(_M_cont.keys.size() == _M_cont.values.size());
172 _Flat_map_impl(__sorted_t,
173 key_container_type __key_cont,
174 mapped_container_type __mapped_cont,
175 const key_compare& __comp = key_compare())
176 : _M_cont(std::move(__key_cont), std::move(__mapped_cont)), _M_comp(__comp)
178 __glibcxx_assert(_M_cont.keys.size() == _M_cont.values.size());
179 _GLIBCXX_DEBUG_ASSERT(ranges::is_sorted(_M_cont.keys, _M_comp));
182 template<__has_input_iter_cat _InputIterator>
183 _Flat_map_impl(_InputIterator __first, _InputIterator __last,
184 const key_compare& __comp = key_compare())
185 : _M_cont(), _M_comp(__comp)
186 { insert(__first, __last); }
188 template<__has_input_iter_cat _InputIterator>
189 _Flat_map_impl(__sorted_t __s,
190 _InputIterator __first, _InputIterator __last,
191 const key_compare& __comp = key_compare())
192 : _M_cont(), _M_comp(__comp)
193 { insert(__s, __first, __last); }
195 template<__detail::__container_compatible_range<value_type> _Rg>
196 _Flat_map_impl(from_range_t, _Rg&& __rg)
197 : _Flat_map_impl(from_range, std::forward<_Rg>(__rg), key_compare())
200 template<__detail::__container_compatible_range<value_type> _Rg>
201 _Flat_map_impl(from_range_t, _Rg&& __rg, const key_compare& __comp)
202 : _Flat_map_impl(__comp)
203 { insert_range(std::forward<_Rg>(__rg)); }
205 _Flat_map_impl(initializer_list<value_type> __il,
206 const key_compare& __comp = key_compare())
207 : _Flat_map_impl(__il.begin(), __il.end(), __comp)
210 _Flat_map_impl(__sorted_t __s,
211 initializer_list<value_type> __il,
212 const key_compare& __comp = key_compare())
213 : _Flat_map_impl(__s, __il.begin(), __il.end(), __comp)
216 // constructors with allocators
218 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
220 _Flat_map_impl(const _Alloc& __a)
221 : _Flat_map_impl(key_compare(), __a)
224 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
225 _Flat_map_impl(const key_compare& __comp, const _Alloc& __a)
226 : _M_cont(std::make_obj_using_allocator<key_container_type>(__a),
227 std::make_obj_using_allocator<mapped_container_type>(__a)),
231 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
232 _Flat_map_impl(const key_container_type& __key_cont,
233 const mapped_container_type& __mapped_cont,
235 : _Flat_map_impl(__key_cont, __mapped_cont, key_compare(), __a)
238 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
239 _Flat_map_impl(const key_container_type& __key_cont,
240 const mapped_container_type& __mapped_cont,
241 const key_compare& __comp,
243 : _M_cont(std::make_obj_using_allocator<key_container_type>(__a, __key_cont),
244 std::make_obj_using_allocator<mapped_container_type>(__a, __mapped_cont)),
247 __glibcxx_assert(_M_cont.keys.size() == _M_cont.values.size());
251 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
252 _Flat_map_impl(__sorted_t __s,
253 const key_container_type& __key_cont,
254 const mapped_container_type& __mapped_cont,
256 : _Flat_map_impl(__s, __key_cont, __mapped_cont, key_compare(), __a)
259 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
260 _Flat_map_impl(__sorted_t,
261 const key_container_type& __key_cont,
262 const mapped_container_type& __mapped_cont,
263 const key_compare& __comp,
265 : _M_cont(std::make_obj_using_allocator<key_container_type>(__a, __key_cont),
266 std::make_obj_using_allocator<mapped_container_type>(__a, __mapped_cont)),
269 __glibcxx_assert(_M_cont.keys.size() == _M_cont.values.size());
270 _GLIBCXX_DEBUG_ASSERT(ranges::is_sorted(_M_cont.keys, _M_comp));
273 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
274 _Flat_map_impl(const _Derived& __x, const _Alloc& __a)
275 : _M_cont(std::make_obj_using_allocator<key_container_type>(__a, __x._M_cont.keys),
276 std::make_obj_using_allocator<mapped_container_type>(__a, __x._M_cont.values)),
280 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
281 _Flat_map_impl(_Derived&& __x, const _Alloc& __a)
282 : _M_cont(std::make_obj_using_allocator<key_container_type>
283 (__a, std::move(__x._M_cont.keys)),
284 std::make_obj_using_allocator<mapped_container_type>
285 (__a, std::move(__x._M_cont.values))),
289 template<__has_input_iter_cat _InputIterator,
290 __allocator_for<key_container_type, mapped_container_type> _Alloc>
291 _Flat_map_impl(_InputIterator __first, _InputIterator __last,
293 : _Flat_map_impl(std::move(__first), std::move(__last), key_compare(), __a)
296 template<__has_input_iter_cat _InputIterator,
297 __allocator_for<key_container_type, mapped_container_type> _Alloc>
298 _Flat_map_impl(_InputIterator __first, _InputIterator __last,
299 const key_compare& __comp,
301 : _Flat_map_impl(__comp, __a)
302 { insert(__first, __last); }
304 template<__has_input_iter_cat _InputIterator,
305 __allocator_for<key_container_type, mapped_container_type> _Alloc>
306 _Flat_map_impl(__sorted_t __s,
307 _InputIterator __first, _InputIterator __last,
309 : _Flat_map_impl(__s, std::move(__first), std::move(__last), key_compare(), __a)
312 template<__has_input_iter_cat _InputIterator,
313 __allocator_for<key_container_type, mapped_container_type> _Alloc>
314 _Flat_map_impl(__sorted_t __s,
315 _InputIterator __first, _InputIterator __last,
316 const key_compare& __comp,
318 : _Flat_map_impl(__comp, __a)
319 { insert(__s, __first, __last); }
321 template<__detail::__container_compatible_range<value_type> _Rg,
322 __allocator_for<key_container_type, mapped_container_type> _Alloc>
323 _Flat_map_impl(from_range_t, _Rg&& __rg,
325 : _Flat_map_impl(from_range, std::forward<_Rg>(__rg), key_compare(), __a)
328 template<__detail::__container_compatible_range<value_type> _Rg,
329 __allocator_for<key_container_type, mapped_container_type> _Alloc>
330 _Flat_map_impl(from_range_t, _Rg&& __rg, const key_compare& __comp,
332 : _Flat_map_impl(__comp, __a)
333 { insert_range(std::forward<_Rg>(__rg)); }
335 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
336 _Flat_map_impl(initializer_list<value_type> __il,
338 : _Flat_map_impl(__il, key_compare(), __a)
341 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
342 _Flat_map_impl(initializer_list<value_type> __il,
343 const key_compare& __comp,
345 : _Flat_map_impl(__il.begin(), __il.end(), __comp, __a)
348 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
349 _Flat_map_impl(__sorted_t __s,
350 initializer_list<value_type> __il,
352 : _Flat_map_impl(__s, __il.begin(), __il.end(), key_compare(), __a)
355 template<__allocator_for<key_container_type, mapped_container_type> _Alloc>
356 _Flat_map_impl(__sorted_t __s,
357 initializer_list<value_type> __il,
358 const key_compare& __comp,
360 : _Flat_map_impl(__s, __il.begin(), __il.end(), __comp, __a)
364 operator=(initializer_list<value_type> __il)
368 return static_cast<_Derived&>(*this);
374 { return {this, _M_cont.keys.cbegin()}; }
377 begin() const noexcept
378 { return {this, _M_cont.keys.cbegin()}; }
382 { return {this, _M_cont.keys.cend()}; }
386 { return {this, _M_cont.keys.cend()}; }
390 { return reverse_iterator(end()); }
392 const_reverse_iterator
393 rbegin() const noexcept
394 { return const_reverse_iterator(end()); }
398 { return reverse_iterator(begin()); }
400 const_reverse_iterator
401 rend() const noexcept
402 { return const_reverse_iterator(begin()); }
405 cbegin() const noexcept
406 { return {this, _M_cont.keys.cbegin()}; }
409 cend() const noexcept
410 { return {this, _M_cont.keys.cend()}; }
412 const_reverse_iterator
413 crbegin() const noexcept
414 { return const_reverse_iterator(cend()); }
416 const_reverse_iterator
417 crend() const noexcept
418 { return const_reverse_iterator(cbegin()); }
423 empty() const noexcept
424 { return _M_cont.keys.empty(); }
427 size() const noexcept
428 { return _M_cont.keys.size(); }
431 max_size() const noexcept
432 { return std::min<size_type>(keys().max_size(), values().max_size()); }
435 // operator[] and at defined directly in class flat_map only.
438 template<typename _Key2, typename... _Args>
440 _M_try_emplace(optional<const_iterator> __hint, _Key2&& __k, _Args&&... __args)
442 // TODO: Simplify and audit the hint handling.
443 typename key_container_type::iterator __key_it;
444 typename mapped_container_type::iterator __value_it;
445 int __r = -1, __s = -1;
446 if (__hint.has_value()
447 && (__hint == cbegin()
448 || (__r = !_M_comp(__k, (*__hint)[-1].first))) // k >= hint[-1]
450 || (__s = !_M_comp((*__hint)[0].first, __k)))) // k <= hint[0]
452 __key_it = _M_cont.keys.begin() + __hint->_M_index;
453 if constexpr (!_Multi)
454 if (__r == 1 && !_M_comp(__key_it[-1], __k)) // k == hint[-1]
455 return {iterator{this, __key_it - 1}, false};
459 auto __first = _M_cont.keys.begin();
460 auto __last = _M_cont.keys.end();
461 if (__r == 1) // k >= hint[-1]
462 __first += __hint->_M_index;
463 else if (__r == 0) // k < __hint[-1]
464 __last = __first + __hint->_M_index;
465 if constexpr (_Multi)
467 if (__s == 0) // hint[0] < k
468 // Insert before the leftmost equivalent key.
469 __key_it = std::lower_bound(__first, __last, __k, _M_comp);
471 // Insert after the rightmost equivalent key.
472 __key_it = std::upper_bound(std::make_reverse_iterator(__last),
473 std::make_reverse_iterator(__first),
474 __k, std::not_fn(_M_comp)).base();
477 __key_it = std::lower_bound(__first, __last, __k, _M_comp);
480 if constexpr (!_Multi)
481 if (__key_it != _M_cont.keys.end() && !_M_comp(__k, __key_it[0]))
482 return {iterator{this, __key_it}, false};
484 auto __guard = _M_make_clear_guard();
485 __key_it = _M_cont.keys.insert(__key_it, std::move(__k));
486 __value_it = _M_cont.values.begin() + (__key_it - _M_cont.keys.begin());
487 _M_cont.values.emplace(__value_it, std::forward<_Args>(__args)...);
488 __guard._M_disable();
489 return {iterator{this, __key_it}, true};
492 template<typename... _Args>
493 requires is_constructible_v<value_type, _Args...>
495 emplace(_Args&&... __args)
497 value_type __p(std::forward<_Args>(__args)...);
498 auto __r = _M_try_emplace(nullopt, std::move(__p.first), std::move(__p.second));
499 if constexpr (_Multi)
505 template<typename... _Args>
507 emplace_hint(const_iterator __position, _Args&&... __args)
509 value_type __p(std::forward<_Args>(__args)...);
510 return _M_try_emplace(__position, std::move(__p.first), std::move(__p.second)).first;
514 insert(const value_type& __x)
515 { return emplace(__x); }
518 insert(value_type&& __x)
519 { return emplace(std::move(__x)); }
522 insert(const_iterator __position, const value_type& __x)
523 { return emplace_hint(__position, __x); }
526 insert(const_iterator __position, value_type&& __x)
527 { return emplace_hint(__position, std::move(__x)); }
529 template<typename _Arg>
530 requires is_constructible_v<value_type, _Arg>
533 { return emplace(std::forward<_Arg>(__x)); }
535 template<typename _Arg>
536 requires is_constructible_v<value_type, _Arg>
538 insert(const_iterator __position, _Arg&& __x)
539 { return emplace_hint(__position, std::forward<_Arg>(__x)); }
542 template<typename _Iter, typename _Sent>
544 _M_insert(_Iter __first, _Sent __last)
546 // FIXME: This implementation fails its complexity requirements.
547 // We can't idiomatically implement an efficient version (as in the
548 // disabled code) until ranges::inplace_merge is fixed to dispatch
549 // on iterator concept instead of iterator category.
551 auto __guard = _M_make_clear_guard();
553 for (; __first != __last; ++__first)
555 value_type __value = *__first;
556 _M_cont.keys.emplace_back(std::move(__value.first));
557 _M_cont.values.emplace_back(std::move(__value.second));
559 auto __zv = views::zip(_M_cont.keys, _M_cont.values);
560 ranges::sort(__zv.begin() + __n, __zv.end(), value_comp());
561 ranges::inplace_merge(__zv.begin(), __zv.begin() + __n, __zv.end(), value_comp());
562 if constexpr (!_Multi)
564 __guard._M_cont = nullptr;
566 auto __guard = _M_make_clear_guard();
567 for (; __first != __last; ++__first)
569 value_type __value = *__first;
570 _M_cont.keys.emplace_back(std::move(__value.first));
571 _M_cont.values.emplace_back(std::move(__value.second));
574 __guard._M_disable();
579 template<__has_input_iter_cat _InputIterator>
581 insert(_InputIterator __first, _InputIterator __last)
582 { _M_insert(std::move(__first), std::move(__last)); }
584 template<__has_input_iter_cat _InputIterator>
586 insert(__sorted_t, _InputIterator __first, _InputIterator __last)
588 // FIXME: This implementation fails its complexity requirements; see above.
589 insert(std::move(__first), std::move(__last));
592 template<__detail::__container_compatible_range<value_type> _Rg>
594 insert_range(_Rg&& __rg)
595 { _M_insert(ranges::begin(__rg), ranges::end(__rg)); }
598 insert(initializer_list<value_type> __il)
599 { insert(__il.begin(), __il.end()); }
602 insert(__sorted_t __s, initializer_list<value_type> __il)
603 { insert(__s, __il.begin(), __il.end()); }
608 auto __guard = _M_make_clear_guard();
609 return {std::move(_M_cont.keys), std::move(_M_cont.values)};
613 replace(key_container_type&& __key_cont, mapped_container_type&& __mapped_cont)
615 __glibcxx_assert(__key_cont.size() == __mapped_cont.size());
616 _GLIBCXX_DEBUG_ASSERT(ranges::is_sorted(__key_cont, _M_comp));
617 auto __guard = _M_make_clear_guard();
618 _M_cont.keys = std::move(__key_cont);
619 _M_cont.values = std::move(__mapped_cont);
620 __guard._M_disable();
623 // try_emplace and insert_or_assign defined directly in class flat_map only.
626 erase(iterator __position)
627 { return erase(static_cast<const_iterator>(__position)); }
630 erase(const_iterator __position)
632 auto __guard = _M_make_clear_guard();
633 auto __idx = __position._M_index;
634 auto __it = _M_cont.keys.erase(_M_cont.keys.begin() + __idx);
635 _M_cont.values.erase(_M_cont.values.begin() + __idx);
636 __guard._M_disable();
637 return iterator{this, __it};
641 erase(const key_type& __x)
642 { return erase<const key_type&>(__x); }
644 template<typename _Key2>
645 requires same_as<remove_cvref_t<_Key2>, _Key>
646 || (__transparent_comparator<_Compare>
647 && !is_convertible_v<_Key2, iterator>
648 && !is_convertible_v<_Key2, const_iterator>)
652 auto [__first, __last] = equal_range(std::forward<_Key2>(__x));
653 auto __n = __last - __first;
654 erase(__first, __last);
659 erase(const_iterator __first, const_iterator __last)
661 auto __guard = _M_make_clear_guard();
662 auto __it = _M_cont.keys.erase(_M_cont.keys.begin() + __first._M_index,
663 _M_cont.keys.begin() + __last._M_index);
664 _M_cont.values.erase(_M_cont.values.begin() + __first._M_index,
665 _M_cont.values.begin() + __last._M_index);
666 __guard._M_disable();
667 return iterator{this, __it};
671 swap(_Derived& __y) noexcept
673 ranges::swap(_M_comp, __y._M_comp);
674 ranges::swap(_M_cont.keys, __y._M_cont.keys);
675 ranges::swap(_M_cont.values, __y._M_cont.values);
681 _M_cont.keys.clear();
682 _M_cont.values.clear();
694 { return value_compare(_M_comp); }
697 const key_container_type&
698 keys() const noexcept
699 { return _M_cont.keys; }
702 const mapped_container_type&
703 values() const noexcept
704 { return _M_cont.values; }
709 find(const key_type& __x)
710 { return find<key_type>(__x); }
714 find(const key_type& __x) const
715 { return find<key_type>(__x); }
717 template<typename _Key2>
718 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
721 find(const _Key2& __x)
723 auto __it = lower_bound(__x);
724 if (__it != end() && !_M_comp(__x, __it->first))
730 template<typename _Key2>
731 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
734 find(const _Key2& __x) const
736 auto __it = lower_bound(__x);
737 if (__it != cend() && !_M_comp(__x, __it->first))
745 count(const key_type& __x) const
746 { return count<key_type>(__x); }
748 template<typename _Key2>
749 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
752 count(const _Key2& __x) const
754 if constexpr (!_Multi)
755 return contains<_Key2>(__x);
758 auto [__first, __last] = equal_range(__x);
759 return __last - __first;
765 contains(const key_type& __x) const
766 { return contains<key_type>(__x); }
768 template<typename _Key2>
769 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
772 contains(const _Key2& __x) const
773 { return find(__x) != cend(); }
777 lower_bound(const key_type& __x)
778 { return lower_bound<key_type>(__x); }
782 lower_bound(const key_type& __x) const
783 { return lower_bound<key_type>(__x); }
785 template<typename _Key2>
786 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
789 lower_bound(const _Key2& __x)
791 auto __it = std::lower_bound(_M_cont.keys.begin(), _M_cont.keys.end(),
796 template<typename _Key2>
797 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
800 lower_bound(const _Key2& __x) const
802 auto __it = std::lower_bound(_M_cont.keys.begin(), _M_cont.keys.end(),
809 upper_bound(const key_type& __x)
810 { return upper_bound<key_type>(__x); }
814 upper_bound(const key_type& __x) const
815 { return upper_bound<key_type>(__x); }
817 template<typename _Key2>
818 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
821 upper_bound(const _Key2& __x)
823 auto __it = std::upper_bound(_M_cont.keys.begin(), _M_cont.keys.end(),
828 template<typename _Key2>
829 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
832 upper_bound(const _Key2& __x) const
834 auto __it = std::upper_bound(_M_cont.keys.begin(), _M_cont.keys.end(),
840 pair<iterator, iterator>
841 equal_range(const key_type& __x)
842 { return equal_range<key_type>(__x); }
845 pair<const_iterator, const_iterator>
846 equal_range(const key_type& __x) const
847 { return equal_range<key_type>(__x); }
849 template<typename _Key2>
850 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
852 pair<iterator, iterator>
853 equal_range(const _Key2& __x)
855 auto [__first, __last] = std::equal_range(_M_cont.keys.begin(),
858 return {{this, __first}, {this, __last}};
861 template<typename _Key2>
862 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
864 pair<const_iterator, const_iterator>
865 equal_range(const _Key2& __x) const
867 auto [__first, __last] = std::equal_range(_M_cont.keys.begin(),
870 return {{this, __first}, {this, __last}};
875 operator==(const _Derived& __x, const _Derived& __y)
876 { return std::equal(__x.begin(), __x.end(), __y.begin(), __y.end()); }
878 template<typename _Up = value_type>
880 friend __detail::__synth3way_t<_Up>
881 operator<=>(const _Derived& __x, const _Derived& __y)
883 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
884 __y.begin(), __y.end(),
885 __detail::__synth3way);
889 swap(_Derived& __x, _Derived& __y) noexcept
890 { return __x.swap(__y); }
892 template<typename _Predicate>
894 erase_if(_Derived& __c, _Predicate __pred)
896 auto __guard = __c._M_make_clear_guard();
897 auto __zv = views::zip(__c._M_cont.keys, __c._M_cont.values);
898 auto __sr = ranges::remove_if(__zv, __pred);
899 auto __erased = __sr.size();
900 __c.erase(__c.end() - __erased, __c.end());
901 __guard._M_disable();
907 [[no_unique_address]] _Compare _M_comp;
912 auto __zv = views::zip(_M_cont.keys, _M_cont.values);
913 ranges::sort(__zv, value_comp());
914 if constexpr (!_Multi)
919 _M_unique() requires (!_Multi)
923 __key_equiv(key_compare __c) : _M_comp(__c) { }
926 operator()(const_reference __x, const_reference __y) const
927 { return !_M_comp(__x.first, __y.first) && !_M_comp(__y.first, __x.first); }
929 [[no_unique_address]] key_compare _M_comp;
932 auto __zv = views::zip(_M_cont.keys, _M_cont.values);
933 auto __it = ranges::unique(__zv, __key_equiv(_M_comp)).begin();
934 auto __n = __it - __zv.begin();
935 _M_cont.keys.erase(_M_cont.keys.begin() + __n, _M_cont.keys.end());
936 _M_cont.values.erase(_M_cont.values.begin() + __n, _M_cont.values.end());
940 template<typename _Key, typename _Tp, typename _Compare,
941 typename _KeyContainer, typename _MappedContainer, bool _Multi>
942 template<bool _Const>
943 class _Flat_map_impl<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer, _Multi>::_Iterator
945 using __size_type = typename _Flat_map_impl::size_type;
948 using iterator_category = input_iterator_tag;
949 using iterator_concept = random_access_iterator_tag;
950 using value_type = pair<const key_type, mapped_type>;
951 using reference = pair<const key_type&,
952 ranges::__maybe_const_t<_Const, mapped_type>&>;
953 using difference_type = ptrdiff_t;
955 _Iterator() = default;
957 _Iterator(_Iterator<!_Const> __it) requires _Const
958 : _M_cont(__it._M_cont), _M_index(__it._M_index)
962 operator*() const noexcept
964 __glibcxx_assert(_M_index < _M_cont->keys.size());
965 return {_M_cont->keys[_M_index], _M_cont->values[_M_index]};
973 operator->() const noexcept
974 { return std::__addressof(__p); }
979 { return pointer{operator*()}; }
982 operator[](difference_type __n) const noexcept
983 { return *(*this + __n); }
986 operator++() noexcept
993 operator--() noexcept
1000 operator++(int) noexcept
1008 operator--(int) noexcept
1016 operator+=(difference_type __n) noexcept
1023 operator-=(difference_type __n) noexcept
1030 friend _Flat_map_impl;
1031 friend _Iterator<!_Const>;
1033 _Iterator(_Flat_map_impl* __fm, typename key_container_type::const_iterator __it)
1035 : _M_cont(std::__addressof(__fm->_M_cont)), _M_index(__it - __fm->keys().cbegin())
1038 _Iterator(const _Flat_map_impl* __fm, typename key_container_type::const_iterator __it)
1040 : _M_cont(std::__addressof(__fm->_M_cont)), _M_index(__it - __fm->keys().cbegin())
1044 operator+(_Iterator __it, difference_type __n) noexcept
1051 operator+(difference_type __n, _Iterator __it) noexcept
1058 operator-(_Iterator __it, difference_type __n) noexcept
1064 friend difference_type
1065 operator-(const _Iterator& __x, const _Iterator& __y) noexcept
1067 __glibcxx_assert(__x._M_cont == __y._M_cont);
1068 return __x._M_index - __y._M_index;
1072 operator==(const _Iterator& __x, const _Iterator& __y) noexcept
1074 __glibcxx_assert(__x._M_cont == __y._M_cont);
1075 __glibcxx_assert((__x._M_index == size_t(-1)) == (__y._M_index == size_t(-1)));
1076 return __x._M_index == __y._M_index;
1079 friend strong_ordering
1080 operator<=>(const _Iterator& __x, const _Iterator& __y)
1082 __glibcxx_assert(__x._M_cont == __y._M_cont);
1083 __glibcxx_assert((__x._M_index == size_t(-1)) == (__y._M_index == size_t(-1)));
1084 return __x._M_index <=> __y._M_index;
1087 ranges::__maybe_const_t<_Const, containers>* _M_cont = nullptr;
1088 __size_type _M_index = -1;
1091 /* Class template flat_map - container adaptor
1095 template<typename _Key, typename _Tp, typename _Compare = less<_Key>,
1096 typename _KeyContainer = vector<_Key>,
1097 typename _MappedContainer = vector<_Tp>>
1099 : private _Flat_map_impl<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer, false>
1101 using _Impl = _Flat_map_impl<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer, false>;
1106 using typename _Impl::key_type;
1107 using typename _Impl::mapped_type;
1108 using typename _Impl::value_type;
1109 using typename _Impl::key_compare;
1110 using typename _Impl::reference;
1111 using typename _Impl::const_reference;
1112 using typename _Impl::size_type;
1113 using typename _Impl::difference_type;
1114 using typename _Impl::iterator;
1115 using typename _Impl::const_iterator;
1116 using typename _Impl::reverse_iterator;
1117 using typename _Impl::const_reverse_iterator;
1118 using typename _Impl::key_container_type;
1119 using typename _Impl::mapped_container_type;
1120 using typename _Impl::value_compare;
1121 using typename _Impl::containers;
1129 using _Impl::rbegin;
1132 using _Impl::cbegin;
1134 using _Impl::crbegin;
1140 using _Impl::max_size;
1144 operator[](const key_type& __x)
1145 { return operator[]<const key_type>(__x); }
1148 operator[](key_type&& __x)
1149 { return operator[]<key_type>(std::move(__x)); }
1151 template<typename _Key2>
1152 requires same_as<remove_cvref_t<_Key2>, _Key> || __transparent_comparator<_Compare>
1154 operator[](_Key2&& __x)
1155 { return try_emplace(std::forward<_Key2>(__x)).first->second; }
1158 at(const key_type& __x)
1159 { return at<key_type>(__x); }
1162 at(const key_type& __x) const
1163 { return at<key_type>(__x); }
1165 template<typename _Key2>
1166 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
1168 at(const _Key2& __x)
1170 auto __it = this->find(__x);
1171 if (__it == this->end())
1172 __throw_out_of_range("flat_map::at");
1173 return __it->second;
1176 template<typename _Key2>
1177 requires same_as<_Key2, _Key> || __transparent_comparator<_Compare>
1179 at(const _Key2& __x) const
1181 auto __it = this->find(__x);
1182 if (__it == this->end())
1183 __throw_out_of_range("flat_map::at");
1184 return __it->second;
1188 using _Impl::emplace;
1189 using _Impl::emplace_hint;
1190 using _Impl::insert;
1191 using _Impl::insert_range;
1192 using _Impl::extract;
1193 using _Impl::replace;
1198 template<typename... _Args>
1199 requires is_constructible_v<mapped_type, _Args...>
1200 pair<iterator, bool>
1201 try_emplace(const key_type& __k, _Args&&... __args)
1202 { return _Impl::_M_try_emplace(nullopt, __k, std::forward<_Args>(__args)...); }
1204 template<typename... _Args>
1205 requires is_constructible_v<mapped_type, _Args...>
1206 pair<iterator, bool>
1207 try_emplace(key_type&& __k, _Args&&... __args)
1209 return _Impl::_M_try_emplace(nullopt, std::move(__k),
1210 std::forward<_Args>(__args)...);
1213 template<typename _Key2, typename... _Args>
1214 requires __transparent_comparator<_Compare>
1215 && is_constructible_v<key_type, _Key2>
1216 && is_constructible_v<mapped_type, _Args...>
1217 && (!is_convertible_v<_Key2&&, const_iterator>)
1218 && (!is_convertible_v<_Key2&&, iterator>)
1219 pair<iterator, bool>
1220 try_emplace(_Key2&& __k, _Args&&... __args)
1222 return _Impl::_M_try_emplace(nullopt, std::forward<_Key2>(__k),
1223 std::forward<_Args>(__args)...);
1226 template<typename... _Args>
1227 requires is_constructible_v<mapped_type, _Args...>
1229 try_emplace(const_iterator __hint, const key_type& __k, _Args&&... __args)
1230 { return _Impl::_M_try_emplace(__hint, __k, std::forward<_Args>(__args)...).first; }
1232 template<typename... _Args>
1233 requires is_constructible_v<mapped_type, _Args...>
1235 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
1237 return _Impl::_M_try_emplace(__hint, std::move(__k),
1238 std::forward<_Args>(__args)...).first;
1241 template<typename _Key2, typename... _Args>
1242 requires __transparent_comparator<_Compare>
1243 && is_constructible_v<key_type, _Key2>
1244 && is_constructible_v<mapped_type, _Args...>
1246 try_emplace(const_iterator __hint, _Key2&& __k, _Args&&... __args)
1248 return _Impl::_M_try_emplace(__hint, std::forward<_Key2>(__k),
1249 std::forward<_Args>(__args)...).first;
1252 template<typename _Mapped>
1253 requires is_assignable_v<mapped_type&, _Mapped>
1254 && is_constructible_v<mapped_type, _Mapped>
1255 pair<iterator, bool>
1256 insert_or_assign(const key_type& __k, _Mapped&& __obj)
1257 { return insert_or_assign<const key_type&, _Mapped>(__k, std::forward<_Mapped>(__obj)); }
1259 template<typename _Mapped>
1260 requires is_assignable_v<mapped_type&, _Mapped>
1261 && is_constructible_v<mapped_type, _Mapped>
1262 pair<iterator, bool>
1263 insert_or_assign(key_type&& __k, _Mapped&& __obj)
1265 return insert_or_assign<key_type, _Mapped>(std::move(__k),
1266 std::forward<_Mapped>(__obj));
1269 template<typename _Key2, typename _Mapped>
1270 requires (same_as<remove_cvref_t<_Key2>, _Key> || __transparent_comparator<_Compare>)
1271 && is_constructible_v<key_type, _Key2>
1272 && is_assignable_v<mapped_type&, _Mapped>
1273 && is_constructible_v<mapped_type, _Mapped>
1274 pair<iterator, bool>
1275 insert_or_assign(_Key2&& __k, _Mapped&& __obj)
1277 auto __r = _Impl::_M_try_emplace(nullopt, std::forward<_Key2>(__k),
1278 std::forward<_Mapped>(__obj));
1280 __r.first->second = std::forward<_Mapped>(__obj);
1284 template<typename _Mapped>
1285 requires is_assignable_v<mapped_type&, _Mapped>
1286 && is_constructible_v<mapped_type, _Mapped>
1288 insert_or_assign(const_iterator __hint, const key_type& __k, _Mapped&& __obj)
1290 return insert_or_assign<const key_type&, _Mapped>(__hint, __k,
1291 std::forward<_Mapped>(__obj));
1294 template<typename _Mapped>
1295 requires is_assignable_v<mapped_type&, _Mapped>
1296 && is_constructible_v<mapped_type, _Mapped>
1298 insert_or_assign(const_iterator __hint, key_type&& __k, _Mapped&& __obj)
1300 return insert_or_assign<key_type, _Mapped>(__hint, std::move(__k),
1301 std::forward<_Mapped>(__obj));
1304 template<typename _Key2, typename _Mapped>
1305 requires (same_as<remove_cvref_t<_Key2>, _Key> || __transparent_comparator<_Compare>)
1306 && is_constructible_v<key_type, _Key2>
1307 && is_assignable_v<mapped_type&, _Mapped>
1308 && is_constructible_v<mapped_type, _Mapped>
1310 insert_or_assign(const_iterator __hint, _Key2&& __k, _Mapped&& __obj)
1312 auto __r = _Impl::_M_try_emplace(__hint, std::forward<_Key2>(__k),
1313 std::forward<_Mapped>(__obj));
1315 __r.first->second = std::forward<_Mapped>(__obj);
1320 using _Impl::key_comp;
1321 using _Impl::value_comp;
1323 using _Impl::values;
1328 using _Impl::contains;
1329 using _Impl::lower_bound;
1330 using _Impl::upper_bound;
1331 using _Impl::equal_range;
1334 template<typename _KeyContainer, typename _MappedContainer,
1335 __not_allocator_like _Compare = less<typename _KeyContainer::value_type>>
1336 flat_map(_KeyContainer, _MappedContainer, _Compare = _Compare())
1337 -> flat_map<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1338 _Compare, _KeyContainer, _MappedContainer>;
1340 template<typename _KeyContainer, typename _MappedContainer,
1341 __allocator_for<_KeyContainer, _MappedContainer> _Alloc>
1342 flat_map(_KeyContainer, _MappedContainer, _Alloc)
1343 -> flat_map<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1344 less<typename _KeyContainer::value_type>, _KeyContainer, _MappedContainer>;
1346 template<typename _KeyContainer, typename _MappedContainer, __not_allocator_like _Compare,
1347 __allocator_for<_KeyContainer, _MappedContainer> _Alloc>
1348 flat_map(_KeyContainer, _MappedContainer, _Compare, _Alloc)
1349 -> flat_map<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1350 _Compare, _KeyContainer, _MappedContainer>;
1352 template<typename _KeyContainer, typename _MappedContainer,
1353 __not_allocator_like _Compare = less<typename _KeyContainer::value_type>>
1354 flat_map(sorted_unique_t, _KeyContainer, _MappedContainer, _Compare = _Compare())
1355 -> flat_map<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1356 _Compare, _KeyContainer, _MappedContainer>;
1358 template<typename _KeyContainer, typename _MappedContainer,
1359 __allocator_for<_KeyContainer, _MappedContainer> _Alloc>
1360 flat_map(sorted_unique_t, _KeyContainer, _MappedContainer, _Alloc)
1361 -> flat_map<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1362 less<typename _KeyContainer::value_type>, _KeyContainer, _MappedContainer>;
1364 template<typename _KeyContainer, typename _MappedContainer, __not_allocator_like _Compare,
1365 __allocator_for<_KeyContainer, _MappedContainer> _Alloc>
1366 flat_map(sorted_unique_t, _KeyContainer, _MappedContainer, _Compare, _Alloc)
1367 -> flat_map<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1368 _Compare, _KeyContainer, _MappedContainer>;
1370 template<__has_input_iter_cat _InputIterator,
1371 __not_allocator_like _Compare = less<__iter_key_t<_InputIterator>>>
1372 flat_map(_InputIterator, _InputIterator, _Compare = _Compare())
1373 -> flat_map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, _Compare>;
1375 template<__has_input_iter_cat _InputIterator,
1376 __not_allocator_like _Compare = less<__iter_key_t<_InputIterator>>>
1377 flat_map(sorted_unique_t, _InputIterator, _InputIterator, _Compare = _Compare())
1378 -> flat_map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, _Compare>;
1380 template<ranges::input_range _Rg,
1381 __not_allocator_like _Compare = less<__detail::__range_key_type<_Rg>>,
1382 __allocator_like _Alloc = allocator<byte>>
1383 flat_map(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
1384 -> flat_map<__detail::__range_key_type<_Rg>, __detail::__range_mapped_type<_Rg>,
1386 vector<__detail::__range_key_type<_Rg>,
1387 __alloc_rebind<_Alloc, __detail::__range_key_type<_Rg>>>,
1388 vector<__detail::__range_mapped_type<_Rg>,
1389 __alloc_rebind<_Alloc, __detail::__range_mapped_type<_Rg>>>>;
1391 template<ranges::input_range _Rg, __allocator_like _Alloc>
1392 flat_map(from_range_t, _Rg&&, _Alloc)
1393 -> flat_map<__detail::__range_key_type<_Rg>, __detail::__range_mapped_type<_Rg>,
1394 less<__detail::__range_key_type<_Rg>>,
1395 vector<__detail::__range_key_type<_Rg>,
1396 __alloc_rebind<_Alloc, __detail::__range_key_type<_Rg>>>,
1397 vector<__detail::__range_mapped_type<_Rg>,
1398 __alloc_rebind<_Alloc, __detail::__range_mapped_type<_Rg>>>>;
1400 template<typename _Key, typename _Tp, __not_allocator_like _Compare = less<_Key>>
1401 flat_map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare())
1402 -> flat_map<_Key, _Tp, _Compare>;
1404 template<typename _Key, typename _Tp, __not_allocator_like _Compare = less<_Key>>
1405 flat_map(sorted_unique_t, initializer_list<pair<_Key, _Tp>>, _Compare = _Compare())
1406 -> flat_map<_Key, _Tp, _Compare>;
1408 template<typename _Key, typename _Tp, typename _Compare,
1409 typename _KeyContainer, typename _MappedContainer, typename _Alloc>
1410 struct uses_allocator<flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>, _Alloc>
1411 : bool_constant<uses_allocator_v<_KeyContainer, _Alloc>
1412 && uses_allocator_v<_MappedContainer, _Alloc>>
1415 /* Class template flat_multimap - container adaptor
1419 template<typename _Key, typename _Tp, typename _Compare = less<_Key>,
1420 typename _KeyContainer = vector<_Key>,
1421 typename _MappedContainer = vector<_Tp>>
1423 : private _Flat_map_impl<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer, true>
1425 using _Impl = _Flat_map_impl<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer, true>;
1430 using typename _Impl::key_type;
1431 using typename _Impl::mapped_type;
1432 using typename _Impl::value_type;
1433 using typename _Impl::key_compare;
1434 using typename _Impl::reference;
1435 using typename _Impl::const_reference;
1436 using typename _Impl::size_type;
1437 using typename _Impl::difference_type;
1438 using typename _Impl::iterator;
1439 using typename _Impl::const_iterator;
1440 using typename _Impl::reverse_iterator;
1441 using typename _Impl::const_reverse_iterator;
1442 using typename _Impl::key_container_type;
1443 using typename _Impl::mapped_container_type;
1444 using typename _Impl::value_compare;
1445 using typename _Impl::containers;
1453 using _Impl::rbegin;
1456 using _Impl::cbegin;
1458 using _Impl::crbegin;
1464 using _Impl::max_size;
1467 using _Impl::emplace;
1468 using _Impl::emplace_hint;
1469 using _Impl::insert;
1470 using _Impl::insert_range;
1471 using _Impl::extract;
1472 using _Impl::replace;
1478 using _Impl::key_comp;
1479 using _Impl::value_comp;
1481 using _Impl::values;
1486 using _Impl::contains;
1487 using _Impl::lower_bound;
1488 using _Impl::upper_bound;
1489 using _Impl::equal_range;
1492 template<typename _KeyContainer, typename _MappedContainer,
1493 __not_allocator_like _Compare = less<typename _KeyContainer::value_type>>
1494 flat_multimap(_KeyContainer, _MappedContainer, _Compare = _Compare())
1495 -> flat_multimap<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1496 _Compare, _KeyContainer, _MappedContainer>;
1498 template<typename _KeyContainer, typename _MappedContainer,
1499 __allocator_for<_KeyContainer, _MappedContainer> _Alloc>
1500 flat_multimap(_KeyContainer, _MappedContainer, _Alloc)
1501 -> flat_multimap<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1502 less<typename _KeyContainer::value_type>, _KeyContainer, _MappedContainer>;
1504 template<typename _KeyContainer, typename _MappedContainer, __not_allocator_like _Compare,
1505 __allocator_for<_KeyContainer, _MappedContainer> _Alloc>
1506 flat_multimap(_KeyContainer, _MappedContainer, _Compare, _Alloc)
1507 -> flat_multimap<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1508 _Compare, _KeyContainer, _MappedContainer>;
1510 template<typename _KeyContainer, typename _MappedContainer,
1511 __not_allocator_like _Compare = less<typename _KeyContainer::value_type>>
1512 flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Compare = _Compare())
1513 -> flat_multimap<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1514 _Compare, _KeyContainer, _MappedContainer>;
1516 template<typename _KeyContainer, typename _MappedContainer,
1517 __allocator_for<_KeyContainer, _MappedContainer> _Alloc>
1518 flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Alloc)
1519 -> flat_multimap<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1520 less<typename _KeyContainer::value_type>, _KeyContainer, _MappedContainer>;
1522 template<typename _KeyContainer, typename _MappedContainer, __not_allocator_like _Compare,
1523 __allocator_for<_KeyContainer, _MappedContainer> _Alloc>
1524 flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Compare, _Alloc)
1525 -> flat_multimap<typename _KeyContainer::value_type, typename _MappedContainer::value_type,
1526 _Compare, _KeyContainer, _MappedContainer>;
1528 template<__has_input_iter_cat _InputIterator,
1529 __not_allocator_like _Compare = less<__iter_key_t<_InputIterator>>>
1530 flat_multimap(_InputIterator, _InputIterator, _Compare = _Compare())
1531 -> flat_multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, _Compare>;
1533 template<__has_input_iter_cat _InputIterator,
1534 __not_allocator_like _Compare = less<__iter_key_t<_InputIterator>>>
1535 flat_multimap(sorted_equivalent_t, _InputIterator, _InputIterator, _Compare = _Compare())
1536 -> flat_multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, _Compare>;
1538 template<ranges::input_range _Rg,
1539 __not_allocator_like _Compare = less<__detail::__range_key_type<_Rg>>,
1540 __allocator_like _Alloc = allocator<byte>>
1541 flat_multimap(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
1542 -> flat_multimap<__detail::__range_key_type<_Rg>, __detail::__range_mapped_type<_Rg>,
1544 vector<__detail::__range_key_type<_Rg>,
1545 __alloc_rebind<_Alloc, __detail::__range_key_type<_Rg>>>,
1546 vector<__detail::__range_mapped_type<_Rg>,
1547 __alloc_rebind<_Alloc, __detail::__range_mapped_type<_Rg>>>>;
1549 template<ranges::input_range _Rg, __allocator_like _Alloc>
1550 flat_multimap(from_range_t, _Rg&&, _Alloc)
1551 -> flat_multimap<__detail::__range_key_type<_Rg>, __detail::__range_mapped_type<_Rg>,
1552 less<__detail::__range_key_type<_Rg>>,
1553 vector<__detail::__range_key_type<_Rg>,
1554 __alloc_rebind<_Alloc, __detail::__range_key_type<_Rg>>>,
1555 vector<__detail::__range_mapped_type<_Rg>,
1556 __alloc_rebind<_Alloc, __detail::__range_mapped_type<_Rg>>>>;
1558 template<typename _Key, typename _Tp, __not_allocator_like _Compare = less<_Key>>
1559 flat_multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare())
1560 -> flat_multimap<_Key, _Tp, _Compare>;
1562 template<typename _Key, typename _Tp, __not_allocator_like _Compare = less<_Key>>
1563 flat_multimap(sorted_equivalent_t, initializer_list<pair<_Key, _Tp>>, _Compare = _Compare())
1564 -> flat_multimap<_Key, _Tp, _Compare>;
1566 template<typename _Key, typename _Tp, typename _Compare,
1567 typename _KeyContainer, typename _MappedContainer, typename _Alloc>
1568 struct uses_allocator<flat_multimap<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>,
1570 : bool_constant<uses_allocator_v<_KeyContainer, _Alloc>
1571 && uses_allocator_v<_MappedContainer, _Alloc>>
1574_GLIBCXX_END_NAMESPACE_VERSION
1576#endif // __cpp_lib_flat_map
1577#endif // _GLIBCXX_FLAT_MAP