libstdc++
stl_map.h
Go to the documentation of this file.
1 // Map implementation -*- C++ -*-
2 
3 // Copyright (C) 2001-2016 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 /*
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,1997
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 
51 /** @file bits/stl_map.h
52  * This is an internal header file, included by other library headers.
53  * Do not attempt to use it directly. @headername{map}
54  */
55 
56 #ifndef _STL_MAP_H
57 #define _STL_MAP_H 1
58 
59 #include <bits/functexcept.h>
60 #include <bits/concept_check.h>
61 #if __cplusplus >= 201103L
62 #include <initializer_list>
63 #include <tuple>
64 #endif
65 
66 namespace std _GLIBCXX_VISIBILITY(default)
67 {
68 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
69 
70  template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
71  class multimap;
72 
73  /**
74  * @brief A standard container made up of (key,value) pairs, which can be
75  * retrieved based on a key, in logarithmic time.
76  *
77  * @ingroup associative_containers
78  *
79  * @tparam _Key Type of key objects.
80  * @tparam _Tp Type of mapped objects.
81  * @tparam _Compare Comparison function object type, defaults to less<_Key>.
82  * @tparam _Alloc Allocator type, defaults to
83  * allocator<pair<const _Key, _Tp>.
84  *
85  * Meets the requirements of a <a href="tables.html#65">container</a>, a
86  * <a href="tables.html#66">reversible container</a>, and an
87  * <a href="tables.html#69">associative container</a> (using unique keys).
88  * For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the
89  * value_type is std::pair<const Key,T>.
90  *
91  * Maps support bidirectional iterators.
92  *
93  * The private tree data is declared exactly the same way for map and
94  * multimap; the distinction is made entirely in how the tree functions are
95  * called (*_unique versus *_equal, same as the standard).
96  */
97  template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
98  typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
99  class map
100  {
101  public:
102  typedef _Key key_type;
103  typedef _Tp mapped_type;
105  typedef _Compare key_compare;
106  typedef _Alloc allocator_type;
107 
108  private:
109  // concept requirements
110  typedef typename _Alloc::value_type _Alloc_value_type;
111  __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
112  __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
113  _BinaryFunctionConcept)
114  __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
115 
116  public:
117  class value_compare
118  : public std::binary_function<value_type, value_type, bool>
119  {
120  friend class map<_Key, _Tp, _Compare, _Alloc>;
121  protected:
122  _Compare comp;
123 
124  value_compare(_Compare __c)
125  : comp(__c) { }
126 
127  public:
128  bool operator()(const value_type& __x, const value_type& __y) const
129  { return comp(__x.first, __y.first); }
130  };
131 
132  private:
133  /// This turns a red-black tree into a [multi]map.
135  rebind<value_type>::other _Pair_alloc_type;
136 
137  typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
138  key_compare, _Pair_alloc_type> _Rep_type;
139 
140  /// The actual tree structure.
141  _Rep_type _M_t;
142 
144 
145  public:
146  // many of these are specified differently in ISO, but the following are
147  // "functionally equivalent"
148  typedef typename _Alloc_traits::pointer pointer;
149  typedef typename _Alloc_traits::const_pointer const_pointer;
150  typedef typename _Alloc_traits::reference reference;
151  typedef typename _Alloc_traits::const_reference const_reference;
152  typedef typename _Rep_type::iterator iterator;
153  typedef typename _Rep_type::const_iterator const_iterator;
154  typedef typename _Rep_type::size_type size_type;
155  typedef typename _Rep_type::difference_type difference_type;
158 
159 #if __cplusplus > 201402L
160  using node_type = typename _Rep_type::node_type;
161  using insert_return_type = typename _Rep_type::insert_return_type;
162 #endif
163 
164  // [23.3.1.1] construct/copy/destroy
165  // (get_allocator() is also listed in this section)
166 
167  /**
168  * @brief Default constructor creates no elements.
169  */
170 #if __cplusplus < 201103L
171  map() : _M_t() { }
172 #else
173  map() = default;
174 #endif
175 
176  /**
177  * @brief Creates a %map with no elements.
178  * @param __comp A comparison object.
179  * @param __a An allocator object.
180  */
181  explicit
182  map(const _Compare& __comp,
183  const allocator_type& __a = allocator_type())
184  : _M_t(__comp, _Pair_alloc_type(__a)) { }
185 
186  /**
187  * @brief %Map copy constructor.
188  * @param __x A %map of identical element and allocator types.
189  *
190  * The newly-created %map uses a copy of the allocator object used
191  * by @a __x (unless the allocator traits dictate a different object).
192  */
193  map(const map& __x)
194  : _M_t(__x._M_t) { }
195 
196 #if __cplusplus >= 201103L
197  /**
198  * @brief %Map move constructor.
199  * @param __x A %map of identical element and allocator types.
200  *
201  * The newly-created %map contains the exact contents of @a __x.
202  * The contents of @a __x are a valid, but unspecified %map.
203  */
204  map(map&& __x)
205  noexcept(is_nothrow_copy_constructible<_Compare>::value)
206  : _M_t(std::move(__x._M_t)) { }
207 
208  /**
209  * @brief Builds a %map from an initializer_list.
210  * @param __l An initializer_list.
211  * @param __comp A comparison object.
212  * @param __a An allocator object.
213  *
214  * Create a %map consisting of copies of the elements in the
215  * initializer_list @a __l.
216  * This is linear in N if the range is already sorted, and NlogN
217  * otherwise (where N is @a __l.size()).
218  */
220  const _Compare& __comp = _Compare(),
221  const allocator_type& __a = allocator_type())
222  : _M_t(__comp, _Pair_alloc_type(__a))
223  { _M_t._M_insert_unique(__l.begin(), __l.end()); }
224 
225  /// Allocator-extended default constructor.
226  explicit
227  map(const allocator_type& __a)
228  : _M_t(_Compare(), _Pair_alloc_type(__a)) { }
229 
230  /// Allocator-extended copy constructor.
231  map(const map& __m, const allocator_type& __a)
232  : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
233 
234  /// Allocator-extended move constructor.
235  map(map&& __m, const allocator_type& __a)
236  noexcept(is_nothrow_copy_constructible<_Compare>::value
237  && _Alloc_traits::_S_always_equal())
238  : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { }
239 
240  /// Allocator-extended initialier-list constructor.
241  map(initializer_list<value_type> __l, const allocator_type& __a)
242  : _M_t(_Compare(), _Pair_alloc_type(__a))
243  { _M_t._M_insert_unique(__l.begin(), __l.end()); }
244 
245  /// Allocator-extended range constructor.
246  template<typename _InputIterator>
247  map(_InputIterator __first, _InputIterator __last,
248  const allocator_type& __a)
249  : _M_t(_Compare(), _Pair_alloc_type(__a))
250  { _M_t._M_insert_unique(__first, __last); }
251 #endif
252 
253  /**
254  * @brief Builds a %map from a range.
255  * @param __first An input iterator.
256  * @param __last An input iterator.
257  *
258  * Create a %map consisting of copies of the elements from
259  * [__first,__last). This is linear in N if the range is
260  * already sorted, and NlogN otherwise (where N is
261  * distance(__first,__last)).
262  */
263  template<typename _InputIterator>
264  map(_InputIterator __first, _InputIterator __last)
265  : _M_t()
266  { _M_t._M_insert_unique(__first, __last); }
267 
268  /**
269  * @brief Builds a %map from a range.
270  * @param __first An input iterator.
271  * @param __last An input iterator.
272  * @param __comp A comparison functor.
273  * @param __a An allocator object.
274  *
275  * Create a %map consisting of copies of the elements from
276  * [__first,__last). This is linear in N if the range is
277  * already sorted, and NlogN otherwise (where N is
278  * distance(__first,__last)).
279  */
280  template<typename _InputIterator>
281  map(_InputIterator __first, _InputIterator __last,
282  const _Compare& __comp,
283  const allocator_type& __a = allocator_type())
284  : _M_t(__comp, _Pair_alloc_type(__a))
285  { _M_t._M_insert_unique(__first, __last); }
286 
287  // FIXME There is no dtor declared, but we should have something
288  // generated by Doxygen. I don't know what tags to add to this
289  // paragraph to make that happen:
290  /**
291  * The dtor only erases the elements, and note that if the elements
292  * themselves are pointers, the pointed-to memory is not touched in any
293  * way. Managing the pointer is the user's responsibility.
294  */
295 
296  /**
297  * @brief %Map assignment operator.
298  * @param __x A %map of identical element and allocator types.
299  *
300  * All the elements of @a __x are copied.
301  *
302  * Whether the allocator is copied depends on the allocator traits.
303  */
304  map&
305  operator=(const map& __x)
306  {
307  _M_t = __x._M_t;
308  return *this;
309  }
310 
311 #if __cplusplus >= 201103L
312  /// Move assignment operator.
313  map&
314  operator=(map&&) = default;
315 
316  /**
317  * @brief %Map list assignment operator.
318  * @param __l An initializer_list.
319  *
320  * This function fills a %map with copies of the elements in the
321  * initializer list @a __l.
322  *
323  * Note that the assignment completely changes the %map and
324  * that the resulting %map's size is the same as the number
325  * of elements assigned.
326  */
327  map&
329  {
330  _M_t._M_assign_unique(__l.begin(), __l.end());
331  return *this;
332  }
333 #endif
334 
335  /// Get a copy of the memory allocation object.
336  allocator_type
337  get_allocator() const _GLIBCXX_NOEXCEPT
338  { return allocator_type(_M_t.get_allocator()); }
339 
340  // iterators
341  /**
342  * Returns a read/write iterator that points to the first pair in the
343  * %map.
344  * Iteration is done in ascending order according to the keys.
345  */
346  iterator
347  begin() _GLIBCXX_NOEXCEPT
348  { return _M_t.begin(); }
349 
350  /**
351  * Returns a read-only (constant) iterator that points to the first pair
352  * in the %map. Iteration is done in ascending order according to the
353  * keys.
354  */
355  const_iterator
356  begin() const _GLIBCXX_NOEXCEPT
357  { return _M_t.begin(); }
358 
359  /**
360  * Returns a read/write iterator that points one past the last
361  * pair in the %map. Iteration is done in ascending order
362  * according to the keys.
363  */
364  iterator
365  end() _GLIBCXX_NOEXCEPT
366  { return _M_t.end(); }
367 
368  /**
369  * Returns a read-only (constant) iterator that points one past the last
370  * pair in the %map. Iteration is done in ascending order according to
371  * the keys.
372  */
373  const_iterator
374  end() const _GLIBCXX_NOEXCEPT
375  { return _M_t.end(); }
376 
377  /**
378  * Returns a read/write reverse iterator that points to the last pair in
379  * the %map. Iteration is done in descending order according to the
380  * keys.
381  */
382  reverse_iterator
383  rbegin() _GLIBCXX_NOEXCEPT
384  { return _M_t.rbegin(); }
385 
386  /**
387  * Returns a read-only (constant) reverse iterator that points to the
388  * last pair in the %map. Iteration is done in descending order
389  * according to the keys.
390  */
391  const_reverse_iterator
392  rbegin() const _GLIBCXX_NOEXCEPT
393  { return _M_t.rbegin(); }
394 
395  /**
396  * Returns a read/write reverse iterator that points to one before the
397  * first pair in the %map. Iteration is done in descending order
398  * according to the keys.
399  */
400  reverse_iterator
401  rend() _GLIBCXX_NOEXCEPT
402  { return _M_t.rend(); }
403 
404  /**
405  * Returns a read-only (constant) reverse iterator that points to one
406  * before the first pair in the %map. Iteration is done in descending
407  * order according to the keys.
408  */
409  const_reverse_iterator
410  rend() const _GLIBCXX_NOEXCEPT
411  { return _M_t.rend(); }
412 
413 #if __cplusplus >= 201103L
414  /**
415  * Returns a read-only (constant) iterator that points to the first pair
416  * in the %map. Iteration is done in ascending order according to the
417  * keys.
418  */
419  const_iterator
420  cbegin() const noexcept
421  { return _M_t.begin(); }
422 
423  /**
424  * Returns a read-only (constant) iterator that points one past the last
425  * pair in the %map. Iteration is done in ascending order according to
426  * the keys.
427  */
428  const_iterator
429  cend() const noexcept
430  { return _M_t.end(); }
431 
432  /**
433  * Returns a read-only (constant) reverse iterator that points to the
434  * last pair in the %map. Iteration is done in descending order
435  * according to the keys.
436  */
437  const_reverse_iterator
438  crbegin() const noexcept
439  { return _M_t.rbegin(); }
440 
441  /**
442  * Returns a read-only (constant) reverse iterator that points to one
443  * before the first pair in the %map. Iteration is done in descending
444  * order according to the keys.
445  */
446  const_reverse_iterator
447  crend() const noexcept
448  { return _M_t.rend(); }
449 #endif
450 
451  // capacity
452  /** Returns true if the %map is empty. (Thus begin() would equal
453  * end().)
454  */
455  bool
456  empty() const _GLIBCXX_NOEXCEPT
457  { return _M_t.empty(); }
458 
459  /** Returns the size of the %map. */
460  size_type
461  size() const _GLIBCXX_NOEXCEPT
462  { return _M_t.size(); }
463 
464  /** Returns the maximum size of the %map. */
465  size_type
466  max_size() const _GLIBCXX_NOEXCEPT
467  { return _M_t.max_size(); }
468 
469  // [23.3.1.2] element access
470  /**
471  * @brief Subscript ( @c [] ) access to %map data.
472  * @param __k The key for which data should be retrieved.
473  * @return A reference to the data of the (key,data) %pair.
474  *
475  * Allows for easy lookup with the subscript ( @c [] )
476  * operator. Returns data associated with the key specified in
477  * subscript. If the key does not exist, a pair with that key
478  * is created using default values, which is then returned.
479  *
480  * Lookup requires logarithmic time.
481  */
482  mapped_type&
483  operator[](const key_type& __k)
484  {
485  // concept requirements
486  __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
487 
488  iterator __i = lower_bound(__k);
489  // __i->first is greater than or equivalent to __k.
490  if (__i == end() || key_comp()(__k, (*__i).first))
491 #if __cplusplus >= 201103L
492  __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
494  std::tuple<>());
495 #else
496  __i = insert(__i, value_type(__k, mapped_type()));
497 #endif
498  return (*__i).second;
499  }
500 
501 #if __cplusplus >= 201103L
502  mapped_type&
503  operator[](key_type&& __k)
504  {
505  // concept requirements
506  __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
507 
508  iterator __i = lower_bound(__k);
509  // __i->first is greater than or equivalent to __k.
510  if (__i == end() || key_comp()(__k, (*__i).first))
511  __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
512  std::forward_as_tuple(std::move(__k)),
513  std::tuple<>());
514  return (*__i).second;
515  }
516 #endif
517 
518  // _GLIBCXX_RESOLVE_LIB_DEFECTS
519  // DR 464. Suggestion for new member functions in standard containers.
520  /**
521  * @brief Access to %map data.
522  * @param __k The key for which data should be retrieved.
523  * @return A reference to the data whose key is equivalent to @a __k, if
524  * such a data is present in the %map.
525  * @throw std::out_of_range If no such data is present.
526  */
527  mapped_type&
528  at(const key_type& __k)
529  {
530  iterator __i = lower_bound(__k);
531  if (__i == end() || key_comp()(__k, (*__i).first))
532  __throw_out_of_range(__N("map::at"));
533  return (*__i).second;
534  }
535 
536  const mapped_type&
537  at(const key_type& __k) const
538  {
539  const_iterator __i = lower_bound(__k);
540  if (__i == end() || key_comp()(__k, (*__i).first))
541  __throw_out_of_range(__N("map::at"));
542  return (*__i).second;
543  }
544 
545  // modifiers
546 #if __cplusplus >= 201103L
547  /**
548  * @brief Attempts to build and insert a std::pair into the %map.
549  *
550  * @param __args Arguments used to generate a new pair instance (see
551  * std::piecewise_contruct for passing arguments to each
552  * part of the pair constructor).
553  *
554  * @return A pair, of which the first element is an iterator that points
555  * to the possibly inserted pair, and the second is a bool that
556  * is true if the pair was actually inserted.
557  *
558  * This function attempts to build and insert a (key, value) %pair into
559  * the %map.
560  * A %map relies on unique keys and thus a %pair is only inserted if its
561  * first element (the key) is not already present in the %map.
562  *
563  * Insertion requires logarithmic time.
564  */
565  template<typename... _Args>
567  emplace(_Args&&... __args)
568  { return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
569 
570  /**
571  * @brief Attempts to build and insert a std::pair into the %map.
572  *
573  * @param __pos An iterator that serves as a hint as to where the pair
574  * should be inserted.
575  * @param __args Arguments used to generate a new pair instance (see
576  * std::piecewise_contruct for passing arguments to each
577  * part of the pair constructor).
578  * @return An iterator that points to the element with key of the
579  * std::pair built from @a __args (may or may not be that
580  * std::pair).
581  *
582  * This function is not concerned about whether the insertion took place,
583  * and thus does not return a boolean like the single-argument emplace()
584  * does.
585  * Note that the first parameter is only a hint and can potentially
586  * improve the performance of the insertion process. A bad hint would
587  * cause no gains in efficiency.
588  *
589  * See
590  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
591  * for more on @a hinting.
592  *
593  * Insertion requires logarithmic time (if the hint is not taken).
594  */
595  template<typename... _Args>
596  iterator
597  emplace_hint(const_iterator __pos, _Args&&... __args)
598  {
599  return _M_t._M_emplace_hint_unique(__pos,
600  std::forward<_Args>(__args)...);
601  }
602 #endif
603 
604 #if __cplusplus > 201402L
605  /// Extract a node.
606  node_type
607  extract(const_iterator __pos)
608  {
609  __glibcxx_assert(__pos != end());
610  return _M_t.extract(__pos);
611  }
612 
613  /// Extract a node.
614  node_type
615  extract(const key_type& __x)
616  { return _M_t.extract(__x); }
617 
618  /// Re-insert an extracted node.
619  insert_return_type
620  insert(node_type&& __nh)
621  { return _M_t._M_reinsert_node_unique(std::move(__nh)); }
622 
623  /// Re-insert an extracted node.
624  iterator
625  insert(const_iterator __hint, node_type&& __nh)
626  { return _M_t._M_reinsert_node_hint_unique(__hint, std::move(__nh)); }
627 
628  template<typename, typename>
629  friend class _Rb_tree_merge_helper;
630 
631  template<typename _C2>
632  void
633  merge(map<_Key, _Tp, _C2, _Alloc>& __source)
634  {
635  using _Merge_helper = _Rb_tree_merge_helper<map, _C2>;
636  _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
637  }
638 
639  template<typename _C2>
640  void
641  merge(map<_Key, _Tp, _C2, _Alloc>&& __source)
642  { merge(__source); }
643 
644  template<typename _C2>
645  void
646  merge(multimap<_Key, _Tp, _C2, _Alloc>& __source)
647  {
648  using _Merge_helper = _Rb_tree_merge_helper<map, _C2>;
649  _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
650  }
651 
652  template<typename _C2>
653  void
654  merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source)
655  { merge(__source); }
656 #endif // C++17
657 
658 #if __cplusplus > 201402L
659 #define __cpp_lib_map_try_emplace 201411
660  /**
661  * @brief Attempts to build and insert a std::pair into the %map.
662  *
663  * @param __k Key to use for finding a possibly existing pair in
664  * the map.
665  * @param __args Arguments used to generate the .second for a new pair
666  * instance.
667  *
668  * @return A pair, of which the first element is an iterator that points
669  * to the possibly inserted pair, and the second is a bool that
670  * is true if the pair was actually inserted.
671  *
672  * This function attempts to build and insert a (key, value) %pair into
673  * the %map.
674  * A %map relies on unique keys and thus a %pair is only inserted if its
675  * first element (the key) is not already present in the %map.
676  * If a %pair is not inserted, this function has no effect.
677  *
678  * Insertion requires logarithmic time.
679  */
680  template <typename... _Args>
682  try_emplace(const key_type& __k, _Args&&... __args)
683  {
684  iterator __i = lower_bound(__k);
685  if (__i == end() || key_comp()(__k, (*__i).first))
686  {
688  std::forward_as_tuple(__k),
689  std::forward_as_tuple(
690  std::forward<_Args>(__args)...));
691  return {__i, true};
692  }
693  return {__i, false};
694  }
695 
696  // move-capable overload
697  template <typename... _Args>
699  try_emplace(key_type&& __k, _Args&&... __args)
700  {
701  iterator __i = lower_bound(__k);
702  if (__i == end() || key_comp()(__k, (*__i).first))
703  {
705  std::forward_as_tuple(std::move(__k)),
706  std::forward_as_tuple(
707  std::forward<_Args>(__args)...));
708  return {__i, true};
709  }
710  return {__i, false};
711  }
712 
713  /**
714  * @brief Attempts to build and insert a std::pair into the %map.
715  *
716  * @param __hint An iterator that serves as a hint as to where the
717  * pair should be inserted.
718  * @param __k Key to use for finding a possibly existing pair in
719  * the map.
720  * @param __args Arguments used to generate the .second for a new pair
721  * instance.
722  * @return An iterator that points to the element with key of the
723  * std::pair built from @a __args (may or may not be that
724  * std::pair).
725  *
726  * This function is not concerned about whether the insertion took place,
727  * and thus does not return a boolean like the single-argument
728  * try_emplace() does. However, if insertion did not take place,
729  * this function has no effect.
730  * Note that the first parameter is only a hint and can potentially
731  * improve the performance of the insertion process. A bad hint would
732  * cause no gains in efficiency.
733  *
734  * See
735  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
736  * for more on @a hinting.
737  *
738  * Insertion requires logarithmic time (if the hint is not taken).
739  */
740  template <typename... _Args>
741  iterator
742  try_emplace(const_iterator __hint, const key_type& __k,
743  _Args&&... __args)
744  {
745  iterator __i;
746  auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
747  if (__true_hint.second)
748  __i = emplace_hint(iterator(__true_hint.second),
750  std::forward_as_tuple(__k),
751  std::forward_as_tuple(
752  std::forward<_Args>(__args)...));
753  else
754  __i = iterator(__true_hint.first);
755  return __i;
756  }
757 
758  // move-capable overload
759  template <typename... _Args>
760  iterator
761  try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
762  {
763  iterator __i;
764  auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
765  if (__true_hint.second)
766  __i = emplace_hint(iterator(__true_hint.second),
768  std::forward_as_tuple(std::move(__k)),
769  std::forward_as_tuple(
770  std::forward<_Args>(__args)...));
771  else
772  __i = iterator(__true_hint.first);
773  return __i;
774  }
775 #endif
776 
777  /**
778  * @brief Attempts to insert a std::pair into the %map.
779 
780  * @param __x Pair to be inserted (see std::make_pair for easy
781  * creation of pairs).
782  *
783  * @return A pair, of which the first element is an iterator that
784  * points to the possibly inserted pair, and the second is
785  * a bool that is true if the pair was actually inserted.
786  *
787  * This function attempts to insert a (key, value) %pair into the %map.
788  * A %map relies on unique keys and thus a %pair is only inserted if its
789  * first element (the key) is not already present in the %map.
790  *
791  * Insertion requires logarithmic time.
792  */
794  insert(const value_type& __x)
795  { return _M_t._M_insert_unique(__x); }
796 
797 #if __cplusplus >= 201103L
798  template<typename _Pair, typename = typename
799  std::enable_if<std::is_constructible<value_type,
800  _Pair&&>::value>::type>
802  insert(_Pair&& __x)
803  { return _M_t._M_insert_unique(std::forward<_Pair>(__x)); }
804 #endif
805 
806 #if __cplusplus >= 201103L
807  /**
808  * @brief Attempts to insert a list of std::pairs into the %map.
809  * @param __list A std::initializer_list<value_type> of pairs to be
810  * inserted.
811  *
812  * Complexity similar to that of the range constructor.
813  */
814  void
816  { insert(__list.begin(), __list.end()); }
817 #endif
818 
819  /**
820  * @brief Attempts to insert a std::pair into the %map.
821  * @param __position An iterator that serves as a hint as to where the
822  * pair should be inserted.
823  * @param __x Pair to be inserted (see std::make_pair for easy creation
824  * of pairs).
825  * @return An iterator that points to the element with key of
826  * @a __x (may or may not be the %pair passed in).
827  *
828 
829  * This function is not concerned about whether the insertion
830  * took place, and thus does not return a boolean like the
831  * single-argument insert() does. Note that the first
832  * parameter is only a hint and can potentially improve the
833  * performance of the insertion process. A bad hint would
834  * cause no gains in efficiency.
835  *
836  * See
837  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
838  * for more on @a hinting.
839  *
840  * Insertion requires logarithmic time (if the hint is not taken).
841  */
842  iterator
843 #if __cplusplus >= 201103L
844  insert(const_iterator __position, const value_type& __x)
845 #else
846  insert(iterator __position, const value_type& __x)
847 #endif
848  { return _M_t._M_insert_unique_(__position, __x); }
849 
850 #if __cplusplus >= 201103L
851  template<typename _Pair, typename = typename
852  std::enable_if<std::is_constructible<value_type,
853  _Pair&&>::value>::type>
854  iterator
855  insert(const_iterator __position, _Pair&& __x)
856  { return _M_t._M_insert_unique_(__position,
857  std::forward<_Pair>(__x)); }
858 #endif
859 
860  /**
861  * @brief Template function that attempts to insert a range of elements.
862  * @param __first Iterator pointing to the start of the range to be
863  * inserted.
864  * @param __last Iterator pointing to the end of the range.
865  *
866  * Complexity similar to that of the range constructor.
867  */
868  template<typename _InputIterator>
869  void
870  insert(_InputIterator __first, _InputIterator __last)
871  { _M_t._M_insert_unique(__first, __last); }
872 
873 #if __cplusplus > 201402L
874 #define __cpp_lib_map_insertion 201411
875  /**
876  * @brief Attempts to insert or assign a std::pair into the %map.
877  * @param __k Key to use for finding a possibly existing pair in
878  * the map.
879  * @param __obj Argument used to generate the .second for a pair
880  * instance.
881  *
882  * @return A pair, of which the first element is an iterator that
883  * points to the possibly inserted pair, and the second is
884  * a bool that is true if the pair was actually inserted.
885  *
886  * This function attempts to insert a (key, value) %pair into the %map.
887  * A %map relies on unique keys and thus a %pair is only inserted if its
888  * first element (the key) is not already present in the %map.
889  * If the %pair was already in the %map, the .second of the %pair
890  * is assigned from __obj.
891  *
892  * Insertion requires logarithmic time.
893  */
894  template <typename _Obj>
896  insert_or_assign(const key_type& __k, _Obj&& __obj)
897  {
898  iterator __i = lower_bound(__k);
899  if (__i == end() || key_comp()(__k, (*__i).first))
900  {
902  std::forward_as_tuple(__k),
903  std::forward_as_tuple(
904  std::forward<_Obj>(__obj)));
905  return {__i, true};
906  }
907  (*__i).second = std::forward<_Obj>(__obj);
908  return {__i, false};
909  }
910 
911  // move-capable overload
912  template <typename _Obj>
914  insert_or_assign(key_type&& __k, _Obj&& __obj)
915  {
916  iterator __i = lower_bound(__k);
917  if (__i == end() || key_comp()(__k, (*__i).first))
918  {
920  std::forward_as_tuple(std::move(__k)),
921  std::forward_as_tuple(
922  std::forward<_Obj>(__obj)));
923  return {__i, true};
924  }
925  (*__i).second = std::forward<_Obj>(__obj);
926  return {__i, false};
927  }
928 
929  /**
930  * @brief Attempts to insert or assign a std::pair into the %map.
931  * @param __hint An iterator that serves as a hint as to where the
932  * pair should be inserted.
933  * @param __k Key to use for finding a possibly existing pair in
934  * the map.
935  * @param __obj Argument used to generate the .second for a pair
936  * instance.
937  *
938  * @return An iterator that points to the element with key of
939  * @a __x (may or may not be the %pair passed in).
940  *
941  * This function attempts to insert a (key, value) %pair into the %map.
942  * A %map relies on unique keys and thus a %pair is only inserted if its
943  * first element (the key) is not already present in the %map.
944  * If the %pair was already in the %map, the .second of the %pair
945  * is assigned from __obj.
946  *
947  * Insertion requires logarithmic time.
948  */
949  template <typename _Obj>
950  iterator
951  insert_or_assign(const_iterator __hint,
952  const key_type& __k, _Obj&& __obj)
953  {
954  iterator __i;
955  auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
956  if (__true_hint.second)
957  {
958  return emplace_hint(iterator(__true_hint.second),
960  std::forward_as_tuple(__k),
961  std::forward_as_tuple(
962  std::forward<_Obj>(__obj)));
963  }
964  __i = iterator(__true_hint.first);
965  (*__i).second = std::forward<_Obj>(__obj);
966  return __i;
967  }
968 
969  // move-capable overload
970  template <typename _Obj>
971  iterator
972  insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
973  {
974  iterator __i;
975  auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
976  if (__true_hint.second)
977  {
978  return emplace_hint(iterator(__true_hint.second),
980  std::forward_as_tuple(std::move(__k)),
981  std::forward_as_tuple(
982  std::forward<_Obj>(__obj)));
983  }
984  __i = iterator(__true_hint.first);
985  (*__i).second = std::forward<_Obj>(__obj);
986  return __i;
987  }
988 #endif
989 
990 #if __cplusplus >= 201103L
991  // _GLIBCXX_RESOLVE_LIB_DEFECTS
992  // DR 130. Associative erase should return an iterator.
993  /**
994  * @brief Erases an element from a %map.
995  * @param __position An iterator pointing to the element to be erased.
996  * @return An iterator pointing to the element immediately following
997  * @a position prior to the element being erased. If no such
998  * element exists, end() is returned.
999  *
1000  * This function erases an element, pointed to by the given
1001  * iterator, from a %map. Note that this function only erases
1002  * the element, and that if the element is itself a pointer,
1003  * the pointed-to memory is not touched in any way. Managing
1004  * the pointer is the user's responsibility.
1005  */
1006  iterator
1007  erase(const_iterator __position)
1008  { return _M_t.erase(__position); }
1009 
1010  // LWG 2059
1011  _GLIBCXX_ABI_TAG_CXX11
1012  iterator
1013  erase(iterator __position)
1014  { return _M_t.erase(__position); }
1015 #else
1016  /**
1017  * @brief Erases an element from a %map.
1018  * @param __position An iterator pointing to the element to be erased.
1019  *
1020  * This function erases an element, pointed to by the given
1021  * iterator, from a %map. Note that this function only erases
1022  * the element, and that if the element is itself a pointer,
1023  * the pointed-to memory is not touched in any way. Managing
1024  * the pointer is the user's responsibility.
1025  */
1026  void
1027  erase(iterator __position)
1028  { _M_t.erase(__position); }
1029 #endif
1030 
1031  /**
1032  * @brief Erases elements according to the provided key.
1033  * @param __x Key of element to be erased.
1034  * @return The number of elements erased.
1035  *
1036  * This function erases all the elements located by the given key from
1037  * a %map.
1038  * Note that this function only erases the element, and that if
1039  * the element is itself a pointer, the pointed-to memory is not touched
1040  * in any way. Managing the pointer is the user's responsibility.
1041  */
1042  size_type
1043  erase(const key_type& __x)
1044  { return _M_t.erase(__x); }
1045 
1046 #if __cplusplus >= 201103L
1047  // _GLIBCXX_RESOLVE_LIB_DEFECTS
1048  // DR 130. Associative erase should return an iterator.
1049  /**
1050  * @brief Erases a [first,last) range of elements from a %map.
1051  * @param __first Iterator pointing to the start of the range to be
1052  * erased.
1053  * @param __last Iterator pointing to the end of the range to
1054  * be erased.
1055  * @return The iterator @a __last.
1056  *
1057  * This function erases a sequence of elements from a %map.
1058  * Note that this function only erases the element, and that if
1059  * the element is itself a pointer, the pointed-to memory is not touched
1060  * in any way. Managing the pointer is the user's responsibility.
1061  */
1062  iterator
1063  erase(const_iterator __first, const_iterator __last)
1064  { return _M_t.erase(__first, __last); }
1065 #else
1066  /**
1067  * @brief Erases a [__first,__last) range of elements from a %map.
1068  * @param __first Iterator pointing to the start of the range to be
1069  * erased.
1070  * @param __last Iterator pointing to the end of the range to
1071  * be erased.
1072  *
1073  * This function erases a sequence of elements from a %map.
1074  * Note that this function only erases the element, and that if
1075  * the element is itself a pointer, the pointed-to memory is not touched
1076  * in any way. Managing the pointer is the user's responsibility.
1077  */
1078  void
1079  erase(iterator __first, iterator __last)
1080  { _M_t.erase(__first, __last); }
1081 #endif
1082 
1083  /**
1084  * @brief Swaps data with another %map.
1085  * @param __x A %map of the same element and allocator types.
1086  *
1087  * This exchanges the elements between two maps in constant
1088  * time. (It is only swapping a pointer, an integer, and an
1089  * instance of the @c Compare type (which itself is often
1090  * stateless and empty), so it should be quite fast.) Note
1091  * that the global std::swap() function is specialized such
1092  * that std::swap(m1,m2) will feed to this function.
1093  *
1094  * Whether the allocators are swapped depends on the allocator traits.
1095  */
1096  void
1097  swap(map& __x)
1098  _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
1099  { _M_t.swap(__x._M_t); }
1100 
1101  /**
1102  * Erases all elements in a %map. Note that this function only
1103  * erases the elements, and that if the elements themselves are
1104  * pointers, the pointed-to memory is not touched in any way.
1105  * Managing the pointer is the user's responsibility.
1106  */
1107  void
1108  clear() _GLIBCXX_NOEXCEPT
1109  { _M_t.clear(); }
1110 
1111  // observers
1112  /**
1113  * Returns the key comparison object out of which the %map was
1114  * constructed.
1115  */
1116  key_compare
1117  key_comp() const
1118  { return _M_t.key_comp(); }
1119 
1120  /**
1121  * Returns a value comparison object, built from the key comparison
1122  * object out of which the %map was constructed.
1123  */
1124  value_compare
1125  value_comp() const
1126  { return value_compare(_M_t.key_comp()); }
1127 
1128  // [23.3.1.3] map operations
1129 
1130  //@{
1131  /**
1132  * @brief Tries to locate an element in a %map.
1133  * @param __x Key of (key, value) %pair to be located.
1134  * @return Iterator pointing to sought-after element, or end() if not
1135  * found.
1136  *
1137  * This function takes a key and tries to locate the element with which
1138  * the key matches. If successful the function returns an iterator
1139  * pointing to the sought after %pair. If unsuccessful it returns the
1140  * past-the-end ( @c end() ) iterator.
1141  */
1142 
1143  iterator
1144  find(const key_type& __x)
1145  { return _M_t.find(__x); }
1146 
1147 #if __cplusplus > 201103L
1148  template<typename _Kt>
1149  auto
1150  find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
1151  { return _M_t._M_find_tr(__x); }
1152 #endif
1153  //@}
1154 
1155  //@{
1156  /**
1157  * @brief Tries to locate an element in a %map.
1158  * @param __x Key of (key, value) %pair to be located.
1159  * @return Read-only (constant) iterator pointing to sought-after
1160  * element, or end() if not found.
1161  *
1162  * This function takes a key and tries to locate the element with which
1163  * the key matches. If successful the function returns a constant
1164  * iterator pointing to the sought after %pair. If unsuccessful it
1165  * returns the past-the-end ( @c end() ) iterator.
1166  */
1167 
1168  const_iterator
1169  find(const key_type& __x) const
1170  { return _M_t.find(__x); }
1171 
1172 #if __cplusplus > 201103L
1173  template<typename _Kt>
1174  auto
1175  find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x))
1176  { return _M_t._M_find_tr(__x); }
1177 #endif
1178  //@}
1179 
1180  //@{
1181  /**
1182  * @brief Finds the number of elements with given key.
1183  * @param __x Key of (key, value) pairs to be located.
1184  * @return Number of elements with specified key.
1185  *
1186  * This function only makes sense for multimaps; for map the result will
1187  * either be 0 (not present) or 1 (present).
1188  */
1189  size_type
1190  count(const key_type& __x) const
1191  { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
1192 
1193 #if __cplusplus > 201103L
1194  template<typename _Kt>
1195  auto
1196  count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
1197  { return _M_t._M_find_tr(__x) == _M_t.end() ? 0 : 1; }
1198 #endif
1199  //@}
1200 
1201  //@{
1202  /**
1203  * @brief Finds the beginning of a subsequence matching given key.
1204  * @param __x Key of (key, value) pair to be located.
1205  * @return Iterator pointing to first element equal to or greater
1206  * than key, or end().
1207  *
1208  * This function returns the first element of a subsequence of elements
1209  * that matches the given key. If unsuccessful it returns an iterator
1210  * pointing to the first element that has a greater value than given key
1211  * or end() if no such element exists.
1212  */
1213  iterator
1214  lower_bound(const key_type& __x)
1215  { return _M_t.lower_bound(__x); }
1216 
1217 #if __cplusplus > 201103L
1218  template<typename _Kt>
1219  auto
1220  lower_bound(const _Kt& __x)
1221  -> decltype(_M_t._M_lower_bound_tr(__x))
1222  { return _M_t._M_lower_bound_tr(__x); }
1223 #endif
1224  //@}
1225 
1226  //@{
1227  /**
1228  * @brief Finds the beginning of a subsequence matching given key.
1229  * @param __x Key of (key, value) pair to be located.
1230  * @return Read-only (constant) iterator pointing to first element
1231  * equal to or greater than key, or end().
1232  *
1233  * This function returns the first element of a subsequence of elements
1234  * that matches the given key. If unsuccessful it returns an iterator
1235  * pointing to the first element that has a greater value than given key
1236  * or end() if no such element exists.
1237  */
1238  const_iterator
1239  lower_bound(const key_type& __x) const
1240  { return _M_t.lower_bound(__x); }
1241 
1242 #if __cplusplus > 201103L
1243  template<typename _Kt>
1244  auto
1245  lower_bound(const _Kt& __x) const
1246  -> decltype(_M_t._M_lower_bound_tr(__x))
1247  { return _M_t._M_lower_bound_tr(__x); }
1248 #endif
1249  //@}
1250 
1251  //@{
1252  /**
1253  * @brief Finds the end of a subsequence matching given key.
1254  * @param __x Key of (key, value) pair to be located.
1255  * @return Iterator pointing to the first element
1256  * greater than key, or end().
1257  */
1258  iterator
1259  upper_bound(const key_type& __x)
1260  { return _M_t.upper_bound(__x); }
1261 
1262 #if __cplusplus > 201103L
1263  template<typename _Kt>
1264  auto
1265  upper_bound(const _Kt& __x)
1266  -> decltype(_M_t._M_upper_bound_tr(__x))
1267  { return _M_t._M_upper_bound_tr(__x); }
1268 #endif
1269  //@}
1270 
1271  //@{
1272  /**
1273  * @brief Finds the end of a subsequence matching given key.
1274  * @param __x Key of (key, value) pair to be located.
1275  * @return Read-only (constant) iterator pointing to first iterator
1276  * greater than key, or end().
1277  */
1278  const_iterator
1279  upper_bound(const key_type& __x) const
1280  { return _M_t.upper_bound(__x); }
1281 
1282 #if __cplusplus > 201103L
1283  template<typename _Kt>
1284  auto
1285  upper_bound(const _Kt& __x) const
1286  -> decltype(_M_t._M_upper_bound_tr(__x))
1287  { return _M_t._M_upper_bound_tr(__x); }
1288 #endif
1289  //@}
1290 
1291  //@{
1292  /**
1293  * @brief Finds a subsequence matching given key.
1294  * @param __x Key of (key, value) pairs to be located.
1295  * @return Pair of iterators that possibly points to the subsequence
1296  * matching given key.
1297  *
1298  * This function is equivalent to
1299  * @code
1300  * std::make_pair(c.lower_bound(val),
1301  * c.upper_bound(val))
1302  * @endcode
1303  * (but is faster than making the calls separately).
1304  *
1305  * This function probably only makes sense for multimaps.
1306  */
1308  equal_range(const key_type& __x)
1309  { return _M_t.equal_range(__x); }
1310 
1311 #if __cplusplus > 201103L
1312  template<typename _Kt>
1313  auto
1314  equal_range(const _Kt& __x)
1315  -> decltype(_M_t._M_equal_range_tr(__x))
1316  { return _M_t._M_equal_range_tr(__x); }
1317 #endif
1318  //@}
1319 
1320  //@{
1321  /**
1322  * @brief Finds a subsequence matching given key.
1323  * @param __x Key of (key, value) pairs to be located.
1324  * @return Pair of read-only (constant) iterators that possibly points
1325  * to the subsequence matching given key.
1326  *
1327  * This function is equivalent to
1328  * @code
1329  * std::make_pair(c.lower_bound(val),
1330  * c.upper_bound(val))
1331  * @endcode
1332  * (but is faster than making the calls separately).
1333  *
1334  * This function probably only makes sense for multimaps.
1335  */
1337  equal_range(const key_type& __x) const
1338  { return _M_t.equal_range(__x); }
1339 
1340 #if __cplusplus > 201103L
1341  template<typename _Kt>
1342  auto
1343  equal_range(const _Kt& __x) const
1344  -> decltype(_M_t._M_equal_range_tr(__x))
1345  { return _M_t._M_equal_range_tr(__x); }
1346 #endif
1347  //@}
1348 
1349  template<typename _K1, typename _T1, typename _C1, typename _A1>
1350  friend bool
1352  const map<_K1, _T1, _C1, _A1>&);
1353 
1354  template<typename _K1, typename _T1, typename _C1, typename _A1>
1355  friend bool
1356  operator<(const map<_K1, _T1, _C1, _A1>&,
1357  const map<_K1, _T1, _C1, _A1>&);
1358  };
1359 
1360  /**
1361  * @brief Map equality comparison.
1362  * @param __x A %map.
1363  * @param __y A %map of the same type as @a x.
1364  * @return True iff the size and elements of the maps are equal.
1365  *
1366  * This is an equivalence relation. It is linear in the size of the
1367  * maps. Maps are considered equivalent if their sizes are equal,
1368  * and if corresponding elements compare equal.
1369  */
1370  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1371  inline bool
1374  { return __x._M_t == __y._M_t; }
1375 
1376  /**
1377  * @brief Map ordering relation.
1378  * @param __x A %map.
1379  * @param __y A %map of the same type as @a x.
1380  * @return True iff @a x is lexicographically less than @a y.
1381  *
1382  * This is a total ordering relation. It is linear in the size of the
1383  * maps. The elements must be comparable with @c <.
1384  *
1385  * See std::lexicographical_compare() for how the determination is made.
1386  */
1387  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1388  inline bool
1389  operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
1391  { return __x._M_t < __y._M_t; }
1392 
1393  /// Based on operator==
1394  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1395  inline bool
1398  { return !(__x == __y); }
1399 
1400  /// Based on operator<
1401  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1402  inline bool
1405  { return __y < __x; }
1406 
1407  /// Based on operator<
1408  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1409  inline bool
1410  operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
1412  { return !(__y < __x); }
1413 
1414  /// Based on operator<
1415  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1416  inline bool
1419  { return !(__x < __y); }
1420 
1421  /// See std::map::swap().
1422  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1423  inline void
1426  _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1427  { __x.swap(__y); }
1428 
1429 _GLIBCXX_END_NAMESPACE_CONTAINER
1430 
1431 #if __cplusplus > 201402L
1432 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1433  // Allow std::map access to internals of compatible maps.
1434  template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc,
1435  typename _Cmp2>
1436  struct
1437  _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>,
1438  _Cmp2>
1439  {
1440  private:
1441  friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>;
1442 
1443  static auto&
1444  _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1445  { return __map._M_t; }
1446 
1447  static auto&
1448  _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1449  { return __map._M_t; }
1450  };
1451 _GLIBCXX_END_NAMESPACE_VERSION
1452 #endif // C++17
1453 
1454 } // namespace std
1455 
1456 #endif /* _STL_MAP_H */
auto upper_bound(const _Kt &__x) -> decltype(_M_t._M_upper_bound_tr(__x))
Finds the end of a subsequence matching given key.
Definition: stl_map.h:1265
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
Definition: stl_map.h:99
size_type size() const noexcept
Definition: stl_map.h:461
bool operator!=(const map< _Key, _Tp, _Compare, _Alloc > &__x, const map< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator==.
Definition: stl_map.h:1396
map(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
Definition: stl_map.h:241
iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a map.
Definition: stl_map.h:1063
const_reverse_iterator rend() const noexcept
Definition: stl_map.h:410
iterator end() noexcept
Definition: stl_map.h:365
key_compare key_comp() const
Definition: stl_map.h:1117
void clear() noexcept
Definition: stl_map.h:1108
iterator insert(const_iterator __position, const value_type &__x)
Attempts to insert a std::pair into the map.
Definition: stl_map.h:844
reverse_iterator rbegin() noexcept
Definition: stl_map.h:383
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
Definition: stl_map.h:1308
Uniform interface to C++98 and C++11 allocators.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
Definition: stl_map.h:337
const_reverse_iterator crend() const noexcept
Definition: stl_map.h:447
iterator find(const key_type &__x)
Tries to locate an element in a map.
Definition: stl_map.h:1144
initializer_list
auto upper_bound(const _Kt &__x) const -> decltype(_M_t._M_upper_bound_tr(__x))
Finds the end of a subsequence matching given key.
Definition: stl_map.h:1285
ISO C++ entities toplevel namespace is std.
const_iterator cbegin() const noexcept
Definition: stl_map.h:420
const_iterator end() const noexcept
Definition: stl_map.h:374
void insert(_InputIterator __first, _InputIterator __last)
Template function that attempts to insert a range of elements.
Definition: stl_map.h:870
mapped_type & at(const key_type &__k)
Access to map data.
Definition: stl_map.h:528
bool operator==(const map< _Key, _Tp, _Compare, _Alloc > &__x, const map< _Key, _Tp, _Compare, _Alloc > &__y)
Map equality comparison.
Definition: stl_map.h:1372
auto equal_range(const _Kt &__x) const -> decltype(_M_t._M_equal_range_tr(__x))
Finds a subsequence matching given key.
Definition: stl_map.h:1343
map(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a map with no elements.
Definition: stl_map.h:182
iterator erase(const_iterator __position)
Erases an element from a map.
Definition: stl_map.h:1007
map(const map &__m, const allocator_type &__a)
Allocator-extended copy constructor.
Definition: stl_map.h:231
auto find(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a map.
Definition: stl_map.h:1175
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
Definition: stl_map.h:1259
std::pair< iterator, bool > emplace(_Args &&... __args)
Attempts to build and insert a std::pair into the map.
Definition: stl_map.h:567
auto equal_range(const _Kt &__x) -> decltype(_M_t._M_equal_range_tr(__x))
Finds a subsequence matching given key.
Definition: stl_map.h:1314
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
Definition: stl_map.h:1214
map(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())
Builds a map from an initializer_list.
Definition: stl_map.h:219
auto lower_bound(const _Kt &__x) const -> decltype(_M_t._M_lower_bound_tr(__x))
Finds the beginning of a subsequence matching given key.
Definition: stl_map.h:1245
map()=default
Default constructor creates no elements.
map(_InputIterator __first, _InputIterator __last)
Builds a map from a range.
Definition: stl_map.h:264
map(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
Definition: stl_map.h:247
iterator begin() noexcept
Definition: stl_map.h:347
bool empty() const noexcept
Definition: stl_map.h:456
size_type erase(const key_type &__x)
Erases elements according to the provided key.
Definition: stl_map.h:1043
map & operator=(initializer_list< value_type > __l)
Map list assignment operator.
Definition: stl_map.h:328
auto find(const _Kt &__x) -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a map.
Definition: stl_map.h:1150
constexpr piecewise_construct_t piecewise_construct
piecewise_construct
Definition: stl_pair.h:79
bool operator>(const map< _Key, _Tp, _Compare, _Alloc > &__x, const map< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
Definition: stl_map.h:1403
const_reverse_iterator rbegin() const noexcept
Definition: stl_map.h:392
mapped_type & operator[](const key_type &__k)
Subscript ( [] ) access to map data.
Definition: stl_map.h:483
size_type max_size() const noexcept
Definition: stl_map.h:466
map(const map &__x)
Map copy constructor.
Definition: stl_map.h:193
const_reverse_iterator crbegin() const noexcept
Definition: stl_map.h:438
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
Definition: stl_map.h:71
auto lower_bound(const _Kt &__x) -> decltype(_M_t._M_lower_bound_tr(__x))
Finds the beginning of a subsequence matching given key.
Definition: stl_map.h:1220
Struct holding two objects of arbitrary type.
Definition: stl_pair.h:190
map(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a map from a range.
Definition: stl_map.h:281
void insert(std::initializer_list< value_type > __list)
Attempts to insert a list of std::pairs into the map.
Definition: stl_map.h:815
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given key.
Definition: stl_map.h:1196
reverse_iterator rend() noexcept
Definition: stl_map.h:401
const_iterator begin() const noexcept
Definition: stl_map.h:356
map(map &&__x) noexcept(is_nothrow_copy_constructible< _Compare >::value)
Map move constructor.
Definition: stl_map.h:204
const_iterator upper_bound(const key_type &__x) const
Finds the end of a subsequence matching given key.
Definition: stl_map.h:1279
const_iterator find(const key_type &__x) const
Tries to locate an element in a map.
Definition: stl_map.h:1169
bool operator>=(const map< _Key, _Tp, _Compare, _Alloc > &__x, const map< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
Definition: stl_map.h:1417
const_iterator cend() const noexcept
Definition: stl_map.h:429
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Attempts to build and insert a std::pair into the map.
Definition: stl_map.h:597
map(const allocator_type &__a)
Allocator-extended default constructor.
Definition: stl_map.h:227
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert a std::pair into the map.
Definition: stl_map.h:794
value_compare value_comp() const
Definition: stl_map.h:1125
void swap(map &__x) noexcept(/*conditional */)
Swaps data with another map.
Definition: stl_map.h:1097
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
Definition: stl_map.h:1337
map & operator=(const map &__x)
Map assignment operator.
Definition: stl_map.h:305
map(map &&__m, const allocator_type &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
Definition: stl_map.h:235
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
Definition: stl_map.h:1239
Primary class template, tuple.
Definition: tuple:53
size_type count(const key_type &__x) const
Finds the number of elements with given key.
Definition: stl_map.h:1190
_T1 first
second_type is the second bound type
Definition: stl_pair.h:195