blob: 561c3ddc93dd5a9993a506777bd9fce1ca22b2de [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===----------------------------- map ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MAP
12#define _LIBCPP_MAP
13
14/*
15
16 map synopsis
17
18namespace std
19{
20
21template <class Key, class T, class Compare = less<Key>,
22 class Allocator = allocator<pair<const Key, T>>>
23class map
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef T mapped_type;
29 typedef pair<const key_type, mapped_type> value_type;
30 typedef Compare key_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::pointer pointer;
35 typedef typename allocator_type::const_pointer const_pointer;
36 typedef typename allocator_type::size_type size_type;
37 typedef typename allocator_type::difference_type difference_type;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
43
44 class value_compare
45 : public binary_function<value_type, value_type, bool>
46 {
47 friend class map;
48 protected:
49 key_compare comp;
50
51 value_compare(key_compare c);
52 public:
53 bool operator()(const value_type& x, const value_type& y) const;
54 };
55
56 // construct/copy/destroy:
Howard Hinnant7686add2011-06-04 14:31:5757 map()
58 noexcept(
59 is_nothrow_default_constructible<allocator_type>::value &&
60 is_nothrow_default_constructible<key_compare>::value &&
61 is_nothrow_copy_constructible<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1662 explicit map(const key_compare& comp);
63 map(const key_compare& comp, const allocator_type& a);
64 template <class InputIterator>
65 map(InputIterator first, InputIterator last,
66 const key_compare& comp = key_compare());
67 template <class InputIterator>
68 map(InputIterator first, InputIterator last,
69 const key_compare& comp, const allocator_type& a);
70 map(const map& m);
Howard Hinnant7686add2011-06-04 14:31:5771 map(map&& m)
72 noexcept(
73 is_nothrow_move_constructible<allocator_type>::value &&
74 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1675 explicit map(const allocator_type& a);
76 map(const map& m, const allocator_type& a);
77 map(map&& m, const allocator_type& a);
78 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
79 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
Marshall Clow49d596d2013-09-11 01:15:4780 template <class InputIterator>
81 map(InputIterator first, InputIterator last, const allocator_type& a)
82 : map(first, last, Compare(), a) {} // C++14
83 map(initializer_list<value_type> il, const allocator_type& a)
84 : map(il, Compare(), a) {} // C++14
85 ~map();
Howard Hinnantbc8d3f92010-05-11 19:42:1686
87 map& operator=(const map& m);
Howard Hinnant7686add2011-06-04 14:31:5788 map& operator=(map&& m)
89 noexcept(
90 allocator_type::propagate_on_container_move_assignment::value &&
91 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantb2e2a8f2011-06-04 15:22:3492 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1693 map& operator=(initializer_list<value_type> il);
94
95 // iterators:
Howard Hinnantb2e2a8f2011-06-04 15:22:3496 iterator begin() noexcept;
97 const_iterator begin() const noexcept;
98 iterator end() noexcept;
99 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16100
Howard Hinnantb2e2a8f2011-06-04 15:22:34101 reverse_iterator rbegin() noexcept;
102 const_reverse_iterator rbegin() const noexcept;
103 reverse_iterator rend() noexcept;
104 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16105
Howard Hinnantb2e2a8f2011-06-04 15:22:34106 const_iterator cbegin() const noexcept;
107 const_iterator cend() const noexcept;
108 const_reverse_iterator crbegin() const noexcept;
109 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16110
111 // capacity:
Howard Hinnantb2e2a8f2011-06-04 15:22:34112 bool empty() const noexcept;
113 size_type size() const noexcept;
114 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16115
116 // element access:
117 mapped_type& operator[](const key_type& k);
118 mapped_type& operator[](key_type&& k);
119
120 mapped_type& at(const key_type& k);
121 const mapped_type& at(const key_type& k) const;
122
123 // modifiers:
124 template <class... Args>
125 pair<iterator, bool> emplace(Args&&... args);
126 template <class... Args>
127 iterator emplace_hint(const_iterator position, Args&&... args);
128 pair<iterator, bool> insert(const value_type& v);
129 template <class P>
130 pair<iterator, bool> insert(P&& p);
131 iterator insert(const_iterator position, const value_type& v);
132 template <class P>
133 iterator insert(const_iterator position, P&& p);
134 template <class InputIterator>
135 void insert(InputIterator first, InputIterator last);
136 void insert(initializer_list<value_type> il);
137
Marshall Clowf3a1a182015-07-07 03:37:33138 template <class... Args>
139 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
140 template <class... Args>
141 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
142 template <class... Args>
143 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
144 template <class... Args>
145 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
146 template <class M>
147 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
148 template <class M>
149 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
150 template <class M>
151 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
152 template <class M>
153 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
154
Howard Hinnantbc8d3f92010-05-11 19:42:16155 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00156 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16157 size_type erase(const key_type& k);
158 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantb2e2a8f2011-06-04 15:22:34159 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16160
Howard Hinnant7686add2011-06-04 14:31:57161 void swap(map& m)
Marshall Clow7d914d12015-07-13 20:04:56162 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
163 __is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16164
165 // observers:
Howard Hinnantb2e2a8f2011-06-04 15:22:34166 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16167 key_compare key_comp() const;
168 value_compare value_comp() const;
169
170 // map operations:
171 iterator find(const key_type& k);
172 const_iterator find(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47173 template<typename K>
174 iterator find(const K& x); // C++14
175 template<typename K>
176 const_iterator find(const K& x) const; // C++14
177 template<typename K>
Marshall Clow4de32042014-08-24 23:54:16178 size_type count(const K& x) const; // C++14
Marshall Clow5cfc6ab2013-08-13 22:18:47179
Howard Hinnantbc8d3f92010-05-11 19:42:16180 size_type count(const key_type& k) const;
181 iterator lower_bound(const key_type& k);
182 const_iterator lower_bound(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47183 template<typename K>
184 iterator lower_bound(const K& x); // C++14
185 template<typename K>
186 const_iterator lower_bound(const K& x) const; // C++14
187
Howard Hinnantbc8d3f92010-05-11 19:42:16188 iterator upper_bound(const key_type& k);
189 const_iterator upper_bound(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47190 template<typename K>
191 iterator upper_bound(const K& x); // C++14
192 template<typename K>
193 const_iterator upper_bound(const K& x) const; // C++14
194
Howard Hinnantbc8d3f92010-05-11 19:42:16195 pair<iterator,iterator> equal_range(const key_type& k);
196 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47197 template<typename K>
198 pair<iterator,iterator> equal_range(const K& x); // C++14
199 template<typename K>
200 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16201};
202
203template <class Key, class T, class Compare, class Allocator>
204bool
205operator==(const map<Key, T, Compare, Allocator>& x,
206 const map<Key, T, Compare, Allocator>& y);
207
208template <class Key, class T, class Compare, class Allocator>
209bool
210operator< (const map<Key, T, Compare, Allocator>& x,
211 const map<Key, T, Compare, Allocator>& y);
212
213template <class Key, class T, class Compare, class Allocator>
214bool
215operator!=(const map<Key, T, Compare, Allocator>& x,
216 const map<Key, T, Compare, Allocator>& y);
217
218template <class Key, class T, class Compare, class Allocator>
219bool
220operator> (const map<Key, T, Compare, Allocator>& x,
221 const map<Key, T, Compare, Allocator>& y);
222
223template <class Key, class T, class Compare, class Allocator>
224bool
225operator>=(const map<Key, T, Compare, Allocator>& x,
226 const map<Key, T, Compare, Allocator>& y);
227
228template <class Key, class T, class Compare, class Allocator>
229bool
230operator<=(const map<Key, T, Compare, Allocator>& x,
231 const map<Key, T, Compare, Allocator>& y);
232
233// specialized algorithms:
234template <class Key, class T, class Compare, class Allocator>
235void
Howard Hinnant7686add2011-06-04 14:31:57236swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
237 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16238
239template <class Key, class T, class Compare = less<Key>,
240 class Allocator = allocator<pair<const Key, T>>>
241class multimap
242{
243public:
244 // types:
245 typedef Key key_type;
246 typedef T mapped_type;
247 typedef pair<const key_type,mapped_type> value_type;
248 typedef Compare key_compare;
249 typedef Allocator allocator_type;
250 typedef typename allocator_type::reference reference;
251 typedef typename allocator_type::const_reference const_reference;
252 typedef typename allocator_type::size_type size_type;
253 typedef typename allocator_type::difference_type difference_type;
254 typedef typename allocator_type::pointer pointer;
255 typedef typename allocator_type::const_pointer const_pointer;
256
257 typedef implementation-defined iterator;
258 typedef implementation-defined const_iterator;
259 typedef std::reverse_iterator<iterator> reverse_iterator;
260 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
261
262 class value_compare
263 : public binary_function<value_type,value_type,bool>
264 {
265 friend class multimap;
266 protected:
267 key_compare comp;
268 value_compare(key_compare c);
269 public:
270 bool operator()(const value_type& x, const value_type& y) const;
271 };
272
273 // construct/copy/destroy:
Howard Hinnant7686add2011-06-04 14:31:57274 multimap()
275 noexcept(
276 is_nothrow_default_constructible<allocator_type>::value &&
277 is_nothrow_default_constructible<key_compare>::value &&
278 is_nothrow_copy_constructible<key_compare>::value);
279 explicit multimap(const key_compare& comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16280 multimap(const key_compare& comp, const allocator_type& a);
281 template <class InputIterator>
282 multimap(InputIterator first, InputIterator last, const key_compare& comp);
283 template <class InputIterator>
284 multimap(InputIterator first, InputIterator last, const key_compare& comp,
285 const allocator_type& a);
286 multimap(const multimap& m);
Howard Hinnant7686add2011-06-04 14:31:57287 multimap(multimap&& m)
288 noexcept(
289 is_nothrow_move_constructible<allocator_type>::value &&
290 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16291 explicit multimap(const allocator_type& a);
292 multimap(const multimap& m, const allocator_type& a);
293 multimap(multimap&& m, const allocator_type& a);
294 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
295 multimap(initializer_list<value_type> il, const key_compare& comp,
296 const allocator_type& a);
Marshall Clow49d596d2013-09-11 01:15:47297 template <class InputIterator>
298 multimap(InputIterator first, InputIterator last, const allocator_type& a)
299 : multimap(first, last, Compare(), a) {} // C++14
300 multimap(initializer_list<value_type> il, const allocator_type& a)
301 : multimap(il, Compare(), a) {} // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16302 ~multimap();
303
304 multimap& operator=(const multimap& m);
Howard Hinnant7686add2011-06-04 14:31:57305 multimap& operator=(multimap&& m)
306 noexcept(
307 allocator_type::propagate_on_container_move_assignment::value &&
308 is_nothrow_move_assignable<allocator_type>::value &&
Howard Hinnantb2e2a8f2011-06-04 15:22:34309 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16310 multimap& operator=(initializer_list<value_type> il);
311
312 // iterators:
Howard Hinnantb2e2a8f2011-06-04 15:22:34313 iterator begin() noexcept;
314 const_iterator begin() const noexcept;
315 iterator end() noexcept;
316 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16317
Howard Hinnantb2e2a8f2011-06-04 15:22:34318 reverse_iterator rbegin() noexcept;
319 const_reverse_iterator rbegin() const noexcept;
320 reverse_iterator rend() noexcept;
321 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16322
Howard Hinnantb2e2a8f2011-06-04 15:22:34323 const_iterator cbegin() const noexcept;
324 const_iterator cend() const noexcept;
325 const_reverse_iterator crbegin() const noexcept;
326 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16327
328 // capacity:
Howard Hinnantb2e2a8f2011-06-04 15:22:34329 bool empty() const noexcept;
330 size_type size() const noexcept;
331 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16332
333 // modifiers:
334 template <class... Args>
335 iterator emplace(Args&&... args);
336 template <class... Args>
337 iterator emplace_hint(const_iterator position, Args&&... args);
338 iterator insert(const value_type& v);
339 template <class P>
340 iterator insert(P&& p);
341 iterator insert(const_iterator position, const value_type& v);
342 template <class P>
343 iterator insert(const_iterator position, P&& p);
344 template <class InputIterator>
345 void insert(InputIterator first, InputIterator last);
346 void insert(initializer_list<value_type> il);
347
348 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00349 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16350 size_type erase(const key_type& k);
351 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantb2e2a8f2011-06-04 15:22:34352 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16353
Howard Hinnant7686add2011-06-04 14:31:57354 void swap(multimap& m)
Marshall Clow7d914d12015-07-13 20:04:56355 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
356 __is_nothrow_swappable<key_compare>::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16357
358 // observers:
Howard Hinnantb2e2a8f2011-06-04 15:22:34359 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16360 key_compare key_comp() const;
361 value_compare value_comp() const;
362
363 // map operations:
364 iterator find(const key_type& k);
365 const_iterator find(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47366 template<typename K>
367 iterator find(const K& x); // C++14
368 template<typename K>
369 const_iterator find(const K& x) const; // C++14
370 template<typename K>
Marshall Clow4de32042014-08-24 23:54:16371 size_type count(const K& x) const; // C++14
Marshall Clow5cfc6ab2013-08-13 22:18:47372
Howard Hinnantbc8d3f92010-05-11 19:42:16373 size_type count(const key_type& k) const;
374 iterator lower_bound(const key_type& k);
375 const_iterator lower_bound(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47376 template<typename K>
377 iterator lower_bound(const K& x); // C++14
378 template<typename K>
379 const_iterator lower_bound(const K& x) const; // C++14
380
Howard Hinnantbc8d3f92010-05-11 19:42:16381 iterator upper_bound(const key_type& k);
382 const_iterator upper_bound(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47383 template<typename K>
384 iterator upper_bound(const K& x); // C++14
385 template<typename K>
386 const_iterator upper_bound(const K& x) const; // C++14
387
Howard Hinnantbc8d3f92010-05-11 19:42:16388 pair<iterator,iterator> equal_range(const key_type& k);
389 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clow5cfc6ab2013-08-13 22:18:47390 template<typename K>
391 pair<iterator,iterator> equal_range(const K& x); // C++14
392 template<typename K>
393 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16394};
395
396template <class Key, class T, class Compare, class Allocator>
397bool
398operator==(const multimap<Key, T, Compare, Allocator>& x,
399 const multimap<Key, T, Compare, Allocator>& y);
400
401template <class Key, class T, class Compare, class Allocator>
402bool
403operator< (const multimap<Key, T, Compare, Allocator>& x,
404 const multimap<Key, T, Compare, Allocator>& y);
405
406template <class Key, class T, class Compare, class Allocator>
407bool
408operator!=(const multimap<Key, T, Compare, Allocator>& x,
409 const multimap<Key, T, Compare, Allocator>& y);
410
411template <class Key, class T, class Compare, class Allocator>
412bool
413operator> (const multimap<Key, T, Compare, Allocator>& x,
414 const multimap<Key, T, Compare, Allocator>& y);
415
416template <class Key, class T, class Compare, class Allocator>
417bool
418operator>=(const multimap<Key, T, Compare, Allocator>& x,
419 const multimap<Key, T, Compare, Allocator>& y);
420
421template <class Key, class T, class Compare, class Allocator>
422bool
423operator<=(const multimap<Key, T, Compare, Allocator>& x,
424 const multimap<Key, T, Compare, Allocator>& y);
425
426// specialized algorithms:
427template <class Key, class T, class Compare, class Allocator>
428void
429swap(multimap<Key, T, Compare, Allocator>& x,
Howard Hinnant7686add2011-06-04 14:31:57430 multimap<Key, T, Compare, Allocator>& y)
431 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16432
433} // std
434
435*/
436
437#include <__config>
438#include <__tree>
439#include <iterator>
440#include <memory>
441#include <utility>
442#include <functional>
443#include <initializer_list>
Eric Fiselier3a0e4302015-06-13 07:08:02444#include <type_traits>
Howard Hinnantbc8d3f92010-05-11 19:42:16445
Howard Hinnant08e17472011-10-17 20:05:10446#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16447#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10448#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16449
450_LIBCPP_BEGIN_NAMESPACE_STD
451
Eric Fiselier3a0e4302015-06-13 07:08:02452template <class _Key, class _CP, class _Compare,
453 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value
Howard Hinnantd4cf2152011-12-11 20:31:33454 >
Howard Hinnantbc8d3f92010-05-11 19:42:16455class __map_value_compare
456 : private _Compare
457{
Howard Hinnantbc8d3f92010-05-11 19:42:16458public:
Howard Hinnant82894812010-09-22 16:48:34459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57460 __map_value_compare()
461 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
462 : _Compare() {}
Howard Hinnant82894812010-09-22 16:48:34463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57464 __map_value_compare(_Compare c)
465 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
466 : _Compare(c) {}
Howard Hinnant82894812010-09-22 16:48:34467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57468 const _Compare& key_comp() const _NOEXCEPT {return *this;}
Howard Hinnant82894812010-09-22 16:48:34469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16470 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00471 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnant82894812010-09-22 16:48:34472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16473 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00474 {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16476 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00477 {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56478 void swap(__map_value_compare&__y)
479 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
480 {
481 using _VSTD::swap;
482 swap(static_cast<const _Compare&>(*this), static_cast<const _Compare&>(__y));
483 }
Marshall Clow5cfc6ab2013-08-13 22:18:47484
485#if _LIBCPP_STD_VER > 11
486 template <typename _K2>
487 _LIBCPP_INLINE_VISIBILITY
488 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
489 operator () ( const _K2& __x, const _CP& __y ) const
490 {return static_cast<const _Compare&>(*this) (__x, __y.__cc.first);}
491
492 template <typename _K2>
493 _LIBCPP_INLINE_VISIBILITY
494 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
495 operator () (const _CP& __x, const _K2& __y) const
496 {return static_cast<const _Compare&>(*this) (__x.__cc.first, __y);}
497#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16498};
499
Howard Hinnant9b128e02013-07-05 18:06:00500template <class _Key, class _CP, class _Compare>
501class __map_value_compare<_Key, _CP, _Compare, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16502{
503 _Compare comp;
504
Howard Hinnantbc8d3f92010-05-11 19:42:16505public:
Howard Hinnant82894812010-09-22 16:48:34506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57507 __map_value_compare()
508 _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
509 : comp() {}
Howard Hinnant82894812010-09-22 16:48:34510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57511 __map_value_compare(_Compare c)
512 _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
513 : comp(c) {}
Howard Hinnant82894812010-09-22 16:48:34514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57515 const _Compare& key_comp() const _NOEXCEPT {return comp;}
Howard Hinnantbc8d3f92010-05-11 19:42:16516
Howard Hinnant82894812010-09-22 16:48:34517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16518 bool operator()(const _CP& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00519 {return comp(__x.__cc.first, __y.__cc.first);}
Howard Hinnant82894812010-09-22 16:48:34520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16521 bool operator()(const _CP& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00522 {return comp(__x.__cc.first, __y);}
Howard Hinnant82894812010-09-22 16:48:34523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16524 bool operator()(const _Key& __x, const _CP& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00525 {return comp(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56526 void swap(__map_value_compare&__y)
527 _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
528 {
529 using _VSTD::swap;
530 swap(comp, __y.comp);
531 }
532
Marshall Clow5cfc6ab2013-08-13 22:18:47533#if _LIBCPP_STD_VER > 11
534 template <typename _K2>
535 _LIBCPP_INLINE_VISIBILITY
536 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
537 operator () ( const _K2& __x, const _CP& __y ) const
538 {return comp (__x, __y.__cc.first);}
539
540 template <typename _K2>
541 _LIBCPP_INLINE_VISIBILITY
542 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
543 operator () (const _CP& __x, const _K2& __y) const
544 {return comp (__x.__cc.first, __y);}
545#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16546};
547
Marshall Clow7d914d12015-07-13 20:04:56548template <class _Key, class _CP, class _Compare, bool __b>
549inline _LIBCPP_INLINE_VISIBILITY
550void
551swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
552 __map_value_compare<_Key, _CP, _Compare, __b>& __y)
553 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
554{
555 __x.swap(__y);
556}
557
Howard Hinnantbc8d3f92010-05-11 19:42:16558template <class _Allocator>
559class __map_node_destructor
560{
561 typedef _Allocator allocator_type;
562 typedef allocator_traits<allocator_type> __alloc_traits;
563 typedef typename __alloc_traits::value_type::value_type value_type;
564public:
565 typedef typename __alloc_traits::pointer pointer;
566private:
Howard Hinnant70342b92013-06-19 21:29:40567 typedef typename value_type::value_type::first_type first_type;
568 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16569
570 allocator_type& __na_;
571
572 __map_node_destructor& operator=(const __map_node_destructor&);
573
574public:
575 bool __first_constructed;
576 bool __second_constructed;
577
Howard Hinnant82894812010-09-22 16:48:34578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57579 explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16580 : __na_(__na),
581 __first_constructed(false),
582 __second_constructed(false)
583 {}
584
Howard Hinnant73d21a42010-09-04 23:28:19585#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57587 __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16588 : __na_(__x.__na_),
589 __first_constructed(__x.__value_constructed),
590 __second_constructed(__x.__value_constructed)
591 {
592 __x.__value_constructed = false;
593 }
Howard Hinnantbfd55302010-09-04 23:46:48594#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16595
Howard Hinnant82894812010-09-22 16:48:34596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57597 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16598 {
599 if (__second_constructed)
Howard Hinnant70342b92013-06-19 21:29:40600 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16601 if (__first_constructed)
Howard Hinnant70342b92013-06-19 21:29:40602 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16603 if (__p)
604 __alloc_traits::deallocate(__na_, __p, 1);
605 }
606};
607
Howard Hinnant2b1b2d42011-06-14 19:58:17608template <class _Key, class _Tp, class _Compare, class _Allocator>
609 class map;
610template <class _Key, class _Tp, class _Compare, class _Allocator>
611 class multimap;
612template <class _TreeIterator> class __map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16613
Howard Hinnantff7546e2013-09-30 19:08:22614#if __cplusplus >= 201103L
615
616template <class _Key, class _Tp>
617union __value_type
618{
619 typedef _Key key_type;
620 typedef _Tp mapped_type;
621 typedef pair<const key_type, mapped_type> value_type;
622 typedef pair<key_type, mapped_type> __nc_value_type;
623
624 value_type __cc;
625 __nc_value_type __nc;
626
627 template <class ..._Args>
628 _LIBCPP_INLINE_VISIBILITY
629 __value_type(_Args&& ...__args)
630 : __cc(std::forward<_Args>(__args)...) {}
631
632 _LIBCPP_INLINE_VISIBILITY
633 __value_type(const __value_type& __v)
634 : __cc(__v.__cc) {}
635
636 _LIBCPP_INLINE_VISIBILITY
637 __value_type(__value_type& __v)
638 : __cc(__v.__cc) {}
639
640 _LIBCPP_INLINE_VISIBILITY
641 __value_type(__value_type&& __v)
642 : __nc(std::move(__v.__nc)) {}
643
644 _LIBCPP_INLINE_VISIBILITY
645 __value_type& operator=(const __value_type& __v)
646 {__nc = __v.__cc; return *this;}
647
648 _LIBCPP_INLINE_VISIBILITY
649 __value_type& operator=(__value_type&& __v)
650 {__nc = std::move(__v.__nc); return *this;}
651
652 _LIBCPP_INLINE_VISIBILITY
653 ~__value_type() {__cc.~value_type();}
654};
655
656#else
657
658template <class _Key, class _Tp>
659struct __value_type
660{
661 typedef _Key key_type;
662 typedef _Tp mapped_type;
663 typedef pair<const key_type, mapped_type> value_type;
664
665 value_type __cc;
666
667 _LIBCPP_INLINE_VISIBILITY
668 __value_type() {}
669
670 template <class _A0>
671 _LIBCPP_INLINE_VISIBILITY
672 __value_type(const _A0& __a0)
673 : __cc(__a0) {}
674
675 template <class _A0, class _A1>
676 _LIBCPP_INLINE_VISIBILITY
677 __value_type(const _A0& __a0, const _A1& __a1)
678 : __cc(__a0, __a1) {}
679};
680
681#endif
682
Eric Fiselier9c8e6632015-03-03 20:10:01683template <class _Tp>
684struct __extract_key_value_types;
685
686template <class _Key, class _Tp>
687struct __extract_key_value_types<__value_type<_Key, _Tp> >
688{
689 typedef _Key const __key_type;
690 typedef _Tp __mapped_type;
691};
692
Howard Hinnantbc8d3f92010-05-11 19:42:16693template <class _TreeIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34694class _LIBCPP_TYPE_VIS_ONLY __map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16695{
696 _TreeIterator __i_;
697
698 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier9c8e6632015-03-03 20:10:01699 typedef typename _TreeIterator::value_type __value_type;
700 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
701 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16702public:
703 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantdf85e572011-02-27 18:02:02704 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16705 typedef typename _TreeIterator::difference_type difference_type;
706 typedef value_type& reference;
707 typedef typename __pointer_traits::template
708#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
709 rebind<value_type>
710#else
711 rebind<value_type>::other
712#endif
713 pointer;
714
Howard Hinnant82894812010-09-22 16:48:34715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57716 __map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16717
Howard Hinnant82894812010-09-22 16:48:34718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57719 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16720
Howard Hinnant82894812010-09-22 16:48:34721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40722 reference operator*() const {return __i_->__cc;}
Howard Hinnant82894812010-09-22 16:48:34723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40724 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16725
Howard Hinnant82894812010-09-22 16:48:34726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16727 __map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16729 __map_iterator operator++(int)
730 {
731 __map_iterator __t(*this);
732 ++(*this);
733 return __t;
734 }
735
Howard Hinnant82894812010-09-22 16:48:34736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16737 __map_iterator& operator--() {--__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16739 __map_iterator operator--(int)
740 {
741 __map_iterator __t(*this);
742 --(*this);
743 return __t;
744 }
745
Howard Hinnant82894812010-09-22 16:48:34746 friend _LIBCPP_INLINE_VISIBILITY
747 bool operator==(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16748 {return __x.__i_ == __y.__i_;}
Howard Hinnant82894812010-09-22 16:48:34749 friend
750 _LIBCPP_INLINE_VISIBILITY
751 bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16752 {return __x.__i_ != __y.__i_;}
753
Howard Hinnant0f678bd2013-08-12 18:38:34754 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
755 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
756 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16757};
758
759template <class _TreeIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34760class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16761{
762 _TreeIterator __i_;
763
764 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
Eric Fiselier9c8e6632015-03-03 20:10:01765 typedef typename _TreeIterator::value_type __value_type;
766 typedef typename __extract_key_value_types<__value_type>::__key_type __key_type;
767 typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16768public:
769 typedef bidirectional_iterator_tag iterator_category;
Howard Hinnantdf85e572011-02-27 18:02:02770 typedef pair<__key_type, __mapped_type> value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16771 typedef typename _TreeIterator::difference_type difference_type;
772 typedef const value_type& reference;
773 typedef typename __pointer_traits::template
774#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant9dbeff92011-04-11 02:18:41775 rebind<const value_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16776#else
Howard Hinnant9dbeff92011-04-11 02:18:41777 rebind<const value_type>::other
Howard Hinnantbc8d3f92010-05-11 19:42:16778#endif
779 pointer;
780
Howard Hinnant82894812010-09-22 16:48:34781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57782 __map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16783
Howard Hinnant82894812010-09-22 16:48:34784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:57785 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant82894812010-09-22 16:48:34786 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9c8e6632015-03-03 20:10:01787 __map_const_iterator(__map_iterator<
788 typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
789 : __i_(__i.__i_) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16790
Howard Hinnant82894812010-09-22 16:48:34791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40792 reference operator*() const {return __i_->__cc;}
Howard Hinnant82894812010-09-22 16:48:34793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant70342b92013-06-19 21:29:40794 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16795
Howard Hinnant82894812010-09-22 16:48:34796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16797 __map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16799 __map_const_iterator operator++(int)
800 {
801 __map_const_iterator __t(*this);
802 ++(*this);
803 return __t;
804 }
805
Howard Hinnant82894812010-09-22 16:48:34806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16807 __map_const_iterator& operator--() {--__i_; return *this;}
Howard Hinnant82894812010-09-22 16:48:34808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16809 __map_const_iterator operator--(int)
810 {
811 __map_const_iterator __t(*this);
812 --(*this);
813 return __t;
814 }
815
Howard Hinnant82894812010-09-22 16:48:34816 friend _LIBCPP_INLINE_VISIBILITY
817 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16818 {return __x.__i_ == __y.__i_;}
Howard Hinnant82894812010-09-22 16:48:34819 friend _LIBCPP_INLINE_VISIBILITY
820 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16821 {return __x.__i_ != __y.__i_;}
822
Howard Hinnant0f678bd2013-08-12 18:38:34823 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
824 template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
825 template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16826};
827
828template <class _Key, class _Tp, class _Compare = less<_Key>,
829 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34830class _LIBCPP_TYPE_VIS_ONLY map
Howard Hinnantbc8d3f92010-05-11 19:42:16831{
832public:
833 // types:
834 typedef _Key key_type;
835 typedef _Tp mapped_type;
836 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant70342b92013-06-19 21:29:40837 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16838 typedef _Compare key_compare;
839 typedef _Allocator allocator_type;
840 typedef value_type& reference;
841 typedef const value_type& const_reference;
842
Howard Hinnant0f678bd2013-08-12 18:38:34843 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantbc8d3f92010-05-11 19:42:16844 : public binary_function<value_type, value_type, bool>
845 {
846 friend class map;
847 protected:
848 key_compare comp;
849
Howard Hinnant82894812010-09-22 16:48:34850 _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16851 public:
Howard Hinnant82894812010-09-22 16:48:34852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16853 bool operator()(const value_type& __x, const value_type& __y) const
854 {return comp(__x.first, __y.first);}
855 };
856
857private:
Howard Hinnant70342b92013-06-19 21:29:40858
Howard Hinnantff7546e2013-09-30 19:08:22859 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00860 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow66302c62015-04-07 05:21:38861 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
862 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16863 typedef __tree<__value_type, __vc, __allocator_type> __base;
864 typedef typename __base::__node_traits __node_traits;
865 typedef allocator_traits<allocator_type> __alloc_traits;
866
867 __base __tree_;
868
869public:
870 typedef typename __alloc_traits::pointer pointer;
871 typedef typename __alloc_traits::const_pointer const_pointer;
872 typedef typename __alloc_traits::size_type size_type;
873 typedef typename __alloc_traits::difference_type difference_type;
Eric Fiselier9c8e6632015-03-03 20:10:01874 typedef __map_iterator<typename __base::iterator> iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16875 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19876 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
877 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16878
Howard Hinnant82894812010-09-22 16:48:34879 _LIBCPP_INLINE_VISIBILITY
Marshall Clowcaaa1412014-03-10 04:50:10880 map()
881 _NOEXCEPT_(
882 is_nothrow_default_constructible<allocator_type>::value &&
883 is_nothrow_default_constructible<key_compare>::value &&
884 is_nothrow_copy_constructible<key_compare>::value)
885 : __tree_(__vc(key_compare())) {}
886
887 _LIBCPP_INLINE_VISIBILITY
888 explicit map(const key_compare& __comp)
Howard Hinnant7686add2011-06-04 14:31:57889 _NOEXCEPT_(
890 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant7686add2011-06-04 14:31:57891 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16892 : __tree_(__vc(__comp)) {}
893
Howard Hinnant82894812010-09-22 16:48:34894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16895 explicit map(const key_compare& __comp, const allocator_type& __a)
896 : __tree_(__vc(__comp), __a) {}
897
898 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16900 map(_InputIterator __f, _InputIterator __l,
901 const key_compare& __comp = key_compare())
902 : __tree_(__vc(__comp))
903 {
904 insert(__f, __l);
905 }
906
907 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:34908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16909 map(_InputIterator __f, _InputIterator __l,
910 const key_compare& __comp, const allocator_type& __a)
911 : __tree_(__vc(__comp), __a)
912 {
913 insert(__f, __l);
914 }
915
Marshall Clow49d596d2013-09-11 01:15:47916#if _LIBCPP_STD_VER > 11
917 template <class _InputIterator>
918 _LIBCPP_INLINE_VISIBILITY
919 map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
920 : map(__f, __l, key_compare(), __a) {}
921#endif
922
Howard Hinnant82894812010-09-22 16:48:34923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16924 map(const map& __m)
925 : __tree_(__m.__tree_)
926 {
927 insert(__m.begin(), __m.end());
928 }
929
Howard Hinnant61aa6012011-07-01 19:24:36930 _LIBCPP_INLINE_VISIBILITY
931 map& operator=(const map& __m)
932 {
Howard Hinnant70342b92013-06-19 21:29:40933#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36934 __tree_ = __m.__tree_;
Howard Hinnant70342b92013-06-19 21:29:40935#else
Marshall Clowebfc50e2014-02-08 04:03:14936 if (this != &__m) {
937 __tree_.clear();
938 __tree_.value_comp() = __m.__tree_.value_comp();
939 __tree_.__copy_assign_alloc(__m.__tree_);
940 insert(__m.begin(), __m.end());
941 }
Howard Hinnant70342b92013-06-19 21:29:40942#endif
Howard Hinnant61aa6012011-07-01 19:24:36943 return *this;
944 }
945
Howard Hinnant73d21a42010-09-04 23:28:19946#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16947
Howard Hinnant82894812010-09-22 16:48:34948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16949 map(map&& __m)
Howard Hinnant7686add2011-06-04 14:31:57950 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:19951 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantbc8d3f92010-05-11 19:42:16952 {
953 }
954
955 map(map&& __m, const allocator_type& __a);
956
Howard Hinnant82894812010-09-22 16:48:34957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante3e32912011-08-12 21:56:02958 map& operator=(map&& __m)
959 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
960 {
961 __tree_ = _VSTD::move(__m.__tree_);
962 return *this;
963 }
964
965#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
966
967#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
968
969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16970 map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
971 : __tree_(__vc(__comp))
972 {
973 insert(__il.begin(), __il.end());
974 }
975
Howard Hinnant82894812010-09-22 16:48:34976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16977 map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
978 : __tree_(__vc(__comp), __a)
979 {
980 insert(__il.begin(), __il.end());
981 }
982
Marshall Clow49d596d2013-09-11 01:15:47983#if _LIBCPP_STD_VER > 11
984 _LIBCPP_INLINE_VISIBILITY
985 map(initializer_list<value_type> __il, const allocator_type& __a)
986 : map(__il, key_compare(), __a) {}
987#endif
988
Howard Hinnant82894812010-09-22 16:48:34989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16990 map& operator=(initializer_list<value_type> __il)
991 {
992 __tree_.__assign_unique(__il.begin(), __il.end());
993 return *this;
994 }
995
Howard Hinnante3e32912011-08-12 21:56:02996#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16997
Howard Hinnant82894812010-09-22 16:48:34998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16999 explicit map(const allocator_type& __a)
1000 : __tree_(__a)
1001 {
1002 }
1003
Howard Hinnant82894812010-09-22 16:48:341004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161005 map(const map& __m, const allocator_type& __a)
1006 : __tree_(__m.__tree_.value_comp(), __a)
1007 {
1008 insert(__m.begin(), __m.end());
1009 }
1010
Howard Hinnant82894812010-09-22 16:48:341011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571012 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571014 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571016 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant82894812010-09-22 16:48:341017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571018 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:161019
Howard Hinnant82894812010-09-22 16:48:341020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571021 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571023 const_reverse_iterator rbegin() const _NOEXCEPT
1024 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571026 reverse_iterator rend() _NOEXCEPT
1027 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:341028 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571029 const_reverse_iterator rend() const _NOEXCEPT
1030 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:161031
Howard Hinnant82894812010-09-22 16:48:341032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571033 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant82894812010-09-22 16:48:341034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571035 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant82894812010-09-22 16:48:341036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571037 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant82894812010-09-22 16:48:341038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571039 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:161040
Howard Hinnant82894812010-09-22 16:48:341041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571042 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant82894812010-09-22 16:48:341043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571044 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant82894812010-09-22 16:48:341045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571046 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:161047
1048 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:191049#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161050 mapped_type& operator[](key_type&& __k);
1051#endif
1052
1053 mapped_type& at(const key_type& __k);
1054 const mapped_type& at(const key_type& __k) const;
1055
Howard Hinnant82894812010-09-22 16:48:341056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571057 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant82894812010-09-22 16:48:341058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161059 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant82894812010-09-22 16:48:341060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161061 value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
1062
Howard Hinnant73d21a42010-09-04 23:28:191063#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:191064#ifndef _LIBCPP_HAS_NO_VARIADICS
1065
Howard Hinnant635ce1d2012-05-25 22:04:211066 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161067 pair<iterator, bool>
Howard Hinnant635ce1d2012-05-25 22:04:211068 emplace(_Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161069
Howard Hinnant635ce1d2012-05-25 22:04:211070 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161071 iterator
Howard Hinnant635ce1d2012-05-25 22:04:211072 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161073
Howard Hinnant73d21a42010-09-04 23:28:191074#endif // _LIBCPP_HAS_NO_VARIADICS
1075
Howard Hinnant99968442011-11-29 18:15:501076 template <class _Pp,
1077 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501079 pair<iterator, bool> insert(_Pp&& __p)
1080 {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161081
Howard Hinnant99968442011-11-29 18:15:501082 template <class _Pp,
1083 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501085 iterator insert(const_iterator __pos, _Pp&& __p)
1086 {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161087
Howard Hinnant73d21a42010-09-04 23:28:191088#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161089
Howard Hinnant82894812010-09-22 16:48:341090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161091 pair<iterator, bool>
1092 insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
1093
Howard Hinnant82894812010-09-22 16:48:341094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161095 iterator
1096 insert(const_iterator __p, const value_type& __v)
1097 {return __tree_.__insert_unique(__p.__i_, __v);}
1098
1099 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161101 void insert(_InputIterator __f, _InputIterator __l)
1102 {
1103 for (const_iterator __e = cend(); __f != __l; ++__f)
1104 insert(__e.__i_, *__f);
1105 }
1106
Howard Hinnante3e32912011-08-12 21:56:021107#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1108
Howard Hinnant82894812010-09-22 16:48:341109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161110 void insert(initializer_list<value_type> __il)
1111 {insert(__il.begin(), __il.end());}
1112
Howard Hinnante3e32912011-08-12 21:56:021113#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1114
Marshall Clowf3a1a182015-07-07 03:37:331115#if _LIBCPP_STD_VER > 14
1116#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1117#ifndef _LIBCPP_HAS_NO_VARIADICS
1118 template <class... _Args>
1119 _LIBCPP_INLINE_VISIBILITY
1120 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1121 {
1122 iterator __p = lower_bound(__k);
1123 if ( __p != end() && !key_comp()(__k, __p->first))
1124 return _VSTD::make_pair(__p, false);
1125 else
1126 return _VSTD::make_pair(
1127 emplace_hint(__p,
1128 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1129 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1130 true);
1131 }
1132
1133 template <class... _Args>
1134 _LIBCPP_INLINE_VISIBILITY
1135 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1136 {
1137 iterator __p = lower_bound(__k);
1138 if ( __p != end() && !key_comp()(__k, __p->first))
1139 return _VSTD::make_pair(__p, false);
1140 else
1141 return _VSTD::make_pair(
1142 emplace_hint(__p,
1143 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1144 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1145 true);
1146 }
1147
1148 template <class... _Args>
1149 _LIBCPP_INLINE_VISIBILITY
1150 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1151 {
1152 iterator __p = lower_bound(__k);
1153 if ( __p != end() && !key_comp()(__k, __p->first))
1154 return __p;
1155 else
1156 return emplace_hint(__p,
1157 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1158 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1159 }
1160
1161 template <class... _Args>
1162 _LIBCPP_INLINE_VISIBILITY
1163 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1164 {
1165 iterator __p = lower_bound(__k);
1166 if ( __p != end() && !key_comp()(__k, __p->first))
1167 return __p;
1168 else
1169 return emplace_hint(__p,
1170 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1171 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1172 }
1173
1174 template <class _Vp>
1175 _LIBCPP_INLINE_VISIBILITY
1176 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1177 {
1178 iterator __p = lower_bound(__k);
1179 if ( __p != end() && !key_comp()(__k, __p->first))
1180 {
1181 __p->second = _VSTD::forward<_Vp>(__v);
1182 return _VSTD::make_pair(__p, false);
1183 }
1184 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1185 }
1186
1187 template <class _Vp>
1188 _LIBCPP_INLINE_VISIBILITY
1189 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1190 {
1191 iterator __p = lower_bound(__k);
1192 if ( __p != end() && !key_comp()(__k, __p->first))
1193 {
1194 __p->second = _VSTD::forward<_Vp>(__v);
1195 return _VSTD::make_pair(__p, false);
1196 }
1197 return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
1198 }
1199
1200 template <class _Vp>
1201 _LIBCPP_INLINE_VISIBILITY
1202 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1203 {
1204 iterator __p = lower_bound(__k);
1205 if ( __p != end() && !key_comp()(__k, __p->first))
1206 {
1207 __p->second = _VSTD::forward<_Vp>(__v);
1208 return __p;
1209 }
1210 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1211 }
1212
1213 template <class _Vp>
1214 _LIBCPP_INLINE_VISIBILITY
1215 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1216 {
1217 iterator __p = lower_bound(__k);
1218 if ( __p != end() && !key_comp()(__k, __p->first))
1219 {
1220 __p->second = _VSTD::forward<_Vp>(__v);
1221 return __p;
1222 }
1223 return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1224 }
1225#endif
1226#endif
1227#endif
1228
Howard Hinnant82894812010-09-22 16:48:341229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161230 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant82894812010-09-22 16:48:341231 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:001232 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161234 size_type erase(const key_type& __k)
1235 {return __tree_.__erase_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:341236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161237 iterator erase(const_iterator __f, const_iterator __l)
1238 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant82894812010-09-22 16:48:341239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571240 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:161241
Howard Hinnant82894812010-09-22 16:48:341242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571243 void swap(map& __m)
1244 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1245 {__tree_.swap(__m.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:161246
Howard Hinnant82894812010-09-22 16:48:341247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161248 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:341249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161250 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471251#if _LIBCPP_STD_VER > 11
1252 template <typename _K2>
1253 _LIBCPP_INLINE_VISIBILITY
1254 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1255 find(const _K2& __k) {return __tree_.find(__k);}
1256 template <typename _K2>
1257 _LIBCPP_INLINE_VISIBILITY
1258 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1259 find(const _K2& __k) const {return __tree_.find(__k);}
1260#endif
1261
Howard Hinnant82894812010-09-22 16:48:341262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161263 size_type count(const key_type& __k) const
1264 {return __tree_.__count_unique(__k);}
Marshall Clow4de32042014-08-24 23:54:161265#if _LIBCPP_STD_VER > 11
1266 template <typename _K2>
1267 _LIBCPP_INLINE_VISIBILITY
1268 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow58113db2015-06-30 18:15:411269 count(const _K2& __k) const {return __tree_.__count_unique(__k);}
Marshall Clow4de32042014-08-24 23:54:161270#endif
Howard Hinnant82894812010-09-22 16:48:341271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161272 iterator lower_bound(const key_type& __k)
1273 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161275 const_iterator lower_bound(const key_type& __k) const
1276 {return __tree_.lower_bound(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471277#if _LIBCPP_STD_VER > 11
1278 template <typename _K2>
1279 _LIBCPP_INLINE_VISIBILITY
1280 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1281 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1282
1283 template <typename _K2>
1284 _LIBCPP_INLINE_VISIBILITY
1285 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1286 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1287#endif
1288
Howard Hinnant82894812010-09-22 16:48:341289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161290 iterator upper_bound(const key_type& __k)
1291 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:341292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161293 const_iterator upper_bound(const key_type& __k) const
1294 {return __tree_.upper_bound(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471295#if _LIBCPP_STD_VER > 11
1296 template <typename _K2>
1297 _LIBCPP_INLINE_VISIBILITY
1298 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1299 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1300 template <typename _K2>
1301 _LIBCPP_INLINE_VISIBILITY
1302 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1303 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1304#endif
1305
Howard Hinnant82894812010-09-22 16:48:341306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161307 pair<iterator,iterator> equal_range(const key_type& __k)
1308 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant82894812010-09-22 16:48:341309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161310 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1311 {return __tree_.__equal_range_unique(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471312#if _LIBCPP_STD_VER > 11
1313 template <typename _K2>
1314 _LIBCPP_INLINE_VISIBILITY
1315 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1316 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
1317 template <typename _K2>
1318 _LIBCPP_INLINE_VISIBILITY
1319 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1320 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
1321#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161322
1323private:
1324 typedef typename __base::__node __node;
1325 typedef typename __base::__node_allocator __node_allocator;
1326 typedef typename __base::__node_pointer __node_pointer;
1327 typedef typename __base::__node_const_pointer __node_const_pointer;
1328 typedef typename __base::__node_base_pointer __node_base_pointer;
1329 typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
Howard Hinnant99968442011-11-29 18:15:501330 typedef __map_node_destructor<__node_allocator> _Dp;
1331 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:161332
Howard Hinnant73d21a42010-09-04 23:28:191333#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161334 __node_holder __construct_node();
Howard Hinnant635ce1d2012-05-25 22:04:211335 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:161336 __node_holder __construct_node(_A0&& __a0);
1337 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:191338#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:211339 template <class _A0, class _A1, class ..._Args>
1340 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:191341#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:161342#endif
Howard Hinnantb66e1c32013-07-04 20:59:161343 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161344
1345 __node_base_pointer&
1346 __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161347 __node_base_const_pointer
1348 __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
1349};
1350
1351// Find place to insert if __k doesn't exist
1352// Set __parent to parent of null leaf
1353// Return reference to null leaf
1354// If __k exists, set parent to node of __k and return reference to node of __k
1355template <class _Key, class _Tp, class _Compare, class _Allocator>
1356typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
1357map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
1358 const key_type& __k)
1359{
1360 __node_pointer __nd = __tree_.__root();
1361 if (__nd != nullptr)
1362 {
1363 while (true)
1364 {
Howard Hinnant70342b92013-06-19 21:29:401365 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantbc8d3f92010-05-11 19:42:161366 {
1367 if (__nd->__left_ != nullptr)
1368 __nd = static_cast<__node_pointer>(__nd->__left_);
1369 else
1370 {
Howard Hinnant70342b92013-06-19 21:29:401371 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161372 return __parent->__left_;
1373 }
1374 }
Howard Hinnant70342b92013-06-19 21:29:401375 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantbc8d3f92010-05-11 19:42:161376 {
1377 if (__nd->__right_ != nullptr)
1378 __nd = static_cast<__node_pointer>(__nd->__right_);
1379 else
1380 {
Howard Hinnant70342b92013-06-19 21:29:401381 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161382 return __parent->__right_;
1383 }
1384 }
1385 else
1386 {
Howard Hinnant70342b92013-06-19 21:29:401387 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161388 return __parent;
1389 }
1390 }
1391 }
Howard Hinnant70342b92013-06-19 21:29:401392 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantbc8d3f92010-05-11 19:42:161393 return __parent->__left_;
1394}
1395
Howard Hinnantbc8d3f92010-05-11 19:42:161396// Find __k
1397// Set __parent to parent of null leaf and
1398// return reference to null leaf iv __k does not exist.
1399// If __k exists, set parent to node of __k and return reference to node of __k
1400template <class _Key, class _Tp, class _Compare, class _Allocator>
1401typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
1402map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
1403 const key_type& __k) const
1404{
1405 __node_const_pointer __nd = __tree_.__root();
1406 if (__nd != nullptr)
1407 {
1408 while (true)
1409 {
Howard Hinnant70342b92013-06-19 21:29:401410 if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
Howard Hinnantbc8d3f92010-05-11 19:42:161411 {
1412 if (__nd->__left_ != nullptr)
1413 __nd = static_cast<__node_pointer>(__nd->__left_);
1414 else
1415 {
Howard Hinnant70342b92013-06-19 21:29:401416 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161417 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1418 }
1419 }
Howard Hinnant70342b92013-06-19 21:29:401420 else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
Howard Hinnantbc8d3f92010-05-11 19:42:161421 {
1422 if (__nd->__right_ != nullptr)
1423 __nd = static_cast<__node_pointer>(__nd->__right_);
1424 else
1425 {
Howard Hinnant70342b92013-06-19 21:29:401426 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161427 return const_cast<const __node_base_const_pointer&>(__parent->__right_);
1428 }
1429 }
1430 else
1431 {
Howard Hinnant70342b92013-06-19 21:29:401432 __parent = static_cast<__node_base_pointer>(__nd);
Howard Hinnantbc8d3f92010-05-11 19:42:161433 return __parent;
1434 }
1435 }
1436 }
Howard Hinnant70342b92013-06-19 21:29:401437 __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
Howard Hinnantbc8d3f92010-05-11 19:42:161438 return const_cast<const __node_base_const_pointer&>(__parent->__left_);
1439}
1440
Howard Hinnant73d21a42010-09-04 23:28:191441#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161442
1443template <class _Key, class _Tp, class _Compare, class _Allocator>
1444map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:191445 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161446{
1447 if (__a != __m.get_allocator())
1448 {
1449 const_iterator __e = cend();
1450 while (!__m.empty())
1451 __tree_.__insert_unique(__e.__i_,
Howard Hinnant0949eed2011-06-30 21:18:191452 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161453 }
1454}
1455
1456template <class _Key, class _Tp, class _Compare, class _Allocator>
1457typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1458map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
1459{
1460 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501461 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant70342b92013-06-19 21:29:401462 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:161463 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401464 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161465 __h.get_deleter().__second_constructed = true;
1466 return __h;
1467}
1468
1469template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211470template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:161471typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:161472map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
1473{
1474 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501475 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:191476 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:161477 __h.get_deleter().__first_constructed = true;
1478 __h.get_deleter().__second_constructed = true;
1479 return __h;
1480}
1481
1482template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnantb66e1c32013-07-04 20:59:161483typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1484map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:161485{
1486 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501487 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:161488 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:161489 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401490 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:211491 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:501492 return __h;
Howard Hinnant635ce1d2012-05-25 22:04:211493}
1494
1495#ifndef _LIBCPP_HAS_NO_VARIADICS
1496
1497template <class _Key, class _Tp, class _Compare, class _Allocator>
1498template <class _A0, class _A1, class ..._Args>
1499typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1500map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
1501{
1502 __node_allocator& __na = __tree_.__node_alloc();
1503 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1504 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1505 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1506 _VSTD::forward<_Args>(__args)...);
1507 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:161508 __h.get_deleter().__second_constructed = true;
1509 return __h;
1510}
1511
Howard Hinnant73d21a42010-09-04 23:28:191512#endif // _LIBCPP_HAS_NO_VARIADICS
1513
Howard Hinnantb66e1c32013-07-04 20:59:161514#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161515
1516template <class _Key, class _Tp, class _Compare, class _Allocator>
1517typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:161518map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:161519{
1520 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501521 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant70342b92013-06-19 21:29:401522 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161523 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:401524 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161525 __h.get_deleter().__second_constructed = true;
Dimitry Andric89663502015-08-19 06:43:331526 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:161527}
1528
Howard Hinnantbc8d3f92010-05-11 19:42:161529template <class _Key, class _Tp, class _Compare, class _Allocator>
1530_Tp&
1531map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
1532{
1533 __node_base_pointer __parent;
1534 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1535 __node_pointer __r = static_cast<__node_pointer>(__child);
1536 if (__child == nullptr)
1537 {
Howard Hinnantb66e1c32013-07-04 20:59:161538 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant70342b92013-06-19 21:29:401539 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:161540 __r = __h.release();
1541 }
Howard Hinnant70342b92013-06-19 21:29:401542 return __r->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161543}
1544
Howard Hinnant73d21a42010-09-04 23:28:191545#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161546
1547template <class _Key, class _Tp, class _Compare, class _Allocator>
1548_Tp&
1549map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
1550{
1551 __node_base_pointer __parent;
1552 __node_base_pointer& __child = __find_equal_key(__parent, __k);
1553 __node_pointer __r = static_cast<__node_pointer>(__child);
1554 if (__child == nullptr)
1555 {
Howard Hinnantb66e1c32013-07-04 20:59:161556 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnant70342b92013-06-19 21:29:401557 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:161558 __r = __h.release();
1559 }
Howard Hinnant70342b92013-06-19 21:29:401560 return __r->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161561}
1562
Howard Hinnant73d21a42010-09-04 23:28:191563#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161564
1565template <class _Key, class _Tp, class _Compare, class _Allocator>
1566_Tp&
1567map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
1568{
1569 __node_base_pointer __parent;
1570 __node_base_pointer& __child = __find_equal_key(__parent, __k);
Howard Hinnantd4444702010-08-11 17:04:311571#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161572 if (__child == nullptr)
1573 throw out_of_range("map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431574#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant70342b92013-06-19 21:29:401575 return static_cast<__node_pointer>(__child)->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161576}
1577
1578template <class _Key, class _Tp, class _Compare, class _Allocator>
1579const _Tp&
1580map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
1581{
1582 __node_base_const_pointer __parent;
1583 __node_base_const_pointer __child = __find_equal_key(__parent, __k);
Howard Hinnantd4444702010-08-11 17:04:311584#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161585 if (__child == nullptr)
1586 throw out_of_range("map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431587#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant70342b92013-06-19 21:29:401588 return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161589}
1590
Howard Hinnant73d21a42010-09-04 23:28:191591#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161592
1593template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211594template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161595pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
Howard Hinnant635ce1d2012-05-25 22:04:211596map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantbc8d3f92010-05-11 19:42:161597{
Howard Hinnant635ce1d2012-05-25 22:04:211598 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161599 pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
1600 if (__r.second)
1601 __h.release();
1602 return __r;
1603}
1604
1605template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:211606template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161607typename map<_Key, _Tp, _Compare, _Allocator>::iterator
1608map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnant635ce1d2012-05-25 22:04:211609 _Args&& ...__args)
Howard Hinnantbc8d3f92010-05-11 19:42:161610{
Howard Hinnant635ce1d2012-05-25 22:04:211611 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161612 iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
1613 if (__r.__i_.__ptr_ == __h.get())
1614 __h.release();
1615 return __r;
1616}
1617
Howard Hinnant73d21a42010-09-04 23:28:191618#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:161619
1620template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341621inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161622bool
1623operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1624 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1625{
Howard Hinnant0949eed2011-06-30 21:18:191626 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:161627}
1628
1629template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161631bool
1632operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1633 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1634{
Howard Hinnant0949eed2011-06-30 21:18:191635 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:161636}
1637
1638template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341639inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161640bool
1641operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1642 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1643{
1644 return !(__x == __y);
1645}
1646
1647template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341648inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161649bool
1650operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
1651 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1652{
1653 return __y < __x;
1654}
1655
1656template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341657inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161658bool
1659operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1660 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1661{
1662 return !(__x < __y);
1663}
1664
1665template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341666inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161667bool
1668operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
1669 const map<_Key, _Tp, _Compare, _Allocator>& __y)
1670{
1671 return !(__y < __x);
1672}
1673
1674template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:341675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161676void
1677swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
1678 map<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant7686add2011-06-04 14:31:571679 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:161680{
1681 __x.swap(__y);
1682}
1683
1684template <class _Key, class _Tp, class _Compare = less<_Key>,
1685 class _Allocator = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:341686class _LIBCPP_TYPE_VIS_ONLY multimap
Howard Hinnantbc8d3f92010-05-11 19:42:161687{
1688public:
1689 // types:
1690 typedef _Key key_type;
1691 typedef _Tp mapped_type;
1692 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant70342b92013-06-19 21:29:401693 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161694 typedef _Compare key_compare;
1695 typedef _Allocator allocator_type;
1696 typedef value_type& reference;
1697 typedef const value_type& const_reference;
1698
Howard Hinnant0f678bd2013-08-12 18:38:341699 class _LIBCPP_TYPE_VIS_ONLY value_compare
Howard Hinnantbc8d3f92010-05-11 19:42:161700 : public binary_function<value_type, value_type, bool>
1701 {
1702 friend class multimap;
1703 protected:
1704 key_compare comp;
1705
Howard Hinnant82894812010-09-22 16:48:341706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161707 value_compare(key_compare c) : comp(c) {}
1708 public:
Howard Hinnant82894812010-09-22 16:48:341709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161710 bool operator()(const value_type& __x, const value_type& __y) const
1711 {return comp(__x.first, __y.first);}
1712 };
1713
1714private:
Howard Hinnant70342b92013-06-19 21:29:401715
Howard Hinnantff7546e2013-09-30 19:08:221716 typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:001717 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
Marshall Clow66302c62015-04-07 05:21:381718 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1719 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161720 typedef __tree<__value_type, __vc, __allocator_type> __base;
1721 typedef typename __base::__node_traits __node_traits;
1722 typedef allocator_traits<allocator_type> __alloc_traits;
1723
1724 __base __tree_;
1725
1726public:
1727 typedef typename __alloc_traits::pointer pointer;
1728 typedef typename __alloc_traits::const_pointer const_pointer;
1729 typedef typename __alloc_traits::size_type size_type;
1730 typedef typename __alloc_traits::difference_type difference_type;
1731 typedef __map_iterator<typename __base::iterator> iterator;
1732 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:191733 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1734 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:161735
Howard Hinnant82894812010-09-22 16:48:341736 _LIBCPP_INLINE_VISIBILITY
Marshall Clowcaaa1412014-03-10 04:50:101737 multimap()
1738 _NOEXCEPT_(
1739 is_nothrow_default_constructible<allocator_type>::value &&
1740 is_nothrow_default_constructible<key_compare>::value &&
1741 is_nothrow_copy_constructible<key_compare>::value)
1742 : __tree_(__vc(key_compare())) {}
1743
1744 _LIBCPP_INLINE_VISIBILITY
1745 explicit multimap(const key_compare& __comp)
Howard Hinnant7686add2011-06-04 14:31:571746 _NOEXCEPT_(
1747 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnant7686add2011-06-04 14:31:571748 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161749 : __tree_(__vc(__comp)) {}
1750
Howard Hinnant82894812010-09-22 16:48:341751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161752 explicit multimap(const key_compare& __comp, const allocator_type& __a)
1753 : __tree_(__vc(__comp), __a) {}
1754
1755 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161757 multimap(_InputIterator __f, _InputIterator __l,
1758 const key_compare& __comp = key_compare())
1759 : __tree_(__vc(__comp))
1760 {
1761 insert(__f, __l);
1762 }
1763
1764 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161766 multimap(_InputIterator __f, _InputIterator __l,
1767 const key_compare& __comp, const allocator_type& __a)
1768 : __tree_(__vc(__comp), __a)
1769 {
1770 insert(__f, __l);
1771 }
1772
Marshall Clow49d596d2013-09-11 01:15:471773#if _LIBCPP_STD_VER > 11
1774 template <class _InputIterator>
1775 _LIBCPP_INLINE_VISIBILITY
1776 multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1777 : multimap(__f, __l, key_compare(), __a) {}
1778#endif
1779
Howard Hinnant82894812010-09-22 16:48:341780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161781 multimap(const multimap& __m)
1782 : __tree_(__m.__tree_.value_comp(),
1783 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
1784 {
1785 insert(__m.begin(), __m.end());
1786 }
1787
Howard Hinnant61aa6012011-07-01 19:24:361788 _LIBCPP_INLINE_VISIBILITY
1789 multimap& operator=(const multimap& __m)
1790 {
Howard Hinnant70342b92013-06-19 21:29:401791#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:361792 __tree_ = __m.__tree_;
Howard Hinnant70342b92013-06-19 21:29:401793#else
Marshall Clowebfc50e2014-02-08 04:03:141794 if (this != &__m) {
1795 __tree_.clear();
1796 __tree_.value_comp() = __m.__tree_.value_comp();
1797 __tree_.__copy_assign_alloc(__m.__tree_);
1798 insert(__m.begin(), __m.end());
1799 }
Howard Hinnant70342b92013-06-19 21:29:401800#endif
Howard Hinnant61aa6012011-07-01 19:24:361801 return *this;
1802 }
1803
Howard Hinnant73d21a42010-09-04 23:28:191804#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161805
Howard Hinnant82894812010-09-22 16:48:341806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161807 multimap(multimap&& __m)
Howard Hinnant7686add2011-06-04 14:31:571808 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:191809 : __tree_(_VSTD::move(__m.__tree_))
Howard Hinnantbc8d3f92010-05-11 19:42:161810 {
1811 }
1812
1813 multimap(multimap&& __m, const allocator_type& __a);
1814
Howard Hinnant82894812010-09-22 16:48:341815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante3e32912011-08-12 21:56:021816 multimap& operator=(multimap&& __m)
1817 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1818 {
1819 __tree_ = _VSTD::move(__m.__tree_);
1820 return *this;
1821 }
1822
1823#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1824
1825#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1826
1827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161828 multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1829 : __tree_(__vc(__comp))
1830 {
1831 insert(__il.begin(), __il.end());
1832 }
1833
Howard Hinnant82894812010-09-22 16:48:341834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161835 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1836 : __tree_(__vc(__comp), __a)
1837 {
1838 insert(__il.begin(), __il.end());
1839 }
1840
Marshall Clow49d596d2013-09-11 01:15:471841#if _LIBCPP_STD_VER > 11
1842 _LIBCPP_INLINE_VISIBILITY
1843 multimap(initializer_list<value_type> __il, const allocator_type& __a)
1844 : multimap(__il, key_compare(), __a) {}
1845#endif
1846
Howard Hinnant82894812010-09-22 16:48:341847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161848 multimap& operator=(initializer_list<value_type> __il)
1849 {
1850 __tree_.__assign_multi(__il.begin(), __il.end());
1851 return *this;
1852 }
Howard Hinnante3e32912011-08-12 21:56:021853
1854#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161855
Howard Hinnant82894812010-09-22 16:48:341856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161857 explicit multimap(const allocator_type& __a)
1858 : __tree_(__a)
1859 {
1860 }
1861
Howard Hinnant82894812010-09-22 16:48:341862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161863 multimap(const multimap& __m, const allocator_type& __a)
1864 : __tree_(__m.__tree_.value_comp(), __a)
1865 {
1866 insert(__m.begin(), __m.end());
1867 }
1868
Howard Hinnant82894812010-09-22 16:48:341869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571870 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571872 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant82894812010-09-22 16:48:341873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571874 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant82894812010-09-22 16:48:341875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571876 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:161877
Howard Hinnant82894812010-09-22 16:48:341878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571879 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571881 const_reverse_iterator rbegin() const _NOEXCEPT
1882 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:341883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571884 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:341885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571886 const_reverse_iterator rend() const _NOEXCEPT
1887 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:161888
Howard Hinnant82894812010-09-22 16:48:341889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571890 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant82894812010-09-22 16:48:341891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571892 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant82894812010-09-22 16:48:341893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571894 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant82894812010-09-22 16:48:341895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571896 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:161897
Howard Hinnant82894812010-09-22 16:48:341898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571899 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant82894812010-09-22 16:48:341900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571901 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant82894812010-09-22 16:48:341902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571903 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:161904
Howard Hinnant82894812010-09-22 16:48:341905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571906 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant82894812010-09-22 16:48:341907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571908 key_compare key_comp() const {return __tree_.value_comp().key_comp();}
Howard Hinnant82894812010-09-22 16:48:341909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571910 value_compare value_comp() const
1911 {return value_compare(__tree_.value_comp().key_comp());}
Howard Hinnantbc8d3f92010-05-11 19:42:161912
Howard Hinnant73d21a42010-09-04 23:28:191913#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:191914#ifndef _LIBCPP_HAS_NO_VARIADICS
1915
Howard Hinnant635ce1d2012-05-25 22:04:211916 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161917 iterator
Howard Hinnant635ce1d2012-05-25 22:04:211918 emplace(_Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161919
Howard Hinnant635ce1d2012-05-25 22:04:211920 template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161921 iterator
Howard Hinnant635ce1d2012-05-25 22:04:211922 emplace_hint(const_iterator __p, _Args&& ...__args);
Howard Hinnantbc8d3f92010-05-11 19:42:161923
Howard Hinnant73d21a42010-09-04 23:28:191924#endif // _LIBCPP_HAS_NO_VARIADICS
1925
Howard Hinnant99968442011-11-29 18:15:501926 template <class _Pp,
1927 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501929 iterator insert(_Pp&& __p)
1930 {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161931
Howard Hinnant99968442011-11-29 18:15:501932 template <class _Pp,
1933 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant82894812010-09-22 16:48:341934 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501935 iterator insert(const_iterator __pos, _Pp&& __p)
1936 {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
Howard Hinnantbc8d3f92010-05-11 19:42:161937
Howard Hinnant73d21a42010-09-04 23:28:191938#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161939
Howard Hinnant82894812010-09-22 16:48:341940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161941 iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
1942
Howard Hinnant82894812010-09-22 16:48:341943 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161944 iterator insert(const_iterator __p, const value_type& __v)
1945 {return __tree_.__insert_multi(__p.__i_, __v);}
1946
1947 template <class _InputIterator>
Howard Hinnant82894812010-09-22 16:48:341948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161949 void insert(_InputIterator __f, _InputIterator __l)
1950 {
1951 for (const_iterator __e = cend(); __f != __l; ++__f)
1952 __tree_.__insert_multi(__e.__i_, *__f);
1953 }
1954
Howard Hinnante3e32912011-08-12 21:56:021955#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1956
Howard Hinnant82894812010-09-22 16:48:341957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161958 void insert(initializer_list<value_type> __il)
1959 {insert(__il.begin(), __il.end());}
1960
Howard Hinnante3e32912011-08-12 21:56:021961#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1962
Howard Hinnant82894812010-09-22 16:48:341963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161964 iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
Howard Hinnant82894812010-09-22 16:48:341965 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:001966 iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
1967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161968 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:341969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161970 iterator erase(const_iterator __f, const_iterator __l)
1971 {return __tree_.erase(__f.__i_, __l.__i_);}
Howard Hinnant82894812010-09-22 16:48:341972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161973 void clear() {__tree_.clear();}
1974
Howard Hinnant82894812010-09-22 16:48:341975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7686add2011-06-04 14:31:571976 void swap(multimap& __m)
1977 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1978 {__tree_.swap(__m.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:161979
Howard Hinnant82894812010-09-22 16:48:341980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161981 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant82894812010-09-22 16:48:341982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161983 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:471984#if _LIBCPP_STD_VER > 11
1985 template <typename _K2>
1986 _LIBCPP_INLINE_VISIBILITY
1987 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1988 find(const _K2& __k) {return __tree_.find(__k);}
1989 template <typename _K2>
1990 _LIBCPP_INLINE_VISIBILITY
1991 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1992 find(const _K2& __k) const {return __tree_.find(__k);}
1993#endif
1994
Howard Hinnant82894812010-09-22 16:48:341995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161996 size_type count(const key_type& __k) const
1997 {return __tree_.__count_multi(__k);}
Marshall Clow4de32042014-08-24 23:54:161998#if _LIBCPP_STD_VER > 11
1999 template <typename _K2>
2000 _LIBCPP_INLINE_VISIBILITY
2001 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow58113db2015-06-30 18:15:412002 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clow4de32042014-08-24 23:54:162003#endif
Howard Hinnant82894812010-09-22 16:48:342004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162005 iterator lower_bound(const key_type& __k)
2006 {return __tree_.lower_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:342007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162008 const_iterator lower_bound(const key_type& __k) const
2009 {return __tree_.lower_bound(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:472010#if _LIBCPP_STD_VER > 11
2011 template <typename _K2>
2012 _LIBCPP_INLINE_VISIBILITY
2013 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2014 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
2015
2016 template <typename _K2>
2017 _LIBCPP_INLINE_VISIBILITY
2018 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2019 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
2020#endif
2021
Howard Hinnant82894812010-09-22 16:48:342022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162023 iterator upper_bound(const key_type& __k)
2024 {return __tree_.upper_bound(__k);}
Howard Hinnant82894812010-09-22 16:48:342025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162026 const_iterator upper_bound(const key_type& __k) const
2027 {return __tree_.upper_bound(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:472028#if _LIBCPP_STD_VER > 11
2029 template <typename _K2>
2030 _LIBCPP_INLINE_VISIBILITY
2031 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
2032 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
2033 template <typename _K2>
2034 _LIBCPP_INLINE_VISIBILITY
2035 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
2036 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
2037#endif
2038
Howard Hinnant82894812010-09-22 16:48:342039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162040 pair<iterator,iterator> equal_range(const key_type& __k)
2041 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant82894812010-09-22 16:48:342042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162043 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
2044 {return __tree_.__equal_range_multi(__k);}
Marshall Clow5cfc6ab2013-08-13 22:18:472045#if _LIBCPP_STD_VER > 11
2046 template <typename _K2>
2047 _LIBCPP_INLINE_VISIBILITY
2048 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
2049 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
2050 template <typename _K2>
2051 _LIBCPP_INLINE_VISIBILITY
2052 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
2053 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
2054#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162055
2056private:
2057 typedef typename __base::__node __node;
2058 typedef typename __base::__node_allocator __node_allocator;
2059 typedef typename __base::__node_pointer __node_pointer;
2060 typedef typename __base::__node_const_pointer __node_const_pointer;
Howard Hinnant99968442011-11-29 18:15:502061 typedef __map_node_destructor<__node_allocator> _Dp;
2062 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:162063
Howard Hinnant73d21a42010-09-04 23:28:192064#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162065 __node_holder __construct_node();
Howard Hinnant635ce1d2012-05-25 22:04:212066 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:162067 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:212068 __construct_node(_A0&& __a0);
Howard Hinnant73d21a42010-09-04 23:28:192069#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:212070 template <class _A0, class _A1, class ..._Args>
2071 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:192072#endif // _LIBCPP_HAS_NO_VARIADICS
2073#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162074};
2075
Howard Hinnant73d21a42010-09-04 23:28:192076#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162077
2078template <class _Key, class _Tp, class _Compare, class _Allocator>
2079multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:192080 : __tree_(_VSTD::move(__m.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:162081{
2082 if (__a != __m.get_allocator())
2083 {
2084 const_iterator __e = cend();
2085 while (!__m.empty())
2086 __tree_.__insert_multi(__e.__i_,
Howard Hinnant0949eed2011-06-30 21:18:192087 _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:162088 }
2089}
2090
2091template <class _Key, class _Tp, class _Compare, class _Allocator>
2092typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2093multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
2094{
2095 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:502096 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant70342b92013-06-19 21:29:402097 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:162098 __h.get_deleter().__first_constructed = true;
Howard Hinnant70342b92013-06-19 21:29:402099 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:162100 __h.get_deleter().__second_constructed = true;
2101 return __h;
2102}
2103
2104template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:212105template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:162106typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:162107multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
2108{
2109 __node_allocator& __na = __tree_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:502110 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:192111 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:162112 __h.get_deleter().__first_constructed = true;
2113 __h.get_deleter().__second_constructed = true;
2114 return __h;
2115}
2116
Howard Hinnant635ce1d2012-05-25 22:04:212117#ifndef _LIBCPP_HAS_NO_VARIADICS
2118
2119template <class _Key, class _Tp, class _Compare, class _Allocator>
2120template <class _A0, class _A1, class ..._Args>
2121typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
2122multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
2123{
2124 __node_allocator& __na = __tree_.__node_alloc();
2125 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2126 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2127 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
2128 _VSTD::forward<_Args>(__args)...);
2129 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:162130 __h.get_deleter().__second_constructed = true;
2131 return __h;
2132}
2133
Howard Hinnant73d21a42010-09-04 23:28:192134#endif // _LIBCPP_HAS_NO_VARIADICS
2135#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162136
Howard Hinnant73d21a42010-09-04 23:28:192137#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:162138
2139template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:212140template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:162141typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
Howard Hinnant635ce1d2012-05-25 22:04:212142multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
Howard Hinnantbc8d3f92010-05-11 19:42:162143{
Howard Hinnant635ce1d2012-05-25 22:04:212144 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162145 iterator __r = __tree_.__node_insert_multi(__h.get());
2146 __h.release();
2147 return __r;
2148}
2149
2150template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant635ce1d2012-05-25 22:04:212151template <class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:162152typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
2153multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
Howard Hinnantbc8d3f92010-05-11 19:42:162154 _Args&& ...__args)
2155{
Howard Hinnant635ce1d2012-05-25 22:04:212156 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162157 iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
2158 __h.release();
2159 return __r;
2160}
2161
Howard Hinnant73d21a42010-09-04 23:28:192162#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:162163
2164template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342165inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162166bool
2167operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2168 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2169{
Howard Hinnant0949eed2011-06-30 21:18:192170 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:162171}
2172
2173template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342174inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162175bool
2176operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2177 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2178{
Howard Hinnant0949eed2011-06-30 21:18:192179 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:162180}
2181
2182template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342183inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162184bool
2185operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2186 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2187{
2188 return !(__x == __y);
2189}
2190
2191template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162193bool
2194operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2195 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2196{
2197 return __y < __x;
2198}
2199
2200template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162202bool
2203operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2204 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2205{
2206 return !(__x < __y);
2207}
2208
2209template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342210inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162211bool
2212operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2213 const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2214{
2215 return !(__y < __x);
2216}
2217
2218template <class _Key, class _Tp, class _Compare, class _Allocator>
Howard Hinnant82894812010-09-22 16:48:342219inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162220void
2221swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2222 multimap<_Key, _Tp, _Compare, _Allocator>& __y)
Howard Hinnant7686add2011-06-04 14:31:572223 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:162224{
2225 __x.swap(__y);
2226}
2227
2228_LIBCPP_END_NAMESPACE_STD
2229
2230#endif // _LIBCPP_MAP