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