Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------- map ------------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_MAP |
| 11 | #define _LIBCPP_MAP |
| 12 | |
| 13 | /* |
| 14 | |
| 15 | map synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class Key, class T, class Compare = less<Key>, |
| 21 | class Allocator = allocator<pair<const Key, T>>> |
| 22 | class map |
| 23 | { |
| 24 | public: |
| 25 | // types: |
| 26 | typedef Key key_type; |
| 27 | typedef T mapped_type; |
| 28 | typedef pair<const key_type, mapped_type> value_type; |
| 29 | typedef Compare key_compare; |
| 30 | typedef Allocator allocator_type; |
| 31 | typedef typename allocator_type::reference reference; |
| 32 | typedef typename allocator_type::const_reference const_reference; |
| 33 | typedef typename allocator_type::pointer pointer; |
| 34 | typedef typename allocator_type::const_pointer const_pointer; |
| 35 | typedef typename allocator_type::size_type size_type; |
| 36 | typedef typename allocator_type::difference_type difference_type; |
| 37 | |
| 38 | typedef implementation-defined iterator; |
| 39 | typedef implementation-defined const_iterator; |
| 40 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 41 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 42 | typedef unspecified node_type; // C++17 |
| 43 | typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 44 | |
| 45 | class value_compare |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 46 | { |
| 47 | friend class map; |
| 48 | protected: |
| 49 | key_compare comp; |
| 50 | |
| 51 | value_compare(key_compare c); |
| 52 | public: |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 53 | typedef bool result_type; // deprecated in C++17, removed in C++20 |
| 54 | typedef value_type first_argument_type; // deprecated in C++17, removed in C++20 |
| 55 | typedef value_type second_argument_type; // deprecated in C++17, removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | bool operator()(const value_type& x, const value_type& y) const; |
| 57 | }; |
| 58 | |
| 59 | // construct/copy/destroy: |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 60 | map() |
| 61 | noexcept( |
| 62 | is_nothrow_default_constructible<allocator_type>::value && |
| 63 | is_nothrow_default_constructible<key_compare>::value && |
| 64 | is_nothrow_copy_constructible<key_compare>::value); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 65 | explicit map(const key_compare& comp); |
| 66 | map(const key_compare& comp, const allocator_type& a); |
| 67 | template <class InputIterator> |
| 68 | map(InputIterator first, InputIterator last, |
| 69 | const key_compare& comp = key_compare()); |
| 70 | template <class InputIterator> |
| 71 | map(InputIterator first, InputIterator last, |
| 72 | const key_compare& comp, const allocator_type& a); |
| 73 | map(const map& m); |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 74 | map(map&& m) |
| 75 | noexcept( |
| 76 | is_nothrow_move_constructible<allocator_type>::value && |
| 77 | is_nothrow_move_constructible<key_compare>::value); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 78 | explicit map(const allocator_type& a); |
| 79 | map(const map& m, const allocator_type& a); |
| 80 | map(map&& m, const allocator_type& a); |
| 81 | map(initializer_list<value_type> il, const key_compare& comp = key_compare()); |
| 82 | map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 83 | template <class InputIterator> |
| 84 | map(InputIterator first, InputIterator last, const allocator_type& a) |
| 85 | : map(first, last, Compare(), a) {} // C++14 |
| 86 | map(initializer_list<value_type> il, const allocator_type& a) |
| 87 | : map(il, Compare(), a) {} // C++14 |
| 88 | ~map(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 89 | |
| 90 | map& operator=(const map& m); |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 91 | map& operator=(map&& m) |
| 92 | noexcept( |
| 93 | allocator_type::propagate_on_container_move_assignment::value && |
| 94 | is_nothrow_move_assignable<allocator_type>::value && |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 95 | is_nothrow_move_assignable<key_compare>::value); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 96 | map& operator=(initializer_list<value_type> il); |
| 97 | |
| 98 | // iterators: |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 99 | iterator begin() noexcept; |
| 100 | const_iterator begin() const noexcept; |
| 101 | iterator end() noexcept; |
| 102 | const_iterator end() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 103 | |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 104 | reverse_iterator rbegin() noexcept; |
| 105 | const_reverse_iterator rbegin() const noexcept; |
| 106 | reverse_iterator rend() noexcept; |
| 107 | const_reverse_iterator rend() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 108 | |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 109 | const_iterator cbegin() const noexcept; |
| 110 | const_iterator cend() const noexcept; |
| 111 | const_reverse_iterator crbegin() const noexcept; |
| 112 | const_reverse_iterator crend() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 113 | |
| 114 | // capacity: |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 115 | bool empty() const noexcept; |
| 116 | size_type size() const noexcept; |
| 117 | size_type max_size() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 118 | |
| 119 | // element access: |
| 120 | mapped_type& operator[](const key_type& k); |
| 121 | mapped_type& operator[](key_type&& k); |
| 122 | |
| 123 | mapped_type& at(const key_type& k); |
| 124 | const mapped_type& at(const key_type& k) const; |
| 125 | |
| 126 | // modifiers: |
| 127 | template <class... Args> |
| 128 | pair<iterator, bool> emplace(Args&&... args); |
| 129 | template <class... Args> |
| 130 | iterator emplace_hint(const_iterator position, Args&&... args); |
| 131 | pair<iterator, bool> insert(const value_type& v); |
Marshall Clow | d430d02 | 2016-01-05 19:32:41 +0000 | [diff] [blame] | 132 | pair<iterator, bool> insert( value_type&& v); // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 133 | template <class P> |
| 134 | pair<iterator, bool> insert(P&& p); |
| 135 | iterator insert(const_iterator position, const value_type& v); |
Marshall Clow | d430d02 | 2016-01-05 19:32:41 +0000 | [diff] [blame] | 136 | iterator insert(const_iterator position, value_type&& v); // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 137 | template <class P> |
| 138 | iterator insert(const_iterator position, P&& p); |
| 139 | template <class InputIterator> |
| 140 | void insert(InputIterator first, InputIterator last); |
| 141 | void insert(initializer_list<value_type> il); |
| 142 | |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 143 | node_type extract(const_iterator position); // C++17 |
| 144 | node_type extract(const key_type& x); // C++17 |
| 145 | insert_return_type insert(node_type&& nh); // C++17 |
| 146 | iterator insert(const_iterator hint, node_type&& nh); // C++17 |
| 147 | |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 148 | template <class... Args> |
| 149 | pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17 |
| 150 | template <class... Args> |
| 151 | pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17 |
| 152 | template <class... Args> |
| 153 | iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17 |
| 154 | template <class... Args> |
| 155 | iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17 |
| 156 | template <class M> |
| 157 | pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17 |
| 158 | template <class M> |
| 159 | pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17 |
| 160 | template <class M> |
| 161 | iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17 |
| 162 | template <class M> |
| 163 | iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17 |
| 164 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 165 | iterator erase(const_iterator position); |
Marshall Clow | 22ea5b8 | 2015-05-10 13:35:00 +0000 | [diff] [blame] | 166 | iterator erase(iterator position); // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 167 | size_type erase(const key_type& k); |
| 168 | iterator erase(const_iterator first, const_iterator last); |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 169 | void clear() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 170 | |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 171 | template<class C2> |
| 172 | void merge(map<Key, T, C2, Allocator>& source); // C++17 |
| 173 | template<class C2> |
| 174 | void merge(map<Key, T, C2, Allocator>&& source); // C++17 |
| 175 | template<class C2> |
| 176 | void merge(multimap<Key, T, C2, Allocator>& source); // C++17 |
| 177 | template<class C2> |
| 178 | void merge(multimap<Key, T, C2, Allocator>&& source); // C++17 |
| 179 | |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 180 | void swap(map& m) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 181 | noexcept(allocator_traits<allocator_type>::is_always_equal::value && |
Eric Fiselier | 6bfed25 | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 182 | is_nothrow_swappable<key_compare>::value); // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 183 | |
| 184 | // observers: |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 185 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | key_compare key_comp() const; |
| 187 | value_compare value_comp() const; |
| 188 | |
| 189 | // map operations: |
| 190 | iterator find(const key_type& k); |
| 191 | const_iterator find(const key_type& k) const; |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 192 | template<typename K> |
| 193 | iterator find(const K& x); // C++14 |
| 194 | template<typename K> |
| 195 | const_iterator find(const K& x) const; // C++14 |
Marek Kurdej | d7e019e | 2021-04-13 17:10:55 +0200 | [diff] [blame] | 196 | |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 197 | template<typename K> |
Marshall Clow | e6a5f52 | 2014-08-24 23:54:16 +0000 | [diff] [blame] | 198 | size_type count(const K& x) const; // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 199 | size_type count(const key_type& k) const; |
Marek Kurdej | d7e019e | 2021-04-13 17:10:55 +0200 | [diff] [blame] | 200 | |
| 201 | bool contains(const key_type& x) const; // C++20 |
| 202 | template<class K> bool contains(const K& x) const; // C++20 |
| 203 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 204 | iterator lower_bound(const key_type& k); |
| 205 | const_iterator lower_bound(const key_type& k) const; |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 206 | template<typename K> |
| 207 | iterator lower_bound(const K& x); // C++14 |
| 208 | template<typename K> |
| 209 | const_iterator lower_bound(const K& x) const; // C++14 |
| 210 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 211 | iterator upper_bound(const key_type& k); |
| 212 | const_iterator upper_bound(const key_type& k) const; |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 213 | template<typename K> |
| 214 | iterator upper_bound(const K& x); // C++14 |
| 215 | template<typename K> |
| 216 | const_iterator upper_bound(const K& x) const; // C++14 |
| 217 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 218 | pair<iterator,iterator> equal_range(const key_type& k); |
| 219 | pair<const_iterator,const_iterator> equal_range(const key_type& k) const; |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 220 | template<typename K> |
| 221 | pair<iterator,iterator> equal_range(const K& x); // C++14 |
| 222 | template<typename K> |
| 223 | pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | template <class Key, class T, class Compare, class Allocator> |
| 227 | bool |
| 228 | operator==(const map<Key, T, Compare, Allocator>& x, |
| 229 | const map<Key, T, Compare, Allocator>& y); |
| 230 | |
| 231 | template <class Key, class T, class Compare, class Allocator> |
| 232 | bool |
| 233 | operator< (const map<Key, T, Compare, Allocator>& x, |
| 234 | const map<Key, T, Compare, Allocator>& y); |
| 235 | |
| 236 | template <class Key, class T, class Compare, class Allocator> |
| 237 | bool |
| 238 | operator!=(const map<Key, T, Compare, Allocator>& x, |
| 239 | const map<Key, T, Compare, Allocator>& y); |
| 240 | |
| 241 | template <class Key, class T, class Compare, class Allocator> |
| 242 | bool |
| 243 | operator> (const map<Key, T, Compare, Allocator>& x, |
| 244 | const map<Key, T, Compare, Allocator>& y); |
| 245 | |
| 246 | template <class Key, class T, class Compare, class Allocator> |
| 247 | bool |
| 248 | operator>=(const map<Key, T, Compare, Allocator>& x, |
| 249 | const map<Key, T, Compare, Allocator>& y); |
| 250 | |
| 251 | template <class Key, class T, class Compare, class Allocator> |
| 252 | bool |
| 253 | operator<=(const map<Key, T, Compare, Allocator>& x, |
| 254 | const map<Key, T, Compare, Allocator>& y); |
| 255 | |
| 256 | // specialized algorithms: |
| 257 | template <class Key, class T, class Compare, class Allocator> |
| 258 | void |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 259 | swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y) |
| 260 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 261 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 262 | template <class Key, class T, class Compare, class Allocator, class Predicate> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 263 | typename map<Key, T, Compare, Allocator>::size_type |
| 264 | erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 265 | |
| 266 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 267 | template <class Key, class T, class Compare = less<Key>, |
| 268 | class Allocator = allocator<pair<const Key, T>>> |
| 269 | class multimap |
| 270 | { |
| 271 | public: |
| 272 | // types: |
| 273 | typedef Key key_type; |
| 274 | typedef T mapped_type; |
| 275 | typedef pair<const key_type,mapped_type> value_type; |
| 276 | typedef Compare key_compare; |
| 277 | typedef Allocator allocator_type; |
| 278 | typedef typename allocator_type::reference reference; |
| 279 | typedef typename allocator_type::const_reference const_reference; |
| 280 | typedef typename allocator_type::size_type size_type; |
| 281 | typedef typename allocator_type::difference_type difference_type; |
| 282 | typedef typename allocator_type::pointer pointer; |
| 283 | typedef typename allocator_type::const_pointer const_pointer; |
| 284 | |
| 285 | typedef implementation-defined iterator; |
| 286 | typedef implementation-defined const_iterator; |
| 287 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 288 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 289 | typedef unspecified node_type; // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 290 | |
| 291 | class value_compare |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 292 | { |
| 293 | friend class multimap; |
| 294 | protected: |
| 295 | key_compare comp; |
| 296 | value_compare(key_compare c); |
| 297 | public: |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 298 | typedef bool result_type; // deprecated in C++17, removed in C++20 |
| 299 | typedef value_type first_argument_type; // deprecated in C++17, removed in C++20 |
| 300 | typedef value_type second_argument_type; // deprecated in C++17, removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 301 | bool operator()(const value_type& x, const value_type& y) const; |
| 302 | }; |
| 303 | |
| 304 | // construct/copy/destroy: |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 305 | multimap() |
| 306 | noexcept( |
| 307 | is_nothrow_default_constructible<allocator_type>::value && |
| 308 | is_nothrow_default_constructible<key_compare>::value && |
| 309 | is_nothrow_copy_constructible<key_compare>::value); |
| 310 | explicit multimap(const key_compare& comp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 311 | multimap(const key_compare& comp, const allocator_type& a); |
| 312 | template <class InputIterator> |
| 313 | multimap(InputIterator first, InputIterator last, const key_compare& comp); |
| 314 | template <class InputIterator> |
| 315 | multimap(InputIterator first, InputIterator last, const key_compare& comp, |
| 316 | const allocator_type& a); |
| 317 | multimap(const multimap& m); |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 318 | multimap(multimap&& m) |
| 319 | noexcept( |
| 320 | is_nothrow_move_constructible<allocator_type>::value && |
| 321 | is_nothrow_move_constructible<key_compare>::value); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 322 | explicit multimap(const allocator_type& a); |
| 323 | multimap(const multimap& m, const allocator_type& a); |
| 324 | multimap(multimap&& m, const allocator_type& a); |
| 325 | multimap(initializer_list<value_type> il, const key_compare& comp = key_compare()); |
| 326 | multimap(initializer_list<value_type> il, const key_compare& comp, |
| 327 | const allocator_type& a); |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 328 | template <class InputIterator> |
| 329 | multimap(InputIterator first, InputIterator last, const allocator_type& a) |
| 330 | : multimap(first, last, Compare(), a) {} // C++14 |
| 331 | multimap(initializer_list<value_type> il, const allocator_type& a) |
| 332 | : multimap(il, Compare(), a) {} // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 333 | ~multimap(); |
| 334 | |
| 335 | multimap& operator=(const multimap& m); |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 336 | multimap& operator=(multimap&& m) |
| 337 | noexcept( |
| 338 | allocator_type::propagate_on_container_move_assignment::value && |
| 339 | is_nothrow_move_assignable<allocator_type>::value && |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 340 | is_nothrow_move_assignable<key_compare>::value); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 341 | multimap& operator=(initializer_list<value_type> il); |
| 342 | |
| 343 | // iterators: |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 344 | iterator begin() noexcept; |
| 345 | const_iterator begin() const noexcept; |
| 346 | iterator end() noexcept; |
| 347 | const_iterator end() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 348 | |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 349 | reverse_iterator rbegin() noexcept; |
| 350 | const_reverse_iterator rbegin() const noexcept; |
| 351 | reverse_iterator rend() noexcept; |
| 352 | const_reverse_iterator rend() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 353 | |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 354 | const_iterator cbegin() const noexcept; |
| 355 | const_iterator cend() const noexcept; |
| 356 | const_reverse_iterator crbegin() const noexcept; |
| 357 | const_reverse_iterator crend() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 358 | |
| 359 | // capacity: |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 360 | bool empty() const noexcept; |
| 361 | size_type size() const noexcept; |
| 362 | size_type max_size() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 363 | |
| 364 | // modifiers: |
| 365 | template <class... Args> |
| 366 | iterator emplace(Args&&... args); |
| 367 | template <class... Args> |
| 368 | iterator emplace_hint(const_iterator position, Args&&... args); |
| 369 | iterator insert(const value_type& v); |
Marshall Clow | d430d02 | 2016-01-05 19:32:41 +0000 | [diff] [blame] | 370 | iterator insert( value_type&& v); // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | template <class P> |
| 372 | iterator insert(P&& p); |
| 373 | iterator insert(const_iterator position, const value_type& v); |
Marshall Clow | d430d02 | 2016-01-05 19:32:41 +0000 | [diff] [blame] | 374 | iterator insert(const_iterator position, value_type&& v); // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 | template <class P> |
| 376 | iterator insert(const_iterator position, P&& p); |
| 377 | template <class InputIterator> |
| 378 | void insert(InputIterator first, InputIterator last); |
| 379 | void insert(initializer_list<value_type> il); |
| 380 | |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 381 | node_type extract(const_iterator position); // C++17 |
| 382 | node_type extract(const key_type& x); // C++17 |
| 383 | iterator insert(node_type&& nh); // C++17 |
| 384 | iterator insert(const_iterator hint, node_type&& nh); // C++17 |
| 385 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | iterator erase(const_iterator position); |
Marshall Clow | 22ea5b8 | 2015-05-10 13:35:00 +0000 | [diff] [blame] | 387 | iterator erase(iterator position); // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 388 | size_type erase(const key_type& k); |
| 389 | iterator erase(const_iterator first, const_iterator last); |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 390 | void clear() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 392 | template<class C2> |
| 393 | void merge(multimap<Key, T, C2, Allocator>& source); // C++17 |
| 394 | template<class C2> |
| 395 | void merge(multimap<Key, T, C2, Allocator>&& source); // C++17 |
| 396 | template<class C2> |
| 397 | void merge(map<Key, T, C2, Allocator>& source); // C++17 |
| 398 | template<class C2> |
| 399 | void merge(map<Key, T, C2, Allocator>&& source); // C++17 |
| 400 | |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 401 | void swap(multimap& m) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 402 | noexcept(allocator_traits<allocator_type>::is_always_equal::value && |
Eric Fiselier | 6bfed25 | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 403 | is_nothrow_swappable<key_compare>::value); // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | |
| 405 | // observers: |
Howard Hinnant | f95f4f5 | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 406 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | key_compare key_comp() const; |
| 408 | value_compare value_comp() const; |
| 409 | |
| 410 | // map operations: |
| 411 | iterator find(const key_type& k); |
| 412 | const_iterator find(const key_type& k) const; |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 413 | template<typename K> |
| 414 | iterator find(const K& x); // C++14 |
| 415 | template<typename K> |
| 416 | const_iterator find(const K& x) const; // C++14 |
Marek Kurdej | d7e019e | 2021-04-13 17:10:55 +0200 | [diff] [blame] | 417 | |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 418 | template<typename K> |
Marshall Clow | e6a5f52 | 2014-08-24 23:54:16 +0000 | [diff] [blame] | 419 | size_type count(const K& x) const; // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 420 | size_type count(const key_type& k) const; |
Marek Kurdej | d7e019e | 2021-04-13 17:10:55 +0200 | [diff] [blame] | 421 | |
| 422 | bool contains(const key_type& x) const; // C++20 |
| 423 | template<class K> bool contains(const K& x) const; // C++20 |
| 424 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 425 | iterator lower_bound(const key_type& k); |
| 426 | const_iterator lower_bound(const key_type& k) const; |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 427 | template<typename K> |
| 428 | iterator lower_bound(const K& x); // C++14 |
| 429 | template<typename K> |
| 430 | const_iterator lower_bound(const K& x) const; // C++14 |
| 431 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 432 | iterator upper_bound(const key_type& k); |
| 433 | const_iterator upper_bound(const key_type& k) const; |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 434 | template<typename K> |
| 435 | iterator upper_bound(const K& x); // C++14 |
| 436 | template<typename K> |
| 437 | const_iterator upper_bound(const K& x) const; // C++14 |
| 438 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 439 | pair<iterator,iterator> equal_range(const key_type& k); |
| 440 | pair<const_iterator,const_iterator> equal_range(const key_type& k) const; |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 441 | template<typename K> |
| 442 | pair<iterator,iterator> equal_range(const K& x); // C++14 |
| 443 | template<typename K> |
| 444 | pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | template <class Key, class T, class Compare, class Allocator> |
| 448 | bool |
| 449 | operator==(const multimap<Key, T, Compare, Allocator>& x, |
| 450 | const multimap<Key, T, Compare, Allocator>& y); |
| 451 | |
| 452 | template <class Key, class T, class Compare, class Allocator> |
| 453 | bool |
| 454 | operator< (const multimap<Key, T, Compare, Allocator>& x, |
| 455 | const multimap<Key, T, Compare, Allocator>& y); |
| 456 | |
| 457 | template <class Key, class T, class Compare, class Allocator> |
| 458 | bool |
| 459 | operator!=(const multimap<Key, T, Compare, Allocator>& x, |
| 460 | const multimap<Key, T, Compare, Allocator>& y); |
| 461 | |
| 462 | template <class Key, class T, class Compare, class Allocator> |
| 463 | bool |
| 464 | operator> (const multimap<Key, T, Compare, Allocator>& x, |
| 465 | const multimap<Key, T, Compare, Allocator>& y); |
| 466 | |
| 467 | template <class Key, class T, class Compare, class Allocator> |
| 468 | bool |
| 469 | operator>=(const multimap<Key, T, Compare, Allocator>& x, |
| 470 | const multimap<Key, T, Compare, Allocator>& y); |
| 471 | |
| 472 | template <class Key, class T, class Compare, class Allocator> |
| 473 | bool |
| 474 | operator<=(const multimap<Key, T, Compare, Allocator>& x, |
| 475 | const multimap<Key, T, Compare, Allocator>& y); |
| 476 | |
| 477 | // specialized algorithms: |
| 478 | template <class Key, class T, class Compare, class Allocator> |
| 479 | void |
| 480 | swap(multimap<Key, T, Compare, Allocator>& x, |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 481 | multimap<Key, T, Compare, Allocator>& y) |
| 482 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 483 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 484 | template <class Key, class T, class Compare, class Allocator, class Predicate> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 485 | typename multimap<Key, T, Compare, Allocator>::size_type |
| 486 | erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 487 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 488 | } // std |
| 489 | |
| 490 | */ |
| 491 | |
| 492 | #include <__config> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 493 | #include <__debug> |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 494 | #include <__node_handle> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 495 | #include <__tree> |
Christopher Di Bella | 41f26e8 | 2021-06-05 02:47:47 +0000 | [diff] [blame] | 496 | #include <__utility/forward.h> |
Arthur O'Dwyer | 7deec12 | 2021-03-24 18:19:12 -0400 | [diff] [blame] | 497 | #include <compare> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 498 | #include <functional> |
Arthur O'Dwyer | 7deec12 | 2021-03-24 18:19:12 -0400 | [diff] [blame] | 499 | #include <initializer_list> |
Arthur O'Dwyer | b6738bd | 2021-03-21 16:53:09 -0400 | [diff] [blame] | 500 | #include <iterator> // __libcpp_erase_if_container |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 501 | #include <memory> |
Eric Fiselier | f739430 | 2015-06-13 07:08:02 +0000 | [diff] [blame] | 502 | #include <type_traits> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 503 | #include <utility> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 504 | #include <version> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 505 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 506 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 507 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 508 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 509 | |
| 510 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 511 | |
Louis Dionne | 878a3a8 | 2018-12-06 21:46:17 +0000 | [diff] [blame] | 512 | template <class _Key, class _CP, class _Compare, |
| 513 | bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 514 | class __map_value_compare |
| 515 | : private _Compare |
| 516 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 517 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 518 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 519 | __map_value_compare() |
| 520 | _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) |
| 521 | : _Compare() {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 522 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 523 | __map_value_compare(_Compare c) |
| 524 | _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) |
| 525 | : _Compare(c) {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 526 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 527 | const _Compare& key_comp() const _NOEXCEPT {return *this;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 528 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 529 | bool operator()(const _CP& __x, const _CP& __y) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 530 | {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 531 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | bool operator()(const _CP& __x, const _Key& __y) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 533 | {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 534 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 535 | bool operator()(const _Key& __x, const _CP& __y) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 536 | {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);} |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 537 | void swap(__map_value_compare&__y) |
| 538 | _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) |
| 539 | { |
Eric Fiselier | 68b5f0b | 2017-04-13 00:34:24 +0000 | [diff] [blame] | 540 | using _VSTD::swap; |
| 541 | swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y)); |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 542 | } |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 543 | |
| 544 | #if _LIBCPP_STD_VER > 11 |
| 545 | template <typename _K2> |
| 546 | _LIBCPP_INLINE_VISIBILITY |
| 547 | typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type |
| 548 | operator () ( const _K2& __x, const _CP& __y ) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 549 | {return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 550 | |
| 551 | template <typename _K2> |
| 552 | _LIBCPP_INLINE_VISIBILITY |
| 553 | typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type |
| 554 | operator () (const _CP& __x, const _K2& __y) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 555 | {return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 556 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | }; |
| 558 | |
Howard Hinnant | 90b9159 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 559 | template <class _Key, class _CP, class _Compare> |
| 560 | class __map_value_compare<_Key, _CP, _Compare, false> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | { |
| 562 | _Compare comp; |
| 563 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 564 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 566 | __map_value_compare() |
| 567 | _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) |
| 568 | : comp() {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 569 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 570 | __map_value_compare(_Compare c) |
| 571 | _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) |
| 572 | : comp(c) {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 573 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 574 | const _Compare& key_comp() const _NOEXCEPT {return comp;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 577 | bool operator()(const _CP& __x, const _CP& __y) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 578 | {return comp(__x.__get_value().first, __y.__get_value().first);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 579 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | bool operator()(const _CP& __x, const _Key& __y) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 581 | {return comp(__x.__get_value().first, __y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 582 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 583 | bool operator()(const _Key& __x, const _CP& __y) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 584 | {return comp(__x, __y.__get_value().first);} |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 585 | void swap(__map_value_compare&__y) |
| 586 | _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) |
| 587 | { |
| 588 | using _VSTD::swap; |
| 589 | swap(comp, __y.comp); |
| 590 | } |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 591 | |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 592 | #if _LIBCPP_STD_VER > 11 |
| 593 | template <typename _K2> |
| 594 | _LIBCPP_INLINE_VISIBILITY |
| 595 | typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type |
| 596 | operator () ( const _K2& __x, const _CP& __y ) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 597 | {return comp (__x, __y.__get_value().first);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 598 | |
| 599 | template <typename _K2> |
| 600 | _LIBCPP_INLINE_VISIBILITY |
| 601 | typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type |
| 602 | operator () (const _CP& __x, const _K2& __y) const |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 603 | {return comp (__x.__get_value().first, __y);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 604 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 605 | }; |
| 606 | |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 607 | template <class _Key, class _CP, class _Compare, bool __b> |
| 608 | inline _LIBCPP_INLINE_VISIBILITY |
| 609 | void |
| 610 | swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x, |
| 611 | __map_value_compare<_Key, _CP, _Compare, __b>& __y) |
| 612 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
| 613 | { |
| 614 | __x.swap(__y); |
| 615 | } |
| 616 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 617 | template <class _Allocator> |
| 618 | class __map_node_destructor |
| 619 | { |
| 620 | typedef _Allocator allocator_type; |
| 621 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | a00b484 | 2016-02-20 05:28:30 +0000 | [diff] [blame] | 622 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 623 | public: |
| 624 | typedef typename __alloc_traits::pointer pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 625 | |
Eric Fiselier | a00b484 | 2016-02-20 05:28:30 +0000 | [diff] [blame] | 626 | private: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 627 | allocator_type& __na_; |
| 628 | |
| 629 | __map_node_destructor& operator=(const __map_node_destructor&); |
| 630 | |
| 631 | public: |
| 632 | bool __first_constructed; |
| 633 | bool __second_constructed; |
| 634 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 635 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 636 | explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 637 | : __na_(__na), |
| 638 | __first_constructed(false), |
| 639 | __second_constructed(false) |
| 640 | {} |
| 641 | |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 642 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 643 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 644 | __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 645 | : __na_(__x.__na_), |
| 646 | __first_constructed(__x.__value_constructed), |
| 647 | __second_constructed(__x.__value_constructed) |
| 648 | { |
| 649 | __x.__value_constructed = false; |
| 650 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 651 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 652 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 653 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 654 | void operator()(pointer __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 655 | { |
| 656 | if (__second_constructed) |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 657 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | if (__first_constructed) |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 659 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 660 | if (__p) |
| 661 | __alloc_traits::deallocate(__na_, __p, 1); |
| 662 | } |
| 663 | }; |
| 664 | |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 665 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 666 | class map; |
| 667 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 668 | class multimap; |
| 669 | template <class _TreeIterator> class __map_const_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 670 | |
Eric Fiselier | a00b484 | 2016-02-20 05:28:30 +0000 | [diff] [blame] | 671 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 672 | |
| 673 | template <class _Key, class _Tp> |
Amy Huang | 63f53b5 | 2021-03-15 14:20:49 -0700 | [diff] [blame] | 674 | struct _LIBCPP_STANDALONE_DEBUG __value_type |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 675 | { |
| 676 | typedef _Key key_type; |
| 677 | typedef _Tp mapped_type; |
| 678 | typedef pair<const key_type, mapped_type> value_type; |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 679 | typedef pair<key_type&, mapped_type&> __nc_ref_pair_type; |
| 680 | typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type; |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 681 | |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 682 | private: |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 683 | value_type __cc; |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 684 | |
| 685 | public: |
| 686 | _LIBCPP_INLINE_VISIBILITY |
| 687 | value_type& __get_value() |
| 688 | { |
| 689 | #if _LIBCPP_STD_VER > 14 |
| 690 | return *_VSTD::launder(_VSTD::addressof(__cc)); |
| 691 | #else |
| 692 | return __cc; |
| 693 | #endif |
| 694 | } |
| 695 | |
| 696 | _LIBCPP_INLINE_VISIBILITY |
| 697 | const value_type& __get_value() const |
| 698 | { |
| 699 | #if _LIBCPP_STD_VER > 14 |
| 700 | return *_VSTD::launder(_VSTD::addressof(__cc)); |
| 701 | #else |
| 702 | return __cc; |
| 703 | #endif |
| 704 | } |
| 705 | |
| 706 | _LIBCPP_INLINE_VISIBILITY |
| 707 | __nc_ref_pair_type __ref() |
| 708 | { |
| 709 | value_type& __v = __get_value(); |
| 710 | return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second); |
| 711 | } |
| 712 | |
| 713 | _LIBCPP_INLINE_VISIBILITY |
| 714 | __nc_rref_pair_type __move() |
| 715 | { |
| 716 | value_type& __v = __get_value(); |
| 717 | return __nc_rref_pair_type( |
| 718 | _VSTD::move(const_cast<key_type&>(__v.first)), |
| 719 | _VSTD::move(__v.second)); |
| 720 | } |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 721 | |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 722 | _LIBCPP_INLINE_VISIBILITY |
| 723 | __value_type& operator=(const __value_type& __v) |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 724 | { |
| 725 | __ref() = __v.__get_value(); |
| 726 | return *this; |
| 727 | } |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 728 | |
| 729 | _LIBCPP_INLINE_VISIBILITY |
| 730 | __value_type& operator=(__value_type&& __v) |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 731 | { |
| 732 | __ref() = __v.__move(); |
| 733 | return *this; |
| 734 | } |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 735 | |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 736 | template <class _ValueTp, |
| 737 | class = typename enable_if< |
| 738 | __is_same_uncvref<_ValueTp, value_type>::value |
| 739 | >::type |
| 740 | > |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 741 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 742 | __value_type& operator=(_ValueTp&& __v) |
| 743 | { |
| 744 | __ref() = _VSTD::forward<_ValueTp>(__v); |
| 745 | return *this; |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | private: |
| 749 | __value_type() _LIBCPP_EQUAL_DELETE; |
| 750 | ~__value_type() _LIBCPP_EQUAL_DELETE; |
| 751 | __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE; |
| 752 | __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE; |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 753 | }; |
| 754 | |
| 755 | #else |
| 756 | |
| 757 | template <class _Key, class _Tp> |
| 758 | struct __value_type |
| 759 | { |
| 760 | typedef _Key key_type; |
| 761 | typedef _Tp mapped_type; |
| 762 | typedef pair<const key_type, mapped_type> value_type; |
| 763 | |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 764 | private: |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 765 | value_type __cc; |
| 766 | |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 767 | public: |
| 768 | _LIBCPP_INLINE_VISIBILITY |
| 769 | value_type& __get_value() { return __cc; } |
| 770 | _LIBCPP_INLINE_VISIBILITY |
| 771 | const value_type& __get_value() const { return __cc; } |
| 772 | |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 773 | private: |
| 774 | __value_type(); |
| 775 | __value_type(__value_type const&); |
| 776 | __value_type& operator=(__value_type const&); |
| 777 | ~__value_type(); |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 778 | }; |
| 779 | |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 780 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 781 | |
Eric Fiselier | 44f9fd0 | 2015-03-03 20:10:01 +0000 | [diff] [blame] | 782 | template <class _Tp> |
| 783 | struct __extract_key_value_types; |
| 784 | |
| 785 | template <class _Key, class _Tp> |
| 786 | struct __extract_key_value_types<__value_type<_Key, _Tp> > |
| 787 | { |
| 788 | typedef _Key const __key_type; |
| 789 | typedef _Tp __mapped_type; |
| 790 | }; |
| 791 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 792 | template <class _TreeIterator> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 793 | class _LIBCPP_TEMPLATE_VIS __map_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 794 | { |
Eric Fiselier | a00b484 | 2016-02-20 05:28:30 +0000 | [diff] [blame] | 795 | typedef typename _TreeIterator::_NodeTypes _NodeTypes; |
| 796 | typedef typename _TreeIterator::__pointer_traits __pointer_traits; |
| 797 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 798 | _TreeIterator __i_; |
| 799 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 800 | public: |
| 801 | typedef bidirectional_iterator_tag iterator_category; |
Eric Fiselier | a00b484 | 2016-02-20 05:28:30 +0000 | [diff] [blame] | 802 | typedef typename _NodeTypes::__map_value_type value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 803 | typedef typename _TreeIterator::difference_type difference_type; |
| 804 | typedef value_type& reference; |
Eric Fiselier | a00b484 | 2016-02-20 05:28:30 +0000 | [diff] [blame] | 805 | typedef typename _NodeTypes::__map_value_type_pointer pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 806 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 807 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 808 | __map_iterator() _NOEXCEPT {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 809 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 810 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 811 | __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 812 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 813 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 814 | reference operator*() const {return __i_->__get_value();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 815 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 816 | pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 817 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 818 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 819 | __map_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 820 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 821 | __map_iterator operator++(int) |
| 822 | { |
| 823 | __map_iterator __t(*this); |
| 824 | ++(*this); |
| 825 | return __t; |
| 826 | } |
| 827 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 828 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 829 | __map_iterator& operator--() {--__i_; return *this;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 830 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | __map_iterator operator--(int) |
| 832 | { |
| 833 | __map_iterator __t(*this); |
| 834 | --(*this); |
| 835 | return __t; |
| 836 | } |
| 837 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 838 | friend _LIBCPP_INLINE_VISIBILITY |
| 839 | bool operator==(const __map_iterator& __x, const __map_iterator& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 840 | {return __x.__i_ == __y.__i_;} |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 841 | friend |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 842 | _LIBCPP_INLINE_VISIBILITY |
| 843 | bool operator!=(const __map_iterator& __x, const __map_iterator& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 844 | {return __x.__i_ != __y.__i_;} |
| 845 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 846 | template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; |
| 847 | template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; |
| 848 | template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 849 | }; |
| 850 | |
| 851 | template <class _TreeIterator> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 852 | class _LIBCPP_TEMPLATE_VIS __map_const_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 853 | { |
Eric Fiselier | a00b484 | 2016-02-20 05:28:30 +0000 | [diff] [blame] | 854 | typedef typename _TreeIterator::_NodeTypes _NodeTypes; |
| 855 | typedef typename _TreeIterator::__pointer_traits __pointer_traits; |
| 856 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 857 | _TreeIterator __i_; |
| 858 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 859 | public: |
| 860 | typedef bidirectional_iterator_tag iterator_category; |
Eric Fiselier | a00b484 | 2016-02-20 05:28:30 +0000 | [diff] [blame] | 861 | typedef typename _NodeTypes::__map_value_type value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 862 | typedef typename _TreeIterator::difference_type difference_type; |
| 863 | typedef const value_type& reference; |
Eric Fiselier | a00b484 | 2016-02-20 05:28:30 +0000 | [diff] [blame] | 864 | typedef typename _NodeTypes::__const_map_value_type_pointer pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 865 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 866 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 867 | __map_const_iterator() _NOEXCEPT {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 868 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 869 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 870 | __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 871 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 44f9fd0 | 2015-03-03 20:10:01 +0000 | [diff] [blame] | 872 | __map_const_iterator(__map_iterator< |
| 873 | typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT |
| 874 | : __i_(__i.__i_) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 875 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 876 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 877 | reference operator*() const {return __i_->__get_value();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 878 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 879 | pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 880 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 881 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 882 | __map_const_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | __map_const_iterator operator++(int) |
| 885 | { |
| 886 | __map_const_iterator __t(*this); |
| 887 | ++(*this); |
| 888 | return __t; |
| 889 | } |
| 890 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 891 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 892 | __map_const_iterator& operator--() {--__i_; return *this;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 893 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 894 | __map_const_iterator operator--(int) |
| 895 | { |
| 896 | __map_const_iterator __t(*this); |
| 897 | --(*this); |
| 898 | return __t; |
| 899 | } |
| 900 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 901 | friend _LIBCPP_INLINE_VISIBILITY |
| 902 | bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 903 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 904 | friend _LIBCPP_INLINE_VISIBILITY |
| 905 | bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 906 | {return __x.__i_ != __y.__i_;} |
| 907 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 908 | template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; |
| 909 | template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; |
| 910 | template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 911 | }; |
| 912 | |
| 913 | template <class _Key, class _Tp, class _Compare = less<_Key>, |
| 914 | class _Allocator = allocator<pair<const _Key, _Tp> > > |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 915 | class _LIBCPP_TEMPLATE_VIS map |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 916 | { |
| 917 | public: |
| 918 | // types: |
| 919 | typedef _Key key_type; |
| 920 | typedef _Tp mapped_type; |
| 921 | typedef pair<const key_type, mapped_type> value_type; |
Arthur O'Dwyer | 6a752e1 | 2021-03-03 11:10:49 -0500 | [diff] [blame] | 922 | typedef __identity_t<_Compare> key_compare; |
| 923 | typedef __identity_t<_Allocator> allocator_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 924 | typedef value_type& reference; |
| 925 | typedef const value_type& const_reference; |
| 926 | |
Marshall Clow | 5128cf3 | 2015-11-26 01:24:04 +0000 | [diff] [blame] | 927 | static_assert((is_same<typename allocator_type::value_type, value_type>::value), |
| 928 | "Allocator::value_type must be same type as value_type"); |
| 929 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 930 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 931 | class _LIBCPP_TEMPLATE_VIS value_compare |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 932 | #if defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 933 | : public binary_function<value_type, value_type, bool> |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 934 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 935 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 936 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 937 | friend class map; |
| 938 | protected: |
| 939 | key_compare comp; |
| 940 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 941 | _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 942 | public: |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 943 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 944 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 945 | _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type first_argument_type; |
| 946 | _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type second_argument_type; |
| 947 | #endif |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 948 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 949 | bool operator()(const value_type& __x, const value_type& __y) const |
| 950 | {return comp(__x.first, __y.first);} |
| 951 | }; |
| 952 | |
| 953 | private: |
Howard Hinnant | 2d0046b | 2013-06-19 21:29:40 +0000 | [diff] [blame] | 954 | |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 955 | typedef _VSTD::__value_type<key_type, mapped_type> __value_type; |
Howard Hinnant | 90b9159 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 956 | typedef __map_value_compare<key_type, __value_type, key_compare> __vc; |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 957 | typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, |
| 958 | __value_type>::type __allocator_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | typedef __tree<__value_type, __vc, __allocator_type> __base; |
| 960 | typedef typename __base::__node_traits __node_traits; |
| 961 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 962 | |
| 963 | __base __tree_; |
| 964 | |
| 965 | public: |
| 966 | typedef typename __alloc_traits::pointer pointer; |
| 967 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 968 | typedef typename __alloc_traits::size_type size_type; |
| 969 | typedef typename __alloc_traits::difference_type difference_type; |
Eric Fiselier | 44f9fd0 | 2015-03-03 20:10:01 +0000 | [diff] [blame] | 970 | typedef __map_iterator<typename __base::iterator> iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 971 | typedef __map_const_iterator<typename __base::const_iterator> const_iterator; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 972 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 973 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 974 | |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 975 | #if _LIBCPP_STD_VER > 14 |
| 976 | typedef __map_node_handle<typename __base::__node, allocator_type> node_type; |
| 977 | typedef __insert_return_type<iterator, node_type> insert_return_type; |
| 978 | #endif |
| 979 | |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 980 | template <class _Key2, class _Value2, class _Comp2, class _Alloc2> |
| 981 | friend class _LIBCPP_TEMPLATE_VIS map; |
| 982 | template <class _Key2, class _Value2, class _Comp2, class _Alloc2> |
| 983 | friend class _LIBCPP_TEMPLATE_VIS multimap; |
| 984 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 985 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 7086a5a | 2014-03-10 04:50:10 +0000 | [diff] [blame] | 986 | map() |
| 987 | _NOEXCEPT_( |
| 988 | is_nothrow_default_constructible<allocator_type>::value && |
| 989 | is_nothrow_default_constructible<key_compare>::value && |
| 990 | is_nothrow_copy_constructible<key_compare>::value) |
| 991 | : __tree_(__vc(key_compare())) {} |
| 992 | |
| 993 | _LIBCPP_INLINE_VISIBILITY |
| 994 | explicit map(const key_compare& __comp) |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 995 | _NOEXCEPT_( |
| 996 | is_nothrow_default_constructible<allocator_type>::value && |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 997 | is_nothrow_copy_constructible<key_compare>::value) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 998 | : __tree_(__vc(__comp)) {} |
| 999 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1000 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1001 | explicit map(const key_compare& __comp, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1002 | : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1003 | |
| 1004 | template <class _InputIterator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1005 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1006 | map(_InputIterator __f, _InputIterator __l, |
| 1007 | const key_compare& __comp = key_compare()) |
| 1008 | : __tree_(__vc(__comp)) |
| 1009 | { |
| 1010 | insert(__f, __l); |
| 1011 | } |
| 1012 | |
| 1013 | template <class _InputIterator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1014 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1015 | map(_InputIterator __f, _InputIterator __l, |
| 1016 | const key_compare& __comp, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1017 | : __tree_(__vc(__comp), typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1018 | { |
| 1019 | insert(__f, __l); |
| 1020 | } |
| 1021 | |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 1022 | #if _LIBCPP_STD_VER > 11 |
| 1023 | template <class _InputIterator> |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 1024 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 1025 | map(_InputIterator __f, _InputIterator __l, const allocator_type& __a) |
| 1026 | : map(__f, __l, key_compare(), __a) {} |
| 1027 | #endif |
| 1028 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1029 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1030 | map(const map& __m) |
| 1031 | : __tree_(__m.__tree_) |
| 1032 | { |
| 1033 | insert(__m.begin(), __m.end()); |
| 1034 | } |
| 1035 | |
Howard Hinnant | d3a657f | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1036 | _LIBCPP_INLINE_VISIBILITY |
| 1037 | map& operator=(const map& __m) |
| 1038 | { |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1039 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d3a657f | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1040 | __tree_ = __m.__tree_; |
Howard Hinnant | 2d0046b | 2013-06-19 21:29:40 +0000 | [diff] [blame] | 1041 | #else |
Marshall Clow | db3cfcb | 2014-02-08 04:03:14 +0000 | [diff] [blame] | 1042 | if (this != &__m) { |
| 1043 | __tree_.clear(); |
| 1044 | __tree_.value_comp() = __m.__tree_.value_comp(); |
| 1045 | __tree_.__copy_assign_alloc(__m.__tree_); |
| 1046 | insert(__m.begin(), __m.end()); |
| 1047 | } |
Howard Hinnant | 2d0046b | 2013-06-19 21:29:40 +0000 | [diff] [blame] | 1048 | #endif |
Howard Hinnant | d3a657f | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1049 | return *this; |
| 1050 | } |
| 1051 | |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1052 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1053 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1054 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1055 | map(map&& __m) |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1056 | _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1057 | : __tree_(_VSTD::move(__m.__tree_)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1058 | { |
| 1059 | } |
| 1060 | |
| 1061 | map(map&& __m, const allocator_type& __a); |
| 1062 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1063 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1064 | map& operator=(map&& __m) |
| 1065 | _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) |
| 1066 | { |
| 1067 | __tree_ = _VSTD::move(__m.__tree_); |
| 1068 | return *this; |
| 1069 | } |
| 1070 | |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1071 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1072 | map(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) |
| 1073 | : __tree_(__vc(__comp)) |
| 1074 | { |
| 1075 | insert(__il.begin(), __il.end()); |
| 1076 | } |
| 1077 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1078 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1079 | map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1080 | : __tree_(__vc(__comp), typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1081 | { |
| 1082 | insert(__il.begin(), __il.end()); |
| 1083 | } |
| 1084 | |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 1085 | #if _LIBCPP_STD_VER > 11 |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 1086 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 1087 | map(initializer_list<value_type> __il, const allocator_type& __a) |
| 1088 | : map(__il, key_compare(), __a) {} |
| 1089 | #endif |
| 1090 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1091 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1092 | map& operator=(initializer_list<value_type> __il) |
| 1093 | { |
| 1094 | __tree_.__assign_unique(__il.begin(), __il.end()); |
| 1095 | return *this; |
| 1096 | } |
| 1097 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1098 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1099 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1100 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1101 | explicit map(const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1102 | : __tree_(typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1103 | { |
| 1104 | } |
| 1105 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1106 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1107 | map(const map& __m, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1108 | : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1109 | { |
| 1110 | insert(__m.begin(), __m.end()); |
| 1111 | } |
| 1112 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1113 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 69c42c0 | 2019-04-11 16:14:56 +0000 | [diff] [blame] | 1114 | ~map() { |
| 1115 | static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); |
| 1116 | } |
| 1117 | |
| 1118 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1119 | iterator begin() _NOEXCEPT {return __tree_.begin();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1120 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1121 | const_iterator begin() const _NOEXCEPT {return __tree_.begin();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1122 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1123 | iterator end() _NOEXCEPT {return __tree_.end();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1124 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1125 | const_iterator end() const _NOEXCEPT {return __tree_.end();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1126 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1127 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1128 | reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1129 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1130 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 1131 | {return const_reverse_iterator(end());} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1132 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1133 | reverse_iterator rend() _NOEXCEPT |
| 1134 | {return reverse_iterator(begin());} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1135 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1136 | const_reverse_iterator rend() const _NOEXCEPT |
| 1137 | {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1138 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1139 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1140 | const_iterator cbegin() const _NOEXCEPT {return begin();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1141 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1142 | const_iterator cend() const _NOEXCEPT {return end();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1143 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1144 | const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1145 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1146 | const_reverse_iterator crend() const _NOEXCEPT {return rend();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1147 | |
Marshall Clow | 425f575 | 2017-11-15 05:51:26 +0000 | [diff] [blame] | 1148 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1149 | bool empty() const _NOEXCEPT {return __tree_.size() == 0;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1150 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1151 | size_type size() const _NOEXCEPT {return __tree_.size();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1152 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1153 | size_type max_size() const _NOEXCEPT {return __tree_.max_size();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1154 | |
| 1155 | mapped_type& operator[](const key_type& __k); |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1156 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1157 | mapped_type& operator[](key_type&& __k); |
| 1158 | #endif |
| 1159 | |
| 1160 | mapped_type& at(const key_type& __k); |
| 1161 | const mapped_type& at(const key_type& __k) const; |
| 1162 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1163 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1164 | allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1165 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1166 | key_compare key_comp() const {return __tree_.value_comp().key_comp();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1167 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1168 | value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());} |
| 1169 | |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 1170 | #ifndef _LIBCPP_CXX03_LANG |
| 1171 | template <class ..._Args> |
| 1172 | _LIBCPP_INLINE_VISIBILITY |
| 1173 | pair<iterator, bool> emplace(_Args&& ...__args) { |
| 1174 | return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...); |
| 1175 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1176 | |
Howard Hinnant | 29eb9b8 | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1177 | template <class ..._Args> |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 1178 | _LIBCPP_INLINE_VISIBILITY |
| 1179 | iterator emplace_hint(const_iterator __p, _Args&& ...__args) { |
| 1180 | return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...); |
| 1181 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1182 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1183 | template <class _Pp, |
| 1184 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1185 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1186 | pair<iterator, bool> insert(_Pp&& __p) |
| 1187 | {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1188 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1189 | template <class _Pp, |
| 1190 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1191 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1192 | iterator insert(const_iterator __pos, _Pp&& __p) |
| 1193 | {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1194 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1195 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1196 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1197 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | pair<iterator, bool> |
| 1199 | insert(const value_type& __v) {return __tree_.__insert_unique(__v);} |
| 1200 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1201 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1202 | iterator |
| 1203 | insert(const_iterator __p, const value_type& __v) |
| 1204 | {return __tree_.__insert_unique(__p.__i_, __v);} |
| 1205 | |
Eric Fiselier | d614313 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 1206 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | d430d02 | 2016-01-05 19:32:41 +0000 | [diff] [blame] | 1207 | _LIBCPP_INLINE_VISIBILITY |
| 1208 | pair<iterator, bool> |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 1209 | insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));} |
Marshall Clow | d430d02 | 2016-01-05 19:32:41 +0000 | [diff] [blame] | 1210 | |
| 1211 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 1212 | iterator insert(const_iterator __p, value_type&& __v) |
| 1213 | {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));} |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1214 | |
| 1215 | _LIBCPP_INLINE_VISIBILITY |
| 1216 | void insert(initializer_list<value_type> __il) |
| 1217 | {insert(__il.begin(), __il.end());} |
Marshall Clow | d430d02 | 2016-01-05 19:32:41 +0000 | [diff] [blame] | 1218 | #endif |
| 1219 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1220 | template <class _InputIterator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1221 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1222 | void insert(_InputIterator __f, _InputIterator __l) |
| 1223 | { |
| 1224 | for (const_iterator __e = cend(); __f != __l; ++__f) |
| 1225 | insert(__e.__i_, *__f); |
| 1226 | } |
| 1227 | |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 1228 | #if _LIBCPP_STD_VER > 14 |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1229 | |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 1230 | template <class... _Args> |
| 1231 | _LIBCPP_INLINE_VISIBILITY |
| 1232 | pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) |
| 1233 | { |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1234 | return __tree_.__emplace_unique_key_args(__k, |
| 1235 | _VSTD::piecewise_construct, |
| 1236 | _VSTD::forward_as_tuple(__k), |
| 1237 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | template <class... _Args> |
| 1241 | _LIBCPP_INLINE_VISIBILITY |
| 1242 | pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) |
| 1243 | { |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1244 | return __tree_.__emplace_unique_key_args(__k, |
| 1245 | _VSTD::piecewise_construct, |
| 1246 | _VSTD::forward_as_tuple(_VSTD::move(__k)), |
| 1247 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | template <class... _Args> |
| 1251 | _LIBCPP_INLINE_VISIBILITY |
| 1252 | iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) |
| 1253 | { |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1254 | return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, |
| 1255 | _VSTD::piecewise_construct, |
| 1256 | _VSTD::forward_as_tuple(__k), |
Mark de Wever | 1ba476f | 2020-09-19 15:39:09 +0200 | [diff] [blame] | 1257 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first; |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | template <class... _Args> |
| 1261 | _LIBCPP_INLINE_VISIBILITY |
| 1262 | iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) |
| 1263 | { |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1264 | return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, |
| 1265 | _VSTD::piecewise_construct, |
| 1266 | _VSTD::forward_as_tuple(_VSTD::move(__k)), |
Mark de Wever | 1ba476f | 2020-09-19 15:39:09 +0200 | [diff] [blame] | 1267 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first; |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | template <class _Vp> |
| 1271 | _LIBCPP_INLINE_VISIBILITY |
| 1272 | pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) |
| 1273 | { |
| 1274 | iterator __p = lower_bound(__k); |
| 1275 | if ( __p != end() && !key_comp()(__k, __p->first)) |
| 1276 | { |
| 1277 | __p->second = _VSTD::forward<_Vp>(__v); |
| 1278 | return _VSTD::make_pair(__p, false); |
| 1279 | } |
| 1280 | return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true); |
| 1281 | } |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1282 | |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 1283 | template <class _Vp> |
| 1284 | _LIBCPP_INLINE_VISIBILITY |
| 1285 | pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) |
| 1286 | { |
| 1287 | iterator __p = lower_bound(__k); |
| 1288 | if ( __p != end() && !key_comp()(__k, __p->first)) |
| 1289 | { |
| 1290 | __p->second = _VSTD::forward<_Vp>(__v); |
| 1291 | return _VSTD::make_pair(__p, false); |
| 1292 | } |
| 1293 | return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true); |
| 1294 | } |
| 1295 | |
| 1296 | template <class _Vp> |
Mark de Wever | 1ba476f | 2020-09-19 15:39:09 +0200 | [diff] [blame] | 1297 | _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h, |
| 1298 | const key_type& __k, |
| 1299 | _Vp&& __v) { |
| 1300 | auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args( |
| 1301 | __h.__i_, __k, __k, _VSTD::forward<_Vp>(__v)); |
| 1302 | |
| 1303 | if (!__inserted) |
| 1304 | __r->__get_value().second = _VSTD::forward<_Vp>(__v); |
| 1305 | |
| 1306 | return __r; |
| 1307 | } |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 1308 | |
| 1309 | template <class _Vp> |
Mark de Wever | 1ba476f | 2020-09-19 15:39:09 +0200 | [diff] [blame] | 1310 | _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h, |
| 1311 | key_type&& __k, |
| 1312 | _Vp&& __v) { |
| 1313 | auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args( |
| 1314 | __h.__i_, __k, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)); |
| 1315 | |
| 1316 | if (!__inserted) |
| 1317 | __r->__get_value().second = _VSTD::forward<_Vp>(__v); |
| 1318 | |
| 1319 | return __r; |
| 1320 | } |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1321 | |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1322 | #endif // _LIBCPP_STD_VER > 14 |
Marshall Clow | 3223db8 | 2015-07-07 03:37:33 +0000 | [diff] [blame] | 1323 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1326 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 22ea5b8 | 2015-05-10 13:35:00 +0000 | [diff] [blame] | 1327 | iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} |
| 1328 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1329 | size_type erase(const key_type& __k) |
| 1330 | {return __tree_.__erase_unique(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1331 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1332 | iterator erase(const_iterator __f, const_iterator __l) |
| 1333 | {return __tree_.erase(__f.__i_, __l.__i_);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1334 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1335 | void clear() _NOEXCEPT {__tree_.clear();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1336 | |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 1337 | #if _LIBCPP_STD_VER > 14 |
| 1338 | _LIBCPP_INLINE_VISIBILITY |
| 1339 | insert_return_type insert(node_type&& __nh) |
| 1340 | { |
| 1341 | _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), |
| 1342 | "node_type with incompatible allocator passed to map::insert()"); |
| 1343 | return __tree_.template __node_handle_insert_unique< |
| 1344 | node_type, insert_return_type>(_VSTD::move(__nh)); |
| 1345 | } |
| 1346 | _LIBCPP_INLINE_VISIBILITY |
| 1347 | iterator insert(const_iterator __hint, node_type&& __nh) |
| 1348 | { |
| 1349 | _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), |
| 1350 | "node_type with incompatible allocator passed to map::insert()"); |
| 1351 | return __tree_.template __node_handle_insert_unique<node_type>( |
| 1352 | __hint.__i_, _VSTD::move(__nh)); |
| 1353 | } |
| 1354 | _LIBCPP_INLINE_VISIBILITY |
| 1355 | node_type extract(key_type const& __key) |
| 1356 | { |
| 1357 | return __tree_.template __node_handle_extract<node_type>(__key); |
| 1358 | } |
| 1359 | _LIBCPP_INLINE_VISIBILITY |
| 1360 | node_type extract(const_iterator __it) |
| 1361 | { |
| 1362 | return __tree_.template __node_handle_extract<node_type>(__it.__i_); |
| 1363 | } |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 1364 | template <class _Compare2> |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 1365 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 1366 | void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 1367 | { |
| 1368 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 1369 | "merging container with incompatible allocator"); |
| 1370 | __tree_.__node_handle_merge_unique(__source.__tree_); |
| 1371 | } |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 1372 | template <class _Compare2> |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 1373 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 1374 | void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 1375 | { |
| 1376 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 1377 | "merging container with incompatible allocator"); |
| 1378 | __tree_.__node_handle_merge_unique(__source.__tree_); |
| 1379 | } |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 1380 | template <class _Compare2> |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 1381 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 1382 | void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 1383 | { |
| 1384 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 1385 | "merging container with incompatible allocator"); |
| 1386 | __tree_.__node_handle_merge_unique(__source.__tree_); |
| 1387 | } |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 1388 | template <class _Compare2> |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 1389 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 1390 | void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 1391 | { |
| 1392 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 1393 | "merging container with incompatible allocator"); |
| 1394 | __tree_.__node_handle_merge_unique(__source.__tree_); |
| 1395 | } |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 1396 | #endif |
| 1397 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1398 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1399 | void swap(map& __m) |
| 1400 | _NOEXCEPT_(__is_nothrow_swappable<__base>::value) |
| 1401 | {__tree_.swap(__m.__tree_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1402 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1403 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1404 | iterator find(const key_type& __k) {return __tree_.find(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1405 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1406 | const_iterator find(const key_type& __k) const {return __tree_.find(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 1407 | #if _LIBCPP_STD_VER > 11 |
| 1408 | template <typename _K2> |
| 1409 | _LIBCPP_INLINE_VISIBILITY |
| 1410 | typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type |
| 1411 | find(const _K2& __k) {return __tree_.find(__k);} |
| 1412 | template <typename _K2> |
| 1413 | _LIBCPP_INLINE_VISIBILITY |
| 1414 | typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type |
| 1415 | find(const _K2& __k) const {return __tree_.find(__k);} |
| 1416 | #endif |
| 1417 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1418 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1419 | size_type count(const key_type& __k) const |
| 1420 | {return __tree_.__count_unique(__k);} |
Marshall Clow | e6a5f52 | 2014-08-24 23:54:16 +0000 | [diff] [blame] | 1421 | #if _LIBCPP_STD_VER > 11 |
| 1422 | template <typename _K2> |
| 1423 | _LIBCPP_INLINE_VISIBILITY |
| 1424 | typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type |
Eric Fiselier | a85c9e9 | 2018-02-10 02:53:47 +0000 | [diff] [blame] | 1425 | count(const _K2& __k) const {return __tree_.__count_multi(__k);} |
Marshall Clow | e6a5f52 | 2014-08-24 23:54:16 +0000 | [diff] [blame] | 1426 | #endif |
Zoe Carver | 3ffbab1 | 2019-07-16 03:21:01 +0000 | [diff] [blame] | 1427 | |
| 1428 | #if _LIBCPP_STD_VER > 17 |
| 1429 | _LIBCPP_INLINE_VISIBILITY |
| 1430 | bool contains(const key_type& __k) const {return find(__k) != end();} |
Marek Kurdej | d7e019e | 2021-04-13 17:10:55 +0200 | [diff] [blame] | 1431 | template <typename _K2> |
| 1432 | _LIBCPP_INLINE_VISIBILITY |
| 1433 | typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type |
| 1434 | contains(const _K2& __k) const { return find(__k) != end(); } |
Zoe Carver | 3ffbab1 | 2019-07-16 03:21:01 +0000 | [diff] [blame] | 1435 | #endif // _LIBCPP_STD_VER > 17 |
| 1436 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1437 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | iterator lower_bound(const key_type& __k) |
| 1439 | {return __tree_.lower_bound(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1440 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1441 | const_iterator lower_bound(const key_type& __k) const |
| 1442 | {return __tree_.lower_bound(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 1443 | #if _LIBCPP_STD_VER > 11 |
| 1444 | template <typename _K2> |
| 1445 | _LIBCPP_INLINE_VISIBILITY |
| 1446 | typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type |
| 1447 | lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} |
| 1448 | |
| 1449 | template <typename _K2> |
| 1450 | _LIBCPP_INLINE_VISIBILITY |
| 1451 | typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type |
| 1452 | lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} |
| 1453 | #endif |
| 1454 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1455 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1456 | iterator upper_bound(const key_type& __k) |
| 1457 | {return __tree_.upper_bound(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1458 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1459 | const_iterator upper_bound(const key_type& __k) const |
| 1460 | {return __tree_.upper_bound(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 1461 | #if _LIBCPP_STD_VER > 11 |
| 1462 | template <typename _K2> |
| 1463 | _LIBCPP_INLINE_VISIBILITY |
| 1464 | typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type |
| 1465 | upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} |
| 1466 | template <typename _K2> |
| 1467 | _LIBCPP_INLINE_VISIBILITY |
| 1468 | typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type |
| 1469 | upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} |
| 1470 | #endif |
| 1471 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1472 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1473 | pair<iterator,iterator> equal_range(const key_type& __k) |
| 1474 | {return __tree_.__equal_range_unique(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1475 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1476 | pair<const_iterator,const_iterator> equal_range(const key_type& __k) const |
| 1477 | {return __tree_.__equal_range_unique(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 1478 | #if _LIBCPP_STD_VER > 11 |
| 1479 | template <typename _K2> |
| 1480 | _LIBCPP_INLINE_VISIBILITY |
| 1481 | typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type |
Eric Fiselier | a85c9e9 | 2018-02-10 02:53:47 +0000 | [diff] [blame] | 1482 | equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 1483 | template <typename _K2> |
| 1484 | _LIBCPP_INLINE_VISIBILITY |
| 1485 | typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type |
Eric Fiselier | a85c9e9 | 2018-02-10 02:53:47 +0000 | [diff] [blame] | 1486 | equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 1487 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1488 | |
| 1489 | private: |
| 1490 | typedef typename __base::__node __node; |
| 1491 | typedef typename __base::__node_allocator __node_allocator; |
| 1492 | typedef typename __base::__node_pointer __node_pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1493 | typedef typename __base::__node_base_pointer __node_base_pointer; |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 1494 | typedef typename __base::__parent_pointer __parent_pointer; |
Eric Fiselier | a92b073 | 2016-02-20 07:12:17 +0000 | [diff] [blame] | 1495 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1496 | typedef __map_node_destructor<__node_allocator> _Dp; |
| 1497 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1498 | |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1499 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | ac7e748 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1500 | __node_holder __construct_node_with_key(const key_type& __k); |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1501 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1502 | }; |
| 1503 | |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 1504 | #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 1505 | template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>, |
| 1506 | class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, |
Louis Dionne | 6c7da9a | 2019-07-19 17:13:39 +0000 | [diff] [blame] | 1507 | class = _EnableIf<!__is_allocator<_Compare>::value, void>, |
| 1508 | class = _EnableIf<__is_allocator<_Allocator>::value, void>> |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 1509 | map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) |
| 1510 | -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>; |
| 1511 | |
| 1512 | template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>, |
| 1513 | class _Allocator = allocator<pair<const _Key, _Tp>>, |
Louis Dionne | 6c7da9a | 2019-07-19 17:13:39 +0000 | [diff] [blame] | 1514 | class = _EnableIf<!__is_allocator<_Compare>::value, void>, |
| 1515 | class = _EnableIf<__is_allocator<_Allocator>::value, void>> |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 1516 | map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator()) |
| 1517 | -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>; |
| 1518 | |
| 1519 | template<class _InputIterator, class _Allocator, |
Louis Dionne | 6c7da9a | 2019-07-19 17:13:39 +0000 | [diff] [blame] | 1520 | class = _EnableIf<__is_allocator<_Allocator>::value, void>> |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 1521 | map(_InputIterator, _InputIterator, _Allocator) |
| 1522 | -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, |
| 1523 | less<__iter_key_type<_InputIterator>>, _Allocator>; |
| 1524 | |
| 1525 | template<class _Key, class _Tp, class _Allocator, |
Louis Dionne | 6c7da9a | 2019-07-19 17:13:39 +0000 | [diff] [blame] | 1526 | class = _EnableIf<__is_allocator<_Allocator>::value, void>> |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 1527 | map(initializer_list<pair<_Key, _Tp>>, _Allocator) |
| 1528 | -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>; |
| 1529 | #endif |
Eric Fiselier | a92b073 | 2016-02-20 07:12:17 +0000 | [diff] [blame] | 1530 | |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 1531 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1532 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1533 | map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1534 | : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1535 | { |
| 1536 | if (__a != __m.get_allocator()) |
| 1537 | { |
| 1538 | const_iterator __e = cend(); |
| 1539 | while (!__m.empty()) |
| 1540 | __tree_.__insert_unique(__e.__i_, |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 1541 | __m.__tree_.remove(__m.begin().__i_)->__value_.__move()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1545 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1546 | _Tp& |
| 1547 | map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) |
| 1548 | { |
| 1549 | return __tree_.__emplace_unique_key_args(__k, |
| 1550 | _VSTD::piecewise_construct, |
| 1551 | _VSTD::forward_as_tuple(__k), |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 1552 | _VSTD::forward_as_tuple()).first->__get_value().second; |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1553 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1554 | |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1555 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1556 | _Tp& |
| 1557 | map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) |
| 1558 | { |
| 1559 | return __tree_.__emplace_unique_key_args(__k, |
| 1560 | _VSTD::piecewise_construct, |
| 1561 | _VSTD::forward_as_tuple(_VSTD::move(__k)), |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 1562 | _VSTD::forward_as_tuple()).first->__get_value().second; |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1563 | } |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1564 | |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1565 | #else // _LIBCPP_CXX03_LANG |
Eric Fiselier | d63f38e | 2016-03-31 03:13:37 +0000 | [diff] [blame] | 1566 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1567 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1568 | typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder |
Howard Hinnant | ac7e748 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1569 | map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1570 | { |
| 1571 | __node_allocator& __na = __tree_.__node_alloc(); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1572 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 1573 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1574 | __h.get_deleter().__first_constructed = true; |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 1575 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1576 | __h.get_deleter().__second_constructed = true; |
Louis Dionne | 7b84436 | 2020-07-30 09:42:23 -0400 | [diff] [blame] | 1577 | return __h; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1580 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1581 | _Tp& |
| 1582 | map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) |
| 1583 | { |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 1584 | __parent_pointer __parent; |
| 1585 | __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1586 | __node_pointer __r = static_cast<__node_pointer>(__child); |
| 1587 | if (__child == nullptr) |
| 1588 | { |
Howard Hinnant | ac7e748 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1589 | __node_holder __h = __construct_node_with_key(__k); |
Howard Hinnant | 2d0046b | 2013-06-19 21:29:40 +0000 | [diff] [blame] | 1590 | __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1591 | __r = __h.release(); |
| 1592 | } |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 1593 | return __r->__value_.__get_value().second; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1596 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1597 | |
| 1598 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1599 | _Tp& |
| 1600 | map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) |
| 1601 | { |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 1602 | __parent_pointer __parent; |
| 1603 | __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1604 | if (__child == nullptr) |
Louis Dionne | 2b23916 | 2019-02-12 16:06:02 +0000 | [diff] [blame] | 1605 | __throw_out_of_range("map::at: key not found"); |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 1606 | return static_cast<__node_pointer>(__child)->__value_.__get_value().second; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1610 | const _Tp& |
| 1611 | map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const |
| 1612 | { |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 1613 | __parent_pointer __parent; |
| 1614 | __node_base_pointer __child = __tree_.__find_equal(__parent, __k); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1615 | if (__child == nullptr) |
Louis Dionne | 2b23916 | 2019-02-12 16:06:02 +0000 | [diff] [blame] | 1616 | __throw_out_of_range("map::at: key not found"); |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 1617 | return static_cast<__node_pointer>(__child)->__value_.__get_value().second; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1620 | |
| 1621 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1622 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1623 | bool |
| 1624 | operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1625 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1626 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1627 | return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1631 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1632 | bool |
| 1633 | operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1634 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1635 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1636 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1640 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1641 | bool |
| 1642 | operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1643 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1644 | { |
| 1645 | return !(__x == __y); |
| 1646 | } |
| 1647 | |
| 1648 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1649 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1650 | bool |
| 1651 | operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1652 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1653 | { |
| 1654 | return __y < __x; |
| 1655 | } |
| 1656 | |
| 1657 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1658 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1659 | bool |
| 1660 | operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1661 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1662 | { |
| 1663 | return !(__x < __y); |
| 1664 | } |
| 1665 | |
| 1666 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1667 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1668 | bool |
| 1669 | operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1670 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1671 | { |
| 1672 | return !(__y < __x); |
| 1673 | } |
| 1674 | |
| 1675 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1676 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1677 | void |
| 1678 | swap(map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1679 | map<_Key, _Tp, _Compare, _Allocator>& __y) |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1680 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1681 | { |
| 1682 | __x.swap(__y); |
| 1683 | } |
| 1684 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 1685 | #if _LIBCPP_STD_VER > 17 |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 1686 | template <class _Key, class _Tp, class _Compare, class _Allocator, |
| 1687 | class _Predicate> |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 1688 | inline _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 1689 | typename map<_Key, _Tp, _Compare, _Allocator>::size_type |
| 1690 | erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) { |
Arthur O'Dwyer | b6738bd | 2021-03-21 16:53:09 -0400 | [diff] [blame] | 1691 | return _VSTD::__libcpp_erase_if_container(__c, __pred); |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 1692 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 1693 | #endif |
| 1694 | |
| 1695 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1696 | template <class _Key, class _Tp, class _Compare = less<_Key>, |
| 1697 | class _Allocator = allocator<pair<const _Key, _Tp> > > |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1698 | class _LIBCPP_TEMPLATE_VIS multimap |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1699 | { |
| 1700 | public: |
| 1701 | // types: |
| 1702 | typedef _Key key_type; |
| 1703 | typedef _Tp mapped_type; |
| 1704 | typedef pair<const key_type, mapped_type> value_type; |
Arthur O'Dwyer | 6a752e1 | 2021-03-03 11:10:49 -0500 | [diff] [blame] | 1705 | typedef __identity_t<_Compare> key_compare; |
| 1706 | typedef __identity_t<_Allocator> allocator_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1707 | typedef value_type& reference; |
| 1708 | typedef const value_type& const_reference; |
| 1709 | |
Marshall Clow | 5128cf3 | 2015-11-26 01:24:04 +0000 | [diff] [blame] | 1710 | static_assert((is_same<typename allocator_type::value_type, value_type>::value), |
| 1711 | "Allocator::value_type must be same type as value_type"); |
| 1712 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 1713 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1714 | class _LIBCPP_TEMPLATE_VIS value_compare |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 1715 | #if defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1716 | : public binary_function<value_type, value_type, bool> |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 1717 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1718 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 1719 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1720 | friend class multimap; |
| 1721 | protected: |
| 1722 | key_compare comp; |
| 1723 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1724 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1725 | value_compare(key_compare c) : comp(c) {} |
| 1726 | public: |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame] | 1727 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 1728 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 1729 | _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type first_argument_type; |
| 1730 | _LIBCPP_DEPRECATED_IN_CXX17 typedef value_type second_argument_type; |
| 1731 | #endif |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1732 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1733 | bool operator()(const value_type& __x, const value_type& __y) const |
| 1734 | {return comp(__x.first, __y.first);} |
| 1735 | }; |
| 1736 | |
| 1737 | private: |
Howard Hinnant | 2d0046b | 2013-06-19 21:29:40 +0000 | [diff] [blame] | 1738 | |
Howard Hinnant | 89f8b79 | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 1739 | typedef _VSTD::__value_type<key_type, mapped_type> __value_type; |
Howard Hinnant | 90b9159 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 1740 | typedef __map_value_compare<key_type, __value_type, key_compare> __vc; |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1741 | typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, |
| 1742 | __value_type>::type __allocator_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1743 | typedef __tree<__value_type, __vc, __allocator_type> __base; |
| 1744 | typedef typename __base::__node_traits __node_traits; |
| 1745 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 1746 | |
| 1747 | __base __tree_; |
| 1748 | |
| 1749 | public: |
| 1750 | typedef typename __alloc_traits::pointer pointer; |
| 1751 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 1752 | typedef typename __alloc_traits::size_type size_type; |
| 1753 | typedef typename __alloc_traits::difference_type difference_type; |
| 1754 | typedef __map_iterator<typename __base::iterator> iterator; |
| 1755 | typedef __map_const_iterator<typename __base::const_iterator> const_iterator; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1756 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 1757 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1758 | |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 1759 | #if _LIBCPP_STD_VER > 14 |
| 1760 | typedef __map_node_handle<typename __base::__node, allocator_type> node_type; |
| 1761 | #endif |
| 1762 | |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 1763 | template <class _Key2, class _Value2, class _Comp2, class _Alloc2> |
| 1764 | friend class _LIBCPP_TEMPLATE_VIS map; |
| 1765 | template <class _Key2, class _Value2, class _Comp2, class _Alloc2> |
| 1766 | friend class _LIBCPP_TEMPLATE_VIS multimap; |
| 1767 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1768 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 7086a5a | 2014-03-10 04:50:10 +0000 | [diff] [blame] | 1769 | multimap() |
| 1770 | _NOEXCEPT_( |
| 1771 | is_nothrow_default_constructible<allocator_type>::value && |
| 1772 | is_nothrow_default_constructible<key_compare>::value && |
| 1773 | is_nothrow_copy_constructible<key_compare>::value) |
| 1774 | : __tree_(__vc(key_compare())) {} |
| 1775 | |
| 1776 | _LIBCPP_INLINE_VISIBILITY |
| 1777 | explicit multimap(const key_compare& __comp) |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1778 | _NOEXCEPT_( |
| 1779 | is_nothrow_default_constructible<allocator_type>::value && |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1780 | is_nothrow_copy_constructible<key_compare>::value) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1781 | : __tree_(__vc(__comp)) {} |
| 1782 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1784 | explicit multimap(const key_compare& __comp, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1785 | : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1786 | |
| 1787 | template <class _InputIterator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1788 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1789 | multimap(_InputIterator __f, _InputIterator __l, |
| 1790 | const key_compare& __comp = key_compare()) |
| 1791 | : __tree_(__vc(__comp)) |
| 1792 | { |
| 1793 | insert(__f, __l); |
| 1794 | } |
| 1795 | |
| 1796 | template <class _InputIterator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1797 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1798 | multimap(_InputIterator __f, _InputIterator __l, |
| 1799 | const key_compare& __comp, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1800 | : __tree_(__vc(__comp), typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1801 | { |
| 1802 | insert(__f, __l); |
| 1803 | } |
| 1804 | |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 1805 | #if _LIBCPP_STD_VER > 11 |
| 1806 | template <class _InputIterator> |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 1807 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 1808 | multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a) |
| 1809 | : multimap(__f, __l, key_compare(), __a) {} |
| 1810 | #endif |
| 1811 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1812 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1813 | multimap(const multimap& __m) |
| 1814 | : __tree_(__m.__tree_.value_comp(), |
| 1815 | __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) |
| 1816 | { |
| 1817 | insert(__m.begin(), __m.end()); |
| 1818 | } |
| 1819 | |
Howard Hinnant | d3a657f | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1820 | _LIBCPP_INLINE_VISIBILITY |
| 1821 | multimap& operator=(const multimap& __m) |
| 1822 | { |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1823 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d3a657f | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1824 | __tree_ = __m.__tree_; |
Howard Hinnant | 2d0046b | 2013-06-19 21:29:40 +0000 | [diff] [blame] | 1825 | #else |
Marshall Clow | db3cfcb | 2014-02-08 04:03:14 +0000 | [diff] [blame] | 1826 | if (this != &__m) { |
| 1827 | __tree_.clear(); |
| 1828 | __tree_.value_comp() = __m.__tree_.value_comp(); |
| 1829 | __tree_.__copy_assign_alloc(__m.__tree_); |
| 1830 | insert(__m.begin(), __m.end()); |
| 1831 | } |
Howard Hinnant | 2d0046b | 2013-06-19 21:29:40 +0000 | [diff] [blame] | 1832 | #endif |
Howard Hinnant | d3a657f | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1833 | return *this; |
| 1834 | } |
| 1835 | |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1836 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1838 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1839 | multimap(multimap&& __m) |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1840 | _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1841 | : __tree_(_VSTD::move(__m.__tree_)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1842 | { |
| 1843 | } |
| 1844 | |
| 1845 | multimap(multimap&& __m, const allocator_type& __a); |
| 1846 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1847 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1848 | multimap& operator=(multimap&& __m) |
| 1849 | _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) |
| 1850 | { |
| 1851 | __tree_ = _VSTD::move(__m.__tree_); |
| 1852 | return *this; |
| 1853 | } |
| 1854 | |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1855 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1856 | multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) |
| 1857 | : __tree_(__vc(__comp)) |
| 1858 | { |
| 1859 | insert(__il.begin(), __il.end()); |
| 1860 | } |
| 1861 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1862 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1863 | multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1864 | : __tree_(__vc(__comp), typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | { |
| 1866 | insert(__il.begin(), __il.end()); |
| 1867 | } |
| 1868 | |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 1869 | #if _LIBCPP_STD_VER > 11 |
Eric Fiselier | cf8c021 | 2017-01-05 06:06:18 +0000 | [diff] [blame] | 1870 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 300abfb | 2013-09-11 01:15:47 +0000 | [diff] [blame] | 1871 | multimap(initializer_list<value_type> __il, const allocator_type& __a) |
| 1872 | : multimap(__il, key_compare(), __a) {} |
| 1873 | #endif |
| 1874 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1875 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1876 | multimap& operator=(initializer_list<value_type> __il) |
| 1877 | { |
| 1878 | __tree_.__assign_multi(__il.begin(), __il.end()); |
| 1879 | return *this; |
| 1880 | } |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1881 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1882 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1883 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1884 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1885 | explicit multimap(const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1886 | : __tree_(typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1887 | { |
| 1888 | } |
| 1889 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1890 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1891 | multimap(const multimap& __m, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1892 | : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1893 | { |
| 1894 | insert(__m.begin(), __m.end()); |
| 1895 | } |
| 1896 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1897 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 69c42c0 | 2019-04-11 16:14:56 +0000 | [diff] [blame] | 1898 | ~multimap() { |
| 1899 | static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); |
| 1900 | } |
| 1901 | |
| 1902 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1903 | iterator begin() _NOEXCEPT {return __tree_.begin();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1904 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1905 | const_iterator begin() const _NOEXCEPT {return __tree_.begin();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1906 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1907 | iterator end() _NOEXCEPT {return __tree_.end();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1908 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1909 | const_iterator end() const _NOEXCEPT {return __tree_.end();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1910 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1911 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1912 | reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1913 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1914 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 1915 | {return const_reverse_iterator(end());} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1916 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1917 | reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1918 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1919 | const_reverse_iterator rend() const _NOEXCEPT |
| 1920 | {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1921 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1922 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1923 | const_iterator cbegin() const _NOEXCEPT {return begin();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1924 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1925 | const_iterator cend() const _NOEXCEPT {return end();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1926 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1927 | const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1928 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1929 | const_reverse_iterator crend() const _NOEXCEPT {return rend();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1930 | |
Marshall Clow | 425f575 | 2017-11-15 05:51:26 +0000 | [diff] [blame] | 1931 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1932 | bool empty() const _NOEXCEPT {return __tree_.size() == 0;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1933 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1934 | size_type size() const _NOEXCEPT {return __tree_.size();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1935 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1936 | size_type max_size() const _NOEXCEPT {return __tree_.max_size();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1937 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1938 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 1939 | allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1940 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1941 | key_compare key_comp() const {return __tree_.value_comp().key_comp();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1942 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1943 | value_compare value_comp() const |
| 1944 | {return value_compare(__tree_.value_comp().key_comp());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1945 | |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 1946 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1947 | |
Howard Hinnant | 29eb9b8 | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1948 | template <class ..._Args> |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 1949 | _LIBCPP_INLINE_VISIBILITY |
| 1950 | iterator emplace(_Args&& ...__args) { |
| 1951 | return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...); |
| 1952 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1953 | |
Howard Hinnant | 29eb9b8 | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1954 | template <class ..._Args> |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 1955 | _LIBCPP_INLINE_VISIBILITY |
| 1956 | iterator emplace_hint(const_iterator __p, _Args&& ...__args) { |
| 1957 | return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...); |
| 1958 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1959 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1960 | template <class _Pp, |
| 1961 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1962 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1963 | iterator insert(_Pp&& __p) |
| 1964 | {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1965 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1966 | template <class _Pp, |
| 1967 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1968 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1969 | iterator insert(const_iterator __pos, _Pp&& __p) |
| 1970 | {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1971 | |
Eric Fiselier | d614313 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 1972 | _LIBCPP_INLINE_VISIBILITY |
| 1973 | iterator insert(value_type&& __v) |
| 1974 | {return __tree_.__insert_multi(_VSTD::move(__v));} |
| 1975 | |
| 1976 | _LIBCPP_INLINE_VISIBILITY |
| 1977 | iterator insert(const_iterator __p, value_type&& __v) |
| 1978 | {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));} |
| 1979 | |
Eric Fiselier | a85b128 | 2017-04-18 21:08:06 +0000 | [diff] [blame] | 1980 | |
| 1981 | _LIBCPP_INLINE_VISIBILITY |
| 1982 | void insert(initializer_list<value_type> __il) |
| 1983 | {insert(__il.begin(), __il.end());} |
| 1984 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1985 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1986 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1987 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1988 | iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);} |
| 1989 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1990 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1991 | iterator insert(const_iterator __p, const value_type& __v) |
| 1992 | {return __tree_.__insert_multi(__p.__i_, __v);} |
| 1993 | |
| 1994 | template <class _InputIterator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1995 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1996 | void insert(_InputIterator __f, _InputIterator __l) |
| 1997 | { |
| 1998 | for (const_iterator __e = cend(); __f != __l; ++__f) |
| 1999 | __tree_.__insert_multi(__e.__i_, *__f); |
| 2000 | } |
| 2001 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2002 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2003 | iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2004 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 22ea5b8 | 2015-05-10 13:35:00 +0000 | [diff] [blame] | 2005 | iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} |
| 2006 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2007 | size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2008 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2009 | iterator erase(const_iterator __f, const_iterator __l) |
| 2010 | {return __tree_.erase(__f.__i_, __l.__i_);} |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 2011 | |
| 2012 | #if _LIBCPP_STD_VER > 14 |
| 2013 | _LIBCPP_INLINE_VISIBILITY |
| 2014 | iterator insert(node_type&& __nh) |
| 2015 | { |
| 2016 | _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), |
| 2017 | "node_type with incompatible allocator passed to multimap::insert()"); |
| 2018 | return __tree_.template __node_handle_insert_multi<node_type>( |
| 2019 | _VSTD::move(__nh)); |
| 2020 | } |
| 2021 | _LIBCPP_INLINE_VISIBILITY |
| 2022 | iterator insert(const_iterator __hint, node_type&& __nh) |
| 2023 | { |
| 2024 | _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), |
| 2025 | "node_type with incompatible allocator passed to multimap::insert()"); |
| 2026 | return __tree_.template __node_handle_insert_multi<node_type>( |
| 2027 | __hint.__i_, _VSTD::move(__nh)); |
| 2028 | } |
| 2029 | _LIBCPP_INLINE_VISIBILITY |
| 2030 | node_type extract(key_type const& __key) |
| 2031 | { |
| 2032 | return __tree_.template __node_handle_extract<node_type>(__key); |
| 2033 | } |
| 2034 | _LIBCPP_INLINE_VISIBILITY |
| 2035 | node_type extract(const_iterator __it) |
| 2036 | { |
| 2037 | return __tree_.template __node_handle_extract<node_type>( |
| 2038 | __it.__i_); |
| 2039 | } |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 2040 | template <class _Compare2> |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 2041 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 2042 | void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 2043 | { |
| 2044 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 2045 | "merging container with incompatible allocator"); |
| 2046 | return __tree_.__node_handle_merge_multi(__source.__tree_); |
| 2047 | } |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 2048 | template <class _Compare2> |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 2049 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 2050 | void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 2051 | { |
| 2052 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 2053 | "merging container with incompatible allocator"); |
| 2054 | return __tree_.__node_handle_merge_multi(__source.__tree_); |
| 2055 | } |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 2056 | template <class _Compare2> |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 2057 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 2058 | void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 2059 | { |
| 2060 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 2061 | "merging container with incompatible allocator"); |
| 2062 | return __tree_.__node_handle_merge_multi(__source.__tree_); |
| 2063 | } |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 2064 | template <class _Compare2> |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 2065 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | d2322c8 | 2018-11-01 14:41:37 +0000 | [diff] [blame] | 2066 | void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) |
Erik Pilkington | 82a65ad | 2018-10-31 17:31:35 +0000 | [diff] [blame] | 2067 | { |
| 2068 | _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), |
| 2069 | "merging container with incompatible allocator"); |
| 2070 | return __tree_.__node_handle_merge_multi(__source.__tree_); |
| 2071 | } |
Erik Pilkington | c37a3d8 | 2018-08-01 01:33:38 +0000 | [diff] [blame] | 2072 | #endif |
| 2073 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2074 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | de1312a | 2018-08-22 04:28:43 +0000 | [diff] [blame] | 2075 | void clear() _NOEXCEPT {__tree_.clear();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2077 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 2078 | void swap(multimap& __m) |
| 2079 | _NOEXCEPT_(__is_nothrow_swappable<__base>::value) |
| 2080 | {__tree_.swap(__m.__tree_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2081 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2082 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2083 | iterator find(const key_type& __k) {return __tree_.find(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2084 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2085 | const_iterator find(const key_type& __k) const {return __tree_.find(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 2086 | #if _LIBCPP_STD_VER > 11 |
| 2087 | template <typename _K2> |
| 2088 | _LIBCPP_INLINE_VISIBILITY |
| 2089 | typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type |
| 2090 | find(const _K2& __k) {return __tree_.find(__k);} |
| 2091 | template <typename _K2> |
| 2092 | _LIBCPP_INLINE_VISIBILITY |
| 2093 | typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type |
| 2094 | find(const _K2& __k) const {return __tree_.find(__k);} |
| 2095 | #endif |
| 2096 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2097 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2098 | size_type count(const key_type& __k) const |
| 2099 | {return __tree_.__count_multi(__k);} |
Marshall Clow | e6a5f52 | 2014-08-24 23:54:16 +0000 | [diff] [blame] | 2100 | #if _LIBCPP_STD_VER > 11 |
| 2101 | template <typename _K2> |
| 2102 | _LIBCPP_INLINE_VISIBILITY |
| 2103 | typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type |
Marshall Clow | 141e47b | 2015-06-30 18:15:41 +0000 | [diff] [blame] | 2104 | count(const _K2& __k) const {return __tree_.__count_multi(__k);} |
Marshall Clow | e6a5f52 | 2014-08-24 23:54:16 +0000 | [diff] [blame] | 2105 | #endif |
Zoe Carver | 3ffbab1 | 2019-07-16 03:21:01 +0000 | [diff] [blame] | 2106 | |
| 2107 | #if _LIBCPP_STD_VER > 17 |
| 2108 | _LIBCPP_INLINE_VISIBILITY |
| 2109 | bool contains(const key_type& __k) const {return find(__k) != end();} |
Marek Kurdej | d7e019e | 2021-04-13 17:10:55 +0200 | [diff] [blame] | 2110 | template <typename _K2> |
| 2111 | _LIBCPP_INLINE_VISIBILITY |
| 2112 | typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type |
| 2113 | contains(const _K2& __k) const { return find(__k) != end(); } |
Zoe Carver | 3ffbab1 | 2019-07-16 03:21:01 +0000 | [diff] [blame] | 2114 | #endif // _LIBCPP_STD_VER > 17 |
| 2115 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2116 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2117 | iterator lower_bound(const key_type& __k) |
| 2118 | {return __tree_.lower_bound(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2119 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2120 | const_iterator lower_bound(const key_type& __k) const |
| 2121 | {return __tree_.lower_bound(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 2122 | #if _LIBCPP_STD_VER > 11 |
| 2123 | template <typename _K2> |
| 2124 | _LIBCPP_INLINE_VISIBILITY |
| 2125 | typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type |
| 2126 | lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} |
| 2127 | |
| 2128 | template <typename _K2> |
| 2129 | _LIBCPP_INLINE_VISIBILITY |
| 2130 | typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type |
| 2131 | lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} |
| 2132 | #endif |
| 2133 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2134 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2135 | iterator upper_bound(const key_type& __k) |
| 2136 | {return __tree_.upper_bound(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2138 | const_iterator upper_bound(const key_type& __k) const |
| 2139 | {return __tree_.upper_bound(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 2140 | #if _LIBCPP_STD_VER > 11 |
| 2141 | template <typename _K2> |
| 2142 | _LIBCPP_INLINE_VISIBILITY |
| 2143 | typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type |
| 2144 | upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} |
| 2145 | template <typename _K2> |
| 2146 | _LIBCPP_INLINE_VISIBILITY |
| 2147 | typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type |
| 2148 | upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} |
| 2149 | #endif |
| 2150 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2151 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2152 | pair<iterator,iterator> equal_range(const key_type& __k) |
| 2153 | {return __tree_.__equal_range_multi(__k);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2154 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2155 | pair<const_iterator,const_iterator> equal_range(const key_type& __k) const |
| 2156 | {return __tree_.__equal_range_multi(__k);} |
Marshall Clow | ebb5732 | 2013-08-13 22:18:47 +0000 | [diff] [blame] | 2157 | #if _LIBCPP_STD_VER > 11 |
| 2158 | template <typename _K2> |
| 2159 | _LIBCPP_INLINE_VISIBILITY |
| 2160 | typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type |
| 2161 | equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} |
| 2162 | template <typename _K2> |
| 2163 | _LIBCPP_INLINE_VISIBILITY |
| 2164 | typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type |
| 2165 | equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} |
| 2166 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2167 | |
| 2168 | private: |
| 2169 | typedef typename __base::__node __node; |
| 2170 | typedef typename __base::__node_allocator __node_allocator; |
| 2171 | typedef typename __base::__node_pointer __node_pointer; |
Eric Fiselier | a92b073 | 2016-02-20 07:12:17 +0000 | [diff] [blame] | 2172 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2173 | typedef __map_node_destructor<__node_allocator> _Dp; |
| 2174 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2175 | }; |
| 2176 | |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 2177 | #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 2178 | template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>, |
| 2179 | class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, |
Louis Dionne | 6c7da9a | 2019-07-19 17:13:39 +0000 | [diff] [blame] | 2180 | class = _EnableIf<!__is_allocator<_Compare>::value, void>, |
| 2181 | class = _EnableIf<__is_allocator<_Allocator>::value, void>> |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 2182 | multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) |
| 2183 | -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>; |
| 2184 | |
| 2185 | template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>, |
| 2186 | class _Allocator = allocator<pair<const _Key, _Tp>>, |
Louis Dionne | 6c7da9a | 2019-07-19 17:13:39 +0000 | [diff] [blame] | 2187 | class = _EnableIf<!__is_allocator<_Compare>::value, void>, |
| 2188 | class = _EnableIf<__is_allocator<_Allocator>::value, void>> |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 2189 | multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator()) |
| 2190 | -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>; |
| 2191 | |
| 2192 | template<class _InputIterator, class _Allocator, |
Louis Dionne | 6c7da9a | 2019-07-19 17:13:39 +0000 | [diff] [blame] | 2193 | class = _EnableIf<__is_allocator<_Allocator>::value, void>> |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 2194 | multimap(_InputIterator, _InputIterator, _Allocator) |
| 2195 | -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, |
| 2196 | less<__iter_key_type<_InputIterator>>, _Allocator>; |
| 2197 | |
| 2198 | template<class _Key, class _Tp, class _Allocator, |
Louis Dionne | 6c7da9a | 2019-07-19 17:13:39 +0000 | [diff] [blame] | 2199 | class = _EnableIf<__is_allocator<_Allocator>::value, void>> |
Louis Dionne | d23a5f2 | 2019-06-20 19:32:00 +0000 | [diff] [blame] | 2200 | multimap(initializer_list<pair<_Key, _Tp>>, _Allocator) |
| 2201 | -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>; |
| 2202 | #endif |
| 2203 | |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 2204 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2205 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 2206 | multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a) |
Marshall Clow | 657cbc4 | 2016-08-17 05:58:40 +0000 | [diff] [blame] | 2207 | : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2208 | { |
| 2209 | if (__a != __m.get_allocator()) |
| 2210 | { |
| 2211 | const_iterator __e = cend(); |
| 2212 | while (!__m.empty()) |
| 2213 | __tree_.__insert_multi(__e.__i_, |
Erik Pilkington | d3fe299 | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 2214 | _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2215 | } |
| 2216 | } |
Eric Fiselier | d06276b | 2016-03-31 02:15:15 +0000 | [diff] [blame] | 2217 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2218 | |
| 2219 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2220 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2221 | bool |
| 2222 | operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 2223 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 2224 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2225 | return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2229 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2230 | bool |
| 2231 | operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 2232 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 2233 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2234 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2238 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2239 | bool |
| 2240 | operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 2241 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 2242 | { |
| 2243 | return !(__x == __y); |
| 2244 | } |
| 2245 | |
| 2246 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2247 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2248 | bool |
| 2249 | operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 2250 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 2251 | { |
| 2252 | return __y < __x; |
| 2253 | } |
| 2254 | |
| 2255 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2256 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2257 | bool |
| 2258 | operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 2259 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 2260 | { |
| 2261 | return !(__x < __y); |
| 2262 | } |
| 2263 | |
| 2264 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2265 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2266 | bool |
| 2267 | operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 2268 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 2269 | { |
| 2270 | return !(__y < __x); |
| 2271 | } |
| 2272 | |
| 2273 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2274 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2275 | void |
| 2276 | swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 2277 | multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
Howard Hinnant | 2f1ea9c | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 2278 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2279 | { |
| 2280 | __x.swap(__y); |
| 2281 | } |
| 2282 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 2283 | #if _LIBCPP_STD_VER > 17 |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 2284 | template <class _Key, class _Tp, class _Compare, class _Allocator, |
| 2285 | class _Predicate> |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 2286 | inline _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 2287 | typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type |
| 2288 | erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, |
| 2289 | _Predicate __pred) { |
Arthur O'Dwyer | b6738bd | 2021-03-21 16:53:09 -0400 | [diff] [blame] | 2290 | return _VSTD::__libcpp_erase_if_container(__c, __pred); |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 2291 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 2292 | #endif |
| 2293 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2294 | _LIBCPP_END_NAMESPACE_STD |
| 2295 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2296 | #endif // _LIBCPP_MAP |