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