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