libstdc++
stl_map.h
Go to the documentation of this file.
1 // Map implementation -*- C++ -*-
2 
3 // Copyright (C) 2001-2017 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  *
189  * Whether the allocator is copied depends on the allocator traits.
190  */
191 #if __cplusplus < 201103L
192  map(const map& __x)
193  : _M_t(__x._M_t) { }
194 #else
195  map(const map&) = default;
196 
197  /**
198  * @brief %Map move constructor.
199  *
200  * The newly-created %map contains the exact contents of the moved
201  * instance. The moved instance is a valid, but unspecified, %map.
202  */
203  map(map&&) = default;
204 
205  /**
206  * @brief Builds a %map from an initializer_list.
207  * @param __l An initializer_list.
208  * @param __comp A comparison object.
209  * @param __a An allocator object.
210  *
211  * Create a %map consisting of copies of the elements in the
212  * initializer_list @a __l.
213  * This is linear in N if the range is already sorted, and NlogN
214  * otherwise (where N is @a __l.size()).
215  */
217  const _Compare& __comp = _Compare(),
218  const allocator_type& __a = allocator_type())
219  : _M_t(__comp, _Pair_alloc_type(__a))
220  { _M_t._M_insert_unique(__l.begin(), __l.end()); }
221 
222  /// Allocator-extended default constructor.
223  explicit
224  map(const allocator_type& __a)
225  : _M_t(_Compare(), _Pair_alloc_type(__a)) { }
226 
227  /// Allocator-extended copy constructor.
228  map(const map& __m, const allocator_type& __a)
229  : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
230 
231  /// Allocator-extended move constructor.
232  map(map&& __m, const allocator_type& __a)
233  noexcept(is_nothrow_copy_constructible<_Compare>::value
234  && _Alloc_traits::_S_always_equal())
235  : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { }
236 
237  /// Allocator-extended initialier-list constructor.
238  map(initializer_list<value_type> __l, const allocator_type& __a)
239  : _M_t(_Compare(), _Pair_alloc_type(__a))
240  { _M_t._M_insert_unique(__l.begin(), __l.end()); }
241 
242  /// Allocator-extended range constructor.
243  template<typename _InputIterator>
244  map(_InputIterator __first, _InputIterator __last,
245  const allocator_type& __a)
246  : _M_t(_Compare(), _Pair_alloc_type(__a))
247  { _M_t._M_insert_unique(__first, __last); }
248 #endif
249 
250  /**
251  * @brief Builds a %map from a range.
252  * @param __first An input iterator.
253  * @param __last An input iterator.
254  *
255  * Create a %map consisting of copies of the elements from
256  * [__first,__last). This is linear in N if the range is
257  * already sorted, and NlogN otherwise (where N is
258  * distance(__first,__last)).
259  */
260  template<typename _InputIterator>
261  map(_InputIterator __first, _InputIterator __last)
262  : _M_t()
263  { _M_t._M_insert_unique(__first, __last); }
264 
265  /**
266  * @brief Builds a %map from a range.
267  * @param __first An input iterator.
268  * @param __last An input iterator.
269  * @param __comp A comparison functor.
270  * @param __a An allocator object.
271  *
272  * Create a %map consisting of copies of the elements from
273  * [__first,__last). This is linear in N if the range is
274  * already sorted, and NlogN otherwise (where N is
275  * distance(__first,__last)).
276  */
277  template<typename _InputIterator>
278  map(_InputIterator __first, _InputIterator __last,
279  const _Compare& __comp,
280  const allocator_type& __a = allocator_type())
281  : _M_t(__comp, _Pair_alloc_type(__a))
282  { _M_t._M_insert_unique(__first, __last); }
283 
284 #if __cplusplus >= 201103L
285  /**
286  * The dtor only erases the elements, and note that if the elements
287  * themselves are pointers, the pointed-to memory is not touched in any
288  * way. Managing the pointer is the user's responsibility.
289  */
290  ~map() = default;
291 #endif
292 
293  /**
294  * @brief %Map assignment operator.
295  *
296  * Whether the allocator is copied depends on the allocator traits.
297  */
298 #if __cplusplus < 201103L
299  map&
300  operator=(const map& __x)
301  {
302  _M_t = __x._M_t;
303  return *this;
304  }
305 #else
306  map&
307  operator=(const map&) = default;
308 
309  /// Move assignment operator.
310  map&
311  operator=(map&&) = default;
312 
313  /**
314  * @brief %Map list assignment operator.
315  * @param __l An initializer_list.
316  *
317  * This function fills a %map with copies of the elements in the
318  * initializer list @a __l.
319  *
320  * Note that the assignment completely changes the %map and
321  * that the resulting %map's size is the same as the number
322  * of elements assigned.
323  */
324  map&
326  {
327  _M_t._M_assign_unique(__l.begin(), __l.end());
328  return *this;
329  }
330 #endif
331 
332  /// Get a copy of the memory allocation object.
333  allocator_type
334  get_allocator() const _GLIBCXX_NOEXCEPT
335  { return allocator_type(_M_t.get_allocator()); }
336 
337  // iterators
338  /**
339  * Returns a read/write iterator that points to the first pair in the
340  * %map.
341  * Iteration is done in ascending order according to the keys.
342  */
343  iterator
344  begin() _GLIBCXX_NOEXCEPT
345  { return _M_t.begin(); }
346 
347  /**
348  * Returns a read-only (constant) iterator that points to the first pair
349  * in the %map. Iteration is done in ascending order according to the
350  * keys.
351  */
352  const_iterator
353  begin() const _GLIBCXX_NOEXCEPT
354  { return _M_t.begin(); }
355 
356  /**
357  * Returns a read/write iterator that points one past the last
358  * pair in the %map. Iteration is done in ascending order
359  * according to the keys.
360  */
361  iterator
362  end() _GLIBCXX_NOEXCEPT
363  { return _M_t.end(); }
364 
365  /**
366  * Returns a read-only (constant) iterator that points one past the last
367  * pair in the %map. Iteration is done in ascending order according to
368  * the keys.
369  */
370  const_iterator
371  end() const _GLIBCXX_NOEXCEPT
372  { return _M_t.end(); }
373 
374  /**
375  * Returns a read/write reverse iterator that points to the last pair in
376  * the %map. Iteration is done in descending order according to the
377  * keys.
378  */
379  reverse_iterator
380  rbegin() _GLIBCXX_NOEXCEPT
381  { return _M_t.rbegin(); }
382 
383  /**
384  * Returns a read-only (constant) reverse iterator that points to the
385  * last pair in the %map. Iteration is done in descending order
386  * according to the keys.
387  */
388  const_reverse_iterator
389  rbegin() const _GLIBCXX_NOEXCEPT
390  { return _M_t.rbegin(); }
391 
392  /**
393  * Returns a read/write reverse iterator that points to one before the
394  * first pair in the %map. Iteration is done in descending order
395  * according to the keys.
396  */
397  reverse_iterator
398  rend() _GLIBCXX_NOEXCEPT
399  { return _M_t.rend(); }
400 
401  /**
402  * Returns a read-only (constant) reverse iterator that points to one
403  * before the first pair in the %map. Iteration is done in descending
404  * order according to the keys.
405  */
406  const_reverse_iterator
407  rend() const _GLIBCXX_NOEXCEPT
408  { return _M_t.rend(); }
409 
410 #if __cplusplus >= 201103L
411  /**
412  * Returns a read-only (constant) iterator that points to the first pair
413  * in the %map. Iteration is done in ascending order according to the
414  * keys.
415  */
416  const_iterator
417  cbegin() const noexcept
418  { return _M_t.begin(); }
419 
420  /**
421  * Returns a read-only (constant) iterator that points one past the last
422  * pair in the %map. Iteration is done in ascending order according to
423  * the keys.
424  */
425  const_iterator
426  cend() const noexcept
427  { return _M_t.end(); }
428 
429  /**
430  * Returns a read-only (constant) reverse iterator that points to the
431  * last pair in the %map. Iteration is done in descending order
432  * according to the keys.
433  */
434  const_reverse_iterator
435  crbegin() const noexcept
436  { return _M_t.rbegin(); }
437 
438  /**
439  * Returns a read-only (constant) reverse iterator that points to one
440  * before the first pair in the %map. Iteration is done in descending
441  * order according to the keys.
442  */
443  const_reverse_iterator
444  crend() const noexcept
445  { return _M_t.rend(); }
446 #endif
447 
448  // capacity
449  /** Returns true if the %map is empty. (Thus begin() would equal
450  * end().)
451  */
452  bool
453  empty() const _GLIBCXX_NOEXCEPT
454  { return _M_t.empty(); }
455 
456  /** Returns the size of the %map. */
457  size_type
458  size() const _GLIBCXX_NOEXCEPT
459  { return _M_t.size(); }
460 
461  /** Returns the maximum size of the %map. */
462  size_type
463  max_size() const _GLIBCXX_NOEXCEPT
464  { return _M_t.max_size(); }
465 
466  // [23.3.1.2] element access
467  /**
468  * @brief Subscript ( @c [] ) access to %map data.
469  * @param __k The key for which data should be retrieved.
470  * @return A reference to the data of the (key,data) %pair.
471  *
472  * Allows for easy lookup with the subscript ( @c [] )
473  * operator. Returns data associated with the key specified in
474  * subscript. If the key does not exist, a pair with that key
475  * is created using default values, which is then returned.
476  *
477  * Lookup requires logarithmic time.
478  */
479  mapped_type&
480  operator[](const key_type& __k)
481  {
482  // concept requirements
483  __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
484 
485  iterator __i = lower_bound(__k);
486  // __i->first is greater than or equivalent to __k.
487  if (__i == end() || key_comp()(__k, (*__i).first))
488 #if __cplusplus >= 201103L
489  __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
491  std::tuple<>());
492 #else
493  __i = insert(__i, value_type(__k, mapped_type()));
494 #endif
495  return (*__i).second;
496  }
497 
498 #if __cplusplus >= 201103L
499  mapped_type&
500  operator[](key_type&& __k)
501  {
502  // concept requirements
503  __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
504 
505  iterator __i = lower_bound(__k);
506  // __i->first is greater than or equivalent to __k.
507  if (__i == end() || key_comp()(__k, (*__i).first))
508  __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
509  std::forward_as_tuple(std::move(__k)),
510  std::tuple<>());
511  return (*__i).second;
512  }
513 #endif
514 
515  // _GLIBCXX_RESOLVE_LIB_DEFECTS
516  // DR 464. Suggestion for new member functions in standard containers.
517  /**
518  * @brief Access to %map data.
519  * @param __k The key for which data should be retrieved.
520  * @return A reference to the data whose key is equivalent to @a __k, if
521  * such a data is present in the %map.
522  * @throw std::out_of_range If no such data is present.
523  */
524  mapped_type&
525  at(const key_type& __k)
526  {
527  iterator __i = lower_bound(__k);
528  if (__i == end() || key_comp()(__k, (*__i).first))
529  __throw_out_of_range(__N("map::at"));
530  return (*__i).second;
531  }
532 
533  const mapped_type&
534  at(const key_type& __k) const
535  {
536  const_iterator __i = lower_bound(__k);
537  if (__i == end() || key_comp()(__k, (*__i).first))
538  __throw_out_of_range(__N("map::at"));
539  return (*__i).second;
540  }
541 
542  // modifiers
543 #if __cplusplus >= 201103L
544  /**
545  * @brief Attempts to build and insert a std::pair into the %map.
546  *
547  * @param __args Arguments used to generate a new pair instance (see
548  * std::piecewise_contruct for passing arguments to each
549  * part of the pair constructor).
550  *
551  * @return A pair, of which the first element is an iterator that points
552  * to the possibly inserted pair, and the second is a bool that
553  * is true if the pair was actually inserted.
554  *
555  * This function attempts to build and insert a (key, value) %pair into
556  * the %map.
557  * A %map relies on unique keys and thus a %pair is only inserted if its
558  * first element (the key) is not already present in the %map.
559  *
560  * Insertion requires logarithmic time.
561  */
562  template<typename... _Args>
564  emplace(_Args&&... __args)
565  { return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
566 
567  /**
568  * @brief Attempts to build and insert a std::pair into the %map.
569  *
570  * @param __pos An iterator that serves as a hint as to where the pair
571  * should be inserted.
572  * @param __args Arguments used to generate a new pair instance (see
573  * std::piecewise_contruct for passing arguments to each
574  * part of the pair constructor).
575  * @return An iterator that points to the element with key of the
576  * std::pair built from @a __args (may or may not be that
577  * std::pair).
578  *
579  * This function is not concerned about whether the insertion took place,
580  * and thus does not return a boolean like the single-argument emplace()
581  * does.
582  * Note that the first parameter is only a hint and can potentially
583  * improve the performance of the insertion process. A bad hint would
584  * cause no gains in efficiency.
585  *
586  * See
587  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
588  * for more on @a hinting.
589  *
590  * Insertion requires logarithmic time (if the hint is not taken).
591  */
592  template<typename... _Args>
593  iterator
594  emplace_hint(const_iterator __pos, _Args&&... __args)
595  {
596  return _M_t._M_emplace_hint_unique(__pos,
597  std::forward<_Args>(__args)...);
598  }
599 #endif
600 
601 #if __cplusplus > 201402L
602  /// Extract a node.
603  node_type
604  extract(const_iterator __pos)
605  {
606  __glibcxx_assert(__pos != end());
607  return _M_t.extract(__pos);
608  }
609 
610  /// Extract a node.
611  node_type
612  extract(const key_type& __x)
613  { return _M_t.extract(__x); }
614 
615  /// Re-insert an extracted node.
616  insert_return_type
617  insert(node_type&& __nh)
618  { return _M_t._M_reinsert_node_unique(std::move(__nh)); }
619 
620  /// Re-insert an extracted node.
621  iterator
622  insert(const_iterator __hint, node_type&& __nh)
623  { return _M_t._M_reinsert_node_hint_unique(__hint, std::move(__nh)); }
624 
625  template<typename, typename>
626  friend class _Rb_tree_merge_helper;
627 
628  template<typename _C2>
629  void
630  merge(map<_Key, _Tp, _C2, _Alloc>& __source)
631  {
632  using _Merge_helper = _Rb_tree_merge_helper<map, _C2>;
633  _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
634  }
635 
636  template<typename _C2>
637  void
638  merge(map<_Key, _Tp, _C2, _Alloc>&& __source)
639  { merge(__source); }
640 
641  template<typename _C2>
642  void
643  merge(multimap<_Key, _Tp, _C2, _Alloc>& __source)
644  {
645  using _Merge_helper = _Rb_tree_merge_helper<map, _C2>;
646  _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
647  }
648 
649  template<typename _C2>
650  void
651  merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source)
652  { merge(__source); }
653 #endif // C++17
654 
655 #if __cplusplus > 201402L
656 #define __cpp_lib_map_try_emplace 201411
657  /**
658  * @brief Attempts to build and insert a std::pair into the %map.
659  *
660  * @param __k Key to use for finding a possibly existing pair in
661  * the map.
662  * @param __args Arguments used to generate the .second for a new pair
663  * instance.
664  *
665  * @return A pair, of which the first element is an iterator that points
666  * to the possibly inserted pair, and the second is a bool that
667  * is true if the pair was actually inserted.
668  *
669  * This function attempts to build and insert a (key, value) %pair into
670  * the %map.
671  * A %map relies on unique keys and thus a %pair is only inserted if its
672  * first element (the key) is not already present in the %map.
673  * If a %pair is not inserted, this function has no effect.
674  *
675  * Insertion requires logarithmic time.
676  */
677  template <typename... _Args>
679  try_emplace(const key_type& __k, _Args&&... __args)
680  {
681  iterator __i = lower_bound(__k);
682  if (__i == end() || key_comp()(__k, (*__i).first))
683  {
685  std::forward_as_tuple(__k),
686  std::forward_as_tuple(
687  std::forward<_Args>(__args)...));
688  return {__i, true};
689  }
690  return {__i, false};
691  }
692 
693  // move-capable overload
694  template <typename... _Args>
696  try_emplace(key_type&& __k, _Args&&... __args)
697  {
698  iterator __i = lower_bound(__k);
699  if (__i == end() || key_comp()(__k, (*__i).first))
700  {
702  std::forward_as_tuple(std::move(__k)),
703  std::forward_as_tuple(
704  std::forward<_Args>(__args)...));
705  return {__i, true};
706  }
707  return {__i, false};
708  }
709 
710  /**
711  * @brief Attempts to build and insert a std::pair into the %map.
712  *
713  * @param __hint An iterator that serves as a hint as to where the
714  * pair should be inserted.
715  * @param __k Key to use for finding a possibly existing pair in
716  * the map.
717  * @param __args Arguments used to generate the .second for a new pair
718  * instance.
719  * @return An iterator that points to the element with key of the
720  * std::pair built from @a __args (may or may not be that
721  * std::pair).
722  *
723  * This function is not concerned about whether the insertion took place,
724  * and thus does not return a boolean like the single-argument
725  * try_emplace() does. However, if insertion did not take place,
726  * this function has no effect.
727  * Note that the first parameter is only a hint and can potentially
728  * improve the performance of the insertion process. A bad hint would
729  * cause no gains in efficiency.
730  *
731  * See
732  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
733  * for more on @a hinting.
734  *
735  * Insertion requires logarithmic time (if the hint is not taken).
736  */
737  template <typename... _Args>
738  iterator
739  try_emplace(const_iterator __hint, const key_type& __k,
740  _Args&&... __args)
741  {
742  iterator __i;
743  auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
744  if (__true_hint.second)
745  __i = emplace_hint(iterator(__true_hint.second),
747  std::forward_as_tuple(__k),
748  std::forward_as_tuple(
749  std::forward<_Args>(__args)...));
750  else
751  __i = iterator(__true_hint.first);
752  return __i;
753  }
754 
755  // move-capable overload
756  template <typename... _Args>
757  iterator
758  try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
759  {
760  iterator __i;
761  auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
762  if (__true_hint.second)
763  __i = emplace_hint(iterator(__true_hint.second),
765  std::forward_as_tuple(std::move(__k)),
766  std::forward_as_tuple(
767  std::forward<_Args>(__args)...));
768  else
769  __i = iterator(__true_hint.first);
770  return __i;
771  }
772 #endif
773 
774  /**
775  * @brief Attempts to insert a std::pair into the %map.
776 
777  * @param __x Pair to be inserted (see std::make_pair for easy
778  * creation of pairs).
779  *
780  * @return A pair, of which the first element is an iterator that
781  * points to the possibly inserted pair, and the second is
782  * a bool that is true if the pair was actually inserted.
783  *
784  * This function attempts to insert a (key, value) %pair into the %map.
785  * A %map relies on unique keys and thus a %pair is only inserted if its
786  * first element (the key) is not already present in the %map.
787  *
788  * Insertion requires logarithmic time.
789  */
791  insert(const value_type& __x)
792  { return _M_t._M_insert_unique(__x); }
793 
794 #if __cplusplus >= 201103L
795  template<typename _Pair, typename = typename
796  std::enable_if<std::is_constructible<value_type,
797  _Pair&&>::value>::type>
799  insert(_Pair&& __x)
800  { return _M_t._M_insert_unique(std::forward<_Pair>(__x)); }
801 #endif
802 
803 #if __cplusplus >= 201103L
804  /**
805  * @brief Attempts to insert a list of std::pairs into the %map.
806  * @param __list A std::initializer_list<value_type> of pairs to be
807  * inserted.
808  *
809  * Complexity similar to that of the range constructor.
810  */
811  void
813  { insert(__list.begin(), __list.end()); }
814 #endif
815 
816  /**
817  * @brief Attempts to insert a std::pair into the %map.
818  * @param __position An iterator that serves as a hint as to where the
819  * pair should be inserted.
820  * @param __x Pair to be inserted (see std::make_pair for easy creation
821  * of pairs).
822  * @return An iterator that points to the element with key of
823  * @a __x (may or may not be the %pair passed in).
824  *
825 
826  * This function is not concerned about whether the insertion
827  * took place, and thus does not return a boolean like the
828  * single-argument insert() does. Note that the first
829  * parameter is only a hint and can potentially improve the
830  * performance of the insertion process. A bad hint would
831  * cause no gains in efficiency.
832  *
833  * See
834  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
835  * for more on @a hinting.
836  *
837  * Insertion requires logarithmic time (if the hint is not taken).
838  */
839  iterator
840 #if __cplusplus >= 201103L
841  insert(const_iterator __position, const value_type& __x)
842 #else
843  insert(iterator __position, const value_type& __x)
844 #endif
845  { return _M_t._M_insert_unique_(__position, __x); }
846 
847 #if __cplusplus >= 201103L
848  template<typename _Pair, typename = typename
849  std::enable_if<std::is_constructible<value_type,
850  _Pair&&>::value>::type>
851  iterator
852  insert(const_iterator __position, _Pair&& __x)
853  { return _M_t._M_insert_unique_(__position,
854  std::forward<_Pair>(__x)); }
855 #endif
856 
857  /**
858  * @brief Template function that attempts to insert a range of elements.
859  * @param __first Iterator pointing to the start of the range to be
860  * inserted.
861  * @param __last Iterator pointing to the end of the range.
862  *
863  * Complexity similar to that of the range constructor.
864  */
865  template<typename _InputIterator>
866  void
867  insert(_InputIterator __first, _InputIterator __last)
868  { _M_t._M_insert_unique(__first, __last); }
869 
870 #if __cplusplus > 201402L
871 #define __cpp_lib_map_insertion 201411
872  /**
873  * @brief Attempts to insert or assign a std::pair into the %map.
874  * @param __k Key to use for finding a possibly existing pair in
875  * the map.
876  * @param __obj Argument used to generate the .second for a pair
877  * instance.
878  *
879  * @return A pair, of which the first element is an iterator that
880  * points to the possibly inserted pair, and the second is
881  * a bool that is true if the pair was actually inserted.
882  *
883  * This function attempts to insert a (key, value) %pair into the %map.
884  * A %map relies on unique keys and thus a %pair is only inserted if its
885  * first element (the key) is not already present in the %map.
886  * If the %pair was already in the %map, the .second of the %pair
887  * is assigned from __obj.
888  *
889  * Insertion requires logarithmic time.
890  */
891  template <typename _Obj>
893  insert_or_assign(const key_type& __k, _Obj&& __obj)
894  {
895  iterator __i = lower_bound(__k);
896  if (__i == end() || key_comp()(__k, (*__i).first))
897  {
899  std::forward_as_tuple(__k),
900  std::forward_as_tuple(
901  std::forward<_Obj>(__obj)));
902  return {__i, true};
903  }
904  (*__i).second = std::forward<_Obj>(__obj);
905  return {__i, false};
906  }
907 
908  // move-capable overload
909  template <typename _Obj>
911  insert_or_assign(key_type&& __k, _Obj&& __obj)
912  {
913  iterator __i = lower_bound(__k);
914  if (__i == end() || key_comp()(__k, (*__i).first))
915  {
917  std::forward_as_tuple(std::move(__k)),
918  std::forward_as_tuple(
919  std::forward<_Obj>(__obj)));
920  return {__i, true};
921  }
922  (*__i).second = std::forward<_Obj>(__obj);
923  return {__i, false};
924  }
925 
926  /**
927  * @brief Attempts to insert or assign a std::pair into the %map.
928  * @param __hint An iterator that serves as a hint as to where the
929  * pair should be inserted.
930  * @param __k Key to use for finding a possibly existing pair in
931  * the map.
932  * @param __obj Argument used to generate the .second for a pair
933  * instance.
934  *
935  * @return An iterator that points to the element with key of
936  * @a __x (may or may not be the %pair passed in).
937  *
938  * This function attempts to insert a (key, value) %pair into the %map.
939  * A %map relies on unique keys and thus a %pair is only inserted if its
940  * first element (the key) is not already present in the %map.
941  * If the %pair was already in the %map, the .second of the %pair
942  * is assigned from __obj.
943  *
944  * Insertion requires logarithmic time.
945  */
946  template <typename _Obj>
947  iterator
948  insert_or_assign(const_iterator __hint,
949  const key_type& __k, _Obj&& __obj)
950  {
951  iterator __i;
952  auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
953  if (__true_hint.second)
954  {
955  return emplace_hint(iterator(__true_hint.second),
957  std::forward_as_tuple(__k),
958  std::forward_as_tuple(
959  std::forward<_Obj>(__obj)));
960  }
961  __i = iterator(__true_hint.first);
962  (*__i).second = std::forward<_Obj>(__obj);
963  return __i;
964  }
965 
966  // move-capable overload
967  template <typename _Obj>
968  iterator
969  insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
970  {
971  iterator __i;
972  auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
973  if (__true_hint.second)
974  {
975  return emplace_hint(iterator(__true_hint.second),
977  std::forward_as_tuple(std::move(__k)),
978  std::forward_as_tuple(
979  std::forward<_Obj>(__obj)));
980  }
981  __i = iterator(__true_hint.first);
982  (*__i).second = std::forward<_Obj>(__obj);
983  return __i;
984  }
985 #endif
986 
987 #if __cplusplus >= 201103L
988  // _GLIBCXX_RESOLVE_LIB_DEFECTS
989  // DR 130. Associative erase should return an iterator.
990  /**
991  * @brief Erases an element from a %map.
992  * @param __position An iterator pointing to the element to be erased.
993  * @return An iterator pointing to the element immediately following
994  * @a position prior to the element being erased. If no such
995  * element exists, end() is returned.
996  *
997  * This function erases an element, pointed to by the given
998  * iterator, from a %map. Note that this function only erases
999  * the element, and that if the element is itself a pointer,
1000  * the pointed-to memory is not touched in any way. Managing
1001  * the pointer is the user's responsibility.
1002  *
1003  * @{
1004  */
1005  iterator
1006  erase(const_iterator __position)
1007  { return _M_t.erase(__position); }
1008 
1009  // LWG 2059
1010  _GLIBCXX_ABI_TAG_CXX11
1011  iterator
1012  erase(iterator __position)
1013  { return _M_t.erase(__position); }
1014  // @}
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_count_tr(__x); }
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(iterator(_M_t._M_lower_bound_tr(__x)))
1222  { return iterator(_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(const_iterator(_M_t._M_lower_bound_tr(__x)))
1247  { return const_iterator(_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(iterator(_M_t._M_upper_bound_tr(__x)))
1267  { return iterator(_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(const_iterator(_M_t._M_upper_bound_tr(__x)))
1287  { return const_iterator(_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(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
1316  { return pair<iterator, iterator>(_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
1345  _M_t._M_equal_range_tr(__x)))
1346  {
1348  _M_t._M_equal_range_tr(__x));
1349  }
1350 #endif
1351  //@}
1352 
1353  template<typename _K1, typename _T1, typename _C1, typename _A1>
1354  friend bool
1356  const map<_K1, _T1, _C1, _A1>&);
1357 
1358  template<typename _K1, typename _T1, typename _C1, typename _A1>
1359  friend bool
1360  operator<(const map<_K1, _T1, _C1, _A1>&,
1361  const map<_K1, _T1, _C1, _A1>&);
1362  };
1363 
1364  /**
1365  * @brief Map equality comparison.
1366  * @param __x A %map.
1367  * @param __y A %map of the same type as @a x.
1368  * @return True iff the size and elements of the maps are equal.
1369  *
1370  * This is an equivalence relation. It is linear in the size of the
1371  * maps. Maps are considered equivalent if their sizes are equal,
1372  * and if corresponding elements compare equal.
1373  */
1374  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1375  inline bool
1378  { return __x._M_t == __y._M_t; }
1379 
1380  /**
1381  * @brief Map ordering relation.
1382  * @param __x A %map.
1383  * @param __y A %map of the same type as @a x.
1384  * @return True iff @a x is lexicographically less than @a y.
1385  *
1386  * This is a total ordering relation. It is linear in the size of the
1387  * maps. The elements must be comparable with @c <.
1388  *
1389  * See std::lexicographical_compare() for how the determination is made.
1390  */
1391  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1392  inline bool
1393  operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
1395  { return __x._M_t < __y._M_t; }
1396 
1397  /// Based on operator==
1398  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1399  inline bool
1402  { return !(__x == __y); }
1403 
1404  /// Based on operator<
1405  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1406  inline bool
1409  { return __y < __x; }
1410 
1411  /// Based on operator<
1412  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1413  inline bool
1414  operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
1416  { return !(__y < __x); }
1417 
1418  /// Based on operator<
1419  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1420  inline bool
1423  { return !(__x < __y); }
1424 
1425  /// See std::map::swap().
1426  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1427  inline void
1430  _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1431  { __x.swap(__y); }
1432 
1433 _GLIBCXX_END_NAMESPACE_CONTAINER
1434 
1435 #if __cplusplus > 201402L
1436 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1437  // Allow std::map access to internals of compatible maps.
1438  template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc,
1439  typename _Cmp2>
1440  struct
1441  _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>,
1442  _Cmp2>
1443  {
1444  private:
1445  friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>;
1446 
1447  static auto&
1448  _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1449  { return __map._M_t; }
1450 
1451  static auto&
1452  _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1453  { return __map._M_t; }
1454  };
1455 _GLIBCXX_END_NAMESPACE_VERSION
1456 #endif // C++17
1457 
1458 } // namespace std
1459 
1460 #endif /* _STL_MAP_H */
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
const_reverse_iterator crbegin() const noexcept
Definition: stl_map.h:435
size_type erase(const key_type &__x)
Erases elements according to the provided key.
Definition: stl_map.h:1043
bool operator!=(const map< _Key, _Tp, _Compare, _Alloc > &__x, const map< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator==.
Definition: stl_map.h:1400
const_iterator cbegin() const noexcept
Definition: stl_map.h:417
Primary class template, tuple.
Definition: tuple:53
size_type size() const noexcept
Definition: stl_map.h:458
map(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a map from a range.
Definition: stl_map.h:278
size_type max_size() const noexcept
Definition: stl_map.h:463
reverse_iterator rbegin() noexcept
Definition: stl_map.h:380
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:232
void insert(std::initializer_list< value_type > __list)
Attempts to insert a list of std::pairs into the map.
Definition: stl_map.h:812
iterator end() noexcept
Definition: stl_map.h:362
auto upper_bound(const _Kt &__x) const -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
Finds the end of a subsequence matching given key.
Definition: stl_map.h:1285
map()=default
Default constructor creates no elements.
map & operator=(const map &)=default
Map assignment operator.
initializer_list
value_compare value_comp() const
Definition: stl_map.h:1125
map(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
Definition: stl_map.h:238
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Attempts to build and insert a std::pair into the map.
Definition: stl_map.h:594
map & operator=(initializer_list< value_type > __l)
Map list assignment operator.
Definition: stl_map.h:325
iterator erase(const_iterator __position)
Erases an element from a map.
Definition: stl_map.h:1006
ISO C++ entities toplevel namespace is std.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
Definition: stl_map.h:1337
auto lower_bound(const _Kt &__x) -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
Definition: stl_map.h:1220
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
const_reverse_iterator rend() const noexcept
Definition: stl_map.h:407
bool operator==(const map< _Key, _Tp, _Compare, _Alloc > &__x, const map< _Key, _Tp, _Compare, _Alloc > &__y)
Map equality comparison.
Definition: stl_map.h:1376
size_type count(const key_type &__x) const
Finds the number of elements with given key.
Definition: stl_map.h:1190
reverse_iterator rend() noexcept
Definition: stl_map.h:398
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
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
Definition: stl_map.h:71
bool empty() const noexcept
Definition: stl_map.h:453
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:841
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
Definition: stl_map.h:1239
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 cend() const noexcept
Definition: stl_map.h:426
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:216
const_reverse_iterator crend() const noexcept
Definition: stl_map.h:444
_GLIBCXX_ABI_TAG_CXX11 iterator erase(iterator __position)
Erases an element from a map.
Definition: stl_map.h:1012
const_iterator begin() const noexcept
Definition: stl_map.h:353
void swap(map &__x) noexcept(/*conditional */)
Swaps data with another map.
Definition: stl_map.h:1097
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
Definition: stl_map.h:1214
constexpr piecewise_construct_t piecewise_construct
piecewise_construct
Definition: stl_pair.h:79
map(const map &__m, const allocator_type &__a)
Allocator-extended copy constructor.
Definition: stl_map.h:228
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
Definition: stl_map.h:1259
bool operator>(const map< _Key, _Tp, _Compare, _Alloc > &__x, const map< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
Definition: stl_map.h:1407
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert a std::pair into the map.
Definition: stl_map.h:791
key_compare key_comp() const
Definition: stl_map.h:1117
map(const allocator_type &__a)
Allocator-extended default constructor.
Definition: stl_map.h:224
void insert(_InputIterator __first, _InputIterator __last)
Template function that attempts to insert a range of elements.
Definition: stl_map.h:867
std::pair< iterator, bool > emplace(_Args &&... __args)
Attempts to build and insert a std::pair into the map.
Definition: stl_map.h:564
map(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
Definition: stl_map.h:244
auto equal_range(const _Kt &__x) -> decltype(pair< iterator, iterator >(_M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
Definition: stl_map.h:1314
bool operator>=(const map< _Key, _Tp, _Compare, _Alloc > &__x, const map< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
Definition: stl_map.h:1421
iterator begin() noexcept
Definition: stl_map.h:344
_T1 first
second_type is the second bound type
Definition: stl_pair.h:195
iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a map.
Definition: stl_map.h:1063
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
Definition: stl_map.h:99
~map()=default
map(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a map with no elements.
Definition: stl_map.h:182
auto upper_bound(const _Kt &__x) -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
Finds the end of a subsequence matching given key.
Definition: stl_map.h:1265
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
Definition: stl_map.h:334
mapped_type & at(const key_type &__k)
Access to map data.
Definition: stl_map.h:525
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
Definition: stl_map.h:1308
Struct holding two objects of arbitrary type.
Definition: stl_pair.h:190
map(_InputIterator __first, _InputIterator __last)
Builds a map from a range.
Definition: stl_map.h:261
auto equal_range(const _Kt &__x) const -> decltype(pair< const_iterator, const_iterator >(_M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
Definition: stl_map.h:1343
const_reverse_iterator rbegin() const noexcept
Definition: stl_map.h:389
const_iterator end() const noexcept
Definition: stl_map.h:371
auto lower_bound(const _Kt &__x) const -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
Definition: stl_map.h:1245
Uniform interface to C++98 and C++11 allocators.
const_iterator find(const key_type &__x) const
Tries to locate an element in a map.
Definition: stl_map.h:1169
iterator find(const key_type &__x)
Tries to locate an element in a map.
Definition: stl_map.h:1144
mapped_type & operator[](const key_type &__k)
Subscript ( [] ) access to map data.
Definition: stl_map.h:480