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