Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------- map ------------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_MAP |
| 12 | #define _LIBCPP_MAP |
| 13 | |
| 14 | /* |
| 15 | |
| 16 | map synopsis |
| 17 | |
| 18 | namespace std |
| 19 | { |
| 20 | |
| 21 | template <class Key, class T, class Compare = less<Key>, |
| 22 | class Allocator = allocator<pair<const Key, T>>> |
| 23 | class map |
| 24 | { |
| 25 | public: |
| 26 | // types: |
| 27 | typedef Key key_type; |
| 28 | typedef T mapped_type; |
| 29 | typedef pair<const key_type, mapped_type> value_type; |
| 30 | typedef Compare key_compare; |
| 31 | typedef Allocator allocator_type; |
| 32 | typedef typename allocator_type::reference reference; |
| 33 | typedef typename allocator_type::const_reference const_reference; |
| 34 | typedef typename allocator_type::pointer pointer; |
| 35 | typedef typename allocator_type::const_pointer const_pointer; |
| 36 | typedef typename allocator_type::size_type size_type; |
| 37 | typedef typename allocator_type::difference_type difference_type; |
| 38 | |
| 39 | typedef implementation-defined iterator; |
| 40 | typedef implementation-defined const_iterator; |
| 41 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 42 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 43 | |
| 44 | class value_compare |
| 45 | : public binary_function<value_type, value_type, bool> |
| 46 | { |
| 47 | friend class map; |
| 48 | protected: |
| 49 | key_compare comp; |
| 50 | |
| 51 | value_compare(key_compare c); |
| 52 | public: |
| 53 | bool operator()(const value_type& x, const value_type& y) const; |
| 54 | }; |
| 55 | |
| 56 | // construct/copy/destroy: |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 57 | map() |
| 58 | noexcept( |
| 59 | is_nothrow_default_constructible<allocator_type>::value && |
| 60 | is_nothrow_default_constructible<key_compare>::value && |
| 61 | is_nothrow_copy_constructible<key_compare>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | explicit map(const key_compare& comp); |
| 63 | map(const key_compare& comp, const allocator_type& a); |
| 64 | template <class InputIterator> |
| 65 | map(InputIterator first, InputIterator last, |
| 66 | const key_compare& comp = key_compare()); |
| 67 | template <class InputIterator> |
| 68 | map(InputIterator first, InputIterator last, |
| 69 | const key_compare& comp, const allocator_type& a); |
| 70 | map(const map& m); |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 71 | map(map&& m) |
| 72 | noexcept( |
| 73 | is_nothrow_move_constructible<allocator_type>::value && |
| 74 | is_nothrow_move_constructible<key_compare>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | explicit map(const allocator_type& a); |
| 76 | map(const map& m, const allocator_type& a); |
| 77 | map(map&& m, const allocator_type& a); |
| 78 | map(initializer_list<value_type> il, const key_compare& comp = key_compare()); |
| 79 | map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); |
| 80 | ~map(); |
| 81 | |
| 82 | map& operator=(const map& m); |
Howard Hinnant | 7686add | 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 | b2e2a8f | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 87 | is_nothrow_move_assignable<key_compare>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 88 | map& operator=(initializer_list<value_type> il); |
| 89 | |
| 90 | // iterators: |
Howard Hinnant | b2e2a8f | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 95 | |
Howard Hinnant | b2e2a8f | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 100 | |
Howard Hinnant | b2e2a8f | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 105 | |
| 106 | // capacity: |
Howard Hinnant | b2e2a8f | 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 | bc8d3f9 | 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 | b2e2a8f | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 136 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 137 | |
Howard Hinnant | 7686add | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 143 | |
| 144 | // observers: |
Howard Hinnant | b2e2a8f | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 145 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | bc8d3f9 | 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 | 7686add | 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 | bc8d3f9 | 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 | 7686add | 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 | bc8d3f9 | 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 | 7686add | 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 | bc8d3f9 | 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 | 7686add | 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 | b2e2a8f | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 262 | is_nothrow_move_assignable<key_compare>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | multimap& operator=(initializer_list<value_type> il); |
| 264 | |
| 265 | // iterators: |
Howard Hinnant | b2e2a8f | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | |
Howard Hinnant | b2e2a8f | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | |
Howard Hinnant | b2e2a8f | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | |
| 281 | // capacity: |
Howard Hinnant | b2e2a8f | 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 | bc8d3f9 | 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 | b2e2a8f | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 304 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 305 | |
Howard Hinnant | 7686add | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 311 | |
| 312 | // observers: |
Howard Hinnant | b2e2a8f | 2011-06-04 15:22:34 +0000 | [diff] [blame] | 313 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | bc8d3f9 | 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 | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 363 | multimap<Key, T, Compare, Allocator>& y) |
| 364 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 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 | 93c382b | 2011-01-04 19:21:05 +0000 | [diff] [blame] | 386 | typedef pair<typename std::remove_const<_Key>::type, _Tp> _P; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 | typedef pair<const _Key, _Tp> _CP; |
| 388 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 389 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 393 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 397 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 398 | const _Compare& key_comp() const _NOEXCEPT {return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 399 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 402 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 405 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 408 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 411 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 414 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 417 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 420 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 423 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | bc8d3f9 | 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 | 93c382b | 2011-01-04 19:21:05 +0000 | [diff] [blame] | 433 | typedef pair<typename std::remove_const<_Key>::type, _Tp> _P; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 434 | typedef pair<const _Key, _Tp> _CP; |
| 435 | |
| 436 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 437 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 441 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 445 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 446 | const _Compare& key_comp() const _NOEXCEPT {return comp;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 447 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 451 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 454 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 457 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 460 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 463 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 466 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 469 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 470 | bool operator()(const _Key& __x, const _P& __y) const |
| 471 | {return comp(__x, __y.first);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 472 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 473 | bool operator()(const _Key& __x, const _Key& __y) const |
| 474 | {return comp(__x, __y);} |
Howard Hinnant | bc8d3f9 | 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 | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 497 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 498 | explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 499 | : __na_(__na), |
| 500 | __first_constructed(false), |
| 501 | __second_constructed(false) |
| 502 | {} |
| 503 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 504 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 505 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 506 | __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 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 | bfd5530 | 2010-09-04 23:46:48 +0000 | [diff] [blame] | 513 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 514 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 515 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 516 | void operator()(pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 517 | { |
| 518 | if (__second_constructed) |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 519 | __alloc_traits::destroy(__na_, _STD::addressof(__p->__value_.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | if (__first_constructed) |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 521 | __alloc_traits::destroy(__na_, _STD::addressof(__p->__value_.first)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 522 | if (__p) |
| 523 | __alloc_traits::deallocate(__na_, __p, 1); |
| 524 | } |
| 525 | }; |
| 526 | |
| 527 | template <class, class, class, class> class map; |
| 528 | template <class, class, class, class> class multimap; |
| 529 | template <class> class __map_const_iterator; |
| 530 | |
| 531 | template <class _TreeIterator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 532 | class _LIBCPP_VISIBLE __map_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | { |
| 534 | _TreeIterator __i_; |
| 535 | |
| 536 | typedef typename _TreeIterator::__pointer_traits __pointer_traits; |
Howard Hinnant | df85e57 | 2011-02-27 18:02:02 +0000 | [diff] [blame] | 537 | typedef const typename _TreeIterator::value_type::first_type __key_type; |
| 538 | typedef typename _TreeIterator::value_type::second_type __mapped_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | public: |
| 540 | typedef bidirectional_iterator_tag iterator_category; |
Howard Hinnant | df85e57 | 2011-02-27 18:02:02 +0000 | [diff] [blame] | 541 | typedef pair<__key_type, __mapped_type> value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 542 | typedef typename _TreeIterator::difference_type difference_type; |
| 543 | typedef value_type& reference; |
| 544 | typedef typename __pointer_traits::template |
| 545 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 546 | rebind<value_type> |
| 547 | #else |
| 548 | rebind<value_type>::other |
| 549 | #endif |
| 550 | pointer; |
| 551 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 552 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 553 | __map_iterator() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 554 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 555 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 556 | __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 558 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 559 | reference operator*() const {return *operator->();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 560 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | pointer operator->() const {return (pointer)__i_.operator->();} |
| 562 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 563 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 564 | __map_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | __map_iterator operator++(int) |
| 567 | { |
| 568 | __map_iterator __t(*this); |
| 569 | ++(*this); |
| 570 | return __t; |
| 571 | } |
| 572 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 573 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 574 | __map_iterator& operator--() {--__i_; return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 575 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 576 | __map_iterator operator--(int) |
| 577 | { |
| 578 | __map_iterator __t(*this); |
| 579 | --(*this); |
| 580 | return __t; |
| 581 | } |
| 582 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 583 | friend _LIBCPP_INLINE_VISIBILITY |
| 584 | bool operator==(const __map_iterator& __x, const __map_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 585 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 586 | friend |
| 587 | _LIBCPP_INLINE_VISIBILITY |
| 588 | bool operator!=(const __map_iterator& __x, const __map_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 589 | {return __x.__i_ != __y.__i_;} |
| 590 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 591 | template <class, class, class, class> friend class _LIBCPP_VISIBLE map; |
| 592 | template <class, class, class, class> friend class _LIBCPP_VISIBLE multimap; |
| 593 | template <class> friend class _LIBCPP_VISIBLE __map_const_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | }; |
| 595 | |
| 596 | template <class _TreeIterator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 597 | class _LIBCPP_VISIBLE __map_const_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 598 | { |
| 599 | _TreeIterator __i_; |
| 600 | |
| 601 | typedef typename _TreeIterator::__pointer_traits __pointer_traits; |
Howard Hinnant | df85e57 | 2011-02-27 18:02:02 +0000 | [diff] [blame] | 602 | typedef const typename _TreeIterator::value_type::first_type __key_type; |
| 603 | typedef typename _TreeIterator::value_type::second_type __mapped_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | public: |
| 605 | typedef bidirectional_iterator_tag iterator_category; |
Howard Hinnant | df85e57 | 2011-02-27 18:02:02 +0000 | [diff] [blame] | 606 | typedef pair<__key_type, __mapped_type> value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 607 | typedef typename _TreeIterator::difference_type difference_type; |
| 608 | typedef const value_type& reference; |
| 609 | typedef typename __pointer_traits::template |
| 610 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | 9dbeff9 | 2011-04-11 02:18:41 +0000 | [diff] [blame] | 611 | rebind<const value_type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 612 | #else |
Howard Hinnant | 9dbeff9 | 2011-04-11 02:18:41 +0000 | [diff] [blame] | 613 | rebind<const value_type>::other |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 614 | #endif |
| 615 | pointer; |
| 616 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 618 | __map_const_iterator() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 620 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 621 | __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 622 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 623 | __map_const_iterator( |
| 624 | __map_iterator<typename _TreeIterator::__non_const_iterator> __i) |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 625 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | : __i_(__i.__i_) {} |
| 627 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 628 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 629 | reference operator*() const {return *operator->();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 630 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 631 | pointer operator->() const {return (pointer)__i_.operator->();} |
| 632 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 633 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 634 | __map_const_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 635 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 636 | __map_const_iterator operator++(int) |
| 637 | { |
| 638 | __map_const_iterator __t(*this); |
| 639 | ++(*this); |
| 640 | return __t; |
| 641 | } |
| 642 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 643 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 644 | __map_const_iterator& operator--() {--__i_; return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 645 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 646 | __map_const_iterator operator--(int) |
| 647 | { |
| 648 | __map_const_iterator __t(*this); |
| 649 | --(*this); |
| 650 | return __t; |
| 651 | } |
| 652 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 653 | friend _LIBCPP_INLINE_VISIBILITY |
| 654 | bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 655 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 656 | friend _LIBCPP_INLINE_VISIBILITY |
| 657 | bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | {return __x.__i_ != __y.__i_;} |
| 659 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 660 | template <class, class, class, class> friend class _LIBCPP_VISIBLE map; |
| 661 | template <class, class, class, class> friend class _LIBCPP_VISIBLE multimap; |
| 662 | template <class, class, class> friend class _LIBCPP_VISIBLE __tree_const_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | template <class _Key, class _Tp, class _Compare = less<_Key>, |
| 666 | class _Allocator = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 667 | class _LIBCPP_VISIBLE map |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 668 | { |
| 669 | public: |
| 670 | // types: |
| 671 | typedef _Key key_type; |
| 672 | typedef _Tp mapped_type; |
| 673 | typedef pair<const key_type, mapped_type> value_type; |
| 674 | typedef _Compare key_compare; |
| 675 | typedef _Allocator allocator_type; |
| 676 | typedef value_type& reference; |
| 677 | typedef const value_type& const_reference; |
| 678 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 679 | class _LIBCPP_VISIBLE value_compare |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 680 | : public binary_function<value_type, value_type, bool> |
| 681 | { |
| 682 | friend class map; |
| 683 | protected: |
| 684 | key_compare comp; |
| 685 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 686 | _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 687 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 688 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 689 | bool operator()(const value_type& __x, const value_type& __y) const |
| 690 | {return comp(__x.first, __y.first);} |
| 691 | }; |
| 692 | |
| 693 | private: |
| 694 | typedef pair<key_type, mapped_type> __value_type; |
| 695 | typedef __map_value_compare<key_type, mapped_type, key_compare> __vc; |
| 696 | typedef typename allocator_traits<allocator_type>::template |
| 697 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 698 | rebind_alloc<__value_type> |
| 699 | #else |
| 700 | rebind_alloc<__value_type>::other |
| 701 | #endif |
| 702 | __allocator_type; |
| 703 | typedef __tree<__value_type, __vc, __allocator_type> __base; |
| 704 | typedef typename __base::__node_traits __node_traits; |
| 705 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 706 | |
| 707 | __base __tree_; |
| 708 | |
| 709 | public: |
| 710 | typedef typename __alloc_traits::pointer pointer; |
| 711 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 712 | typedef typename __alloc_traits::size_type size_type; |
| 713 | typedef typename __alloc_traits::difference_type difference_type; |
| 714 | typedef __map_iterator<typename __base::iterator> iterator; |
| 715 | typedef __map_const_iterator<typename __base::const_iterator> const_iterator; |
| 716 | typedef _STD::reverse_iterator<iterator> reverse_iterator; |
| 717 | typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator; |
| 718 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 719 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 720 | explicit map(const key_compare& __comp = key_compare()) |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 721 | _NOEXCEPT_( |
| 722 | is_nothrow_default_constructible<allocator_type>::value && |
| 723 | is_nothrow_default_constructible<key_compare>::value && |
| 724 | is_nothrow_copy_constructible<key_compare>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 725 | : __tree_(__vc(__comp)) {} |
| 726 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 727 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 728 | explicit map(const key_compare& __comp, const allocator_type& __a) |
| 729 | : __tree_(__vc(__comp), __a) {} |
| 730 | |
| 731 | template <class _InputIterator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 732 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 733 | map(_InputIterator __f, _InputIterator __l, |
| 734 | const key_compare& __comp = key_compare()) |
| 735 | : __tree_(__vc(__comp)) |
| 736 | { |
| 737 | insert(__f, __l); |
| 738 | } |
| 739 | |
| 740 | template <class _InputIterator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 741 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 742 | map(_InputIterator __f, _InputIterator __l, |
| 743 | const key_compare& __comp, const allocator_type& __a) |
| 744 | : __tree_(__vc(__comp), __a) |
| 745 | { |
| 746 | insert(__f, __l); |
| 747 | } |
| 748 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 749 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 750 | map(const map& __m) |
| 751 | : __tree_(__m.__tree_) |
| 752 | { |
| 753 | insert(__m.begin(), __m.end()); |
| 754 | } |
| 755 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 756 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 757 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 758 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 759 | map(map&& __m) |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 760 | _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 761 | : __tree_(_STD::move(__m.__tree_)) |
| 762 | { |
| 763 | } |
| 764 | |
| 765 | map(map&& __m, const allocator_type& __a); |
| 766 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 767 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 768 | map(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) |
| 769 | : __tree_(__vc(__comp)) |
| 770 | { |
| 771 | insert(__il.begin(), __il.end()); |
| 772 | } |
| 773 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 774 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 775 | map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) |
| 776 | : __tree_(__vc(__comp), __a) |
| 777 | { |
| 778 | insert(__il.begin(), __il.end()); |
| 779 | } |
| 780 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 781 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 782 | map& operator=(map&& __m) |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 783 | _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 784 | { |
| 785 | __tree_ = _STD::move(__m.__tree_); |
| 786 | return *this; |
| 787 | } |
| 788 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 789 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 790 | map& operator=(initializer_list<value_type> __il) |
| 791 | { |
| 792 | __tree_.__assign_unique(__il.begin(), __il.end()); |
| 793 | return *this; |
| 794 | } |
| 795 | |
Howard Hinnant | bfd5530 | 2010-09-04 23:46:48 +0000 | [diff] [blame] | 796 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 797 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 799 | explicit map(const allocator_type& __a) |
| 800 | : __tree_(__a) |
| 801 | { |
| 802 | } |
| 803 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 804 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 805 | map(const map& __m, const allocator_type& __a) |
| 806 | : __tree_(__m.__tree_.value_comp(), __a) |
| 807 | { |
| 808 | insert(__m.begin(), __m.end()); |
| 809 | } |
| 810 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 811 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 812 | iterator begin() _NOEXCEPT {return __tree_.begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 813 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 814 | const_iterator begin() const _NOEXCEPT {return __tree_.begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 815 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 816 | iterator end() _NOEXCEPT {return __tree_.end();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 817 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 818 | const_iterator end() const _NOEXCEPT {return __tree_.end();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 819 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 820 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 821 | reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 822 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 823 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 824 | {return const_reverse_iterator(end());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 825 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 826 | reverse_iterator rend() _NOEXCEPT |
| 827 | {return reverse_iterator(begin());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 828 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 829 | const_reverse_iterator rend() const _NOEXCEPT |
| 830 | {return const_reverse_iterator(begin());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 832 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 833 | const_iterator cbegin() const _NOEXCEPT {return begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 834 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 835 | const_iterator cend() const _NOEXCEPT {return end();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 836 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 837 | const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 838 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 839 | const_reverse_iterator crend() const _NOEXCEPT {return rend();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 840 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 841 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 842 | bool empty() const _NOEXCEPT {return __tree_.size() == 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 843 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 844 | size_type size() const _NOEXCEPT {return __tree_.size();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 845 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 846 | size_type max_size() const _NOEXCEPT {return __tree_.max_size();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 847 | |
| 848 | mapped_type& operator[](const key_type& __k); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 849 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 850 | mapped_type& operator[](key_type&& __k); |
| 851 | #endif |
| 852 | |
| 853 | mapped_type& at(const key_type& __k); |
| 854 | const mapped_type& at(const key_type& __k) const; |
| 855 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 857 | allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 858 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 859 | key_compare key_comp() const {return __tree_.value_comp().key_comp();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 860 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 861 | value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());} |
| 862 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 863 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 864 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 865 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 866 | pair<iterator, bool> |
| 867 | emplace() {return __tree_.__emplace_unique();} |
| 868 | |
| 869 | template <class _A0, |
| 870 | class = typename enable_if<is_convertible<_A0, value_type>::value>::type> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 871 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 872 | pair<iterator, bool> |
| 873 | emplace(_A0&& __a0) |
| 874 | {return __tree_.__emplace_unique(_STD::forward<_A0>(__a0));} |
| 875 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 876 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 877 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 878 | template <class _A0, class ..._Args, |
| 879 | class = typename enable_if<is_convertible<_A0, key_type>::value>::type> |
| 880 | pair<iterator, bool> |
| 881 | emplace(_A0&& __a0, _Args&& ...__args); |
| 882 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 883 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 884 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 885 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 886 | iterator |
| 887 | emplace_hint(const_iterator __p) |
| 888 | {return __tree_.__emplace_hint_unique(__p.__i_);} |
| 889 | |
| 890 | template <class _A0, |
| 891 | class = typename enable_if<is_convertible<_A0, value_type>::value>::type> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 892 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 893 | iterator |
| 894 | emplace_hint(const_iterator __p, _A0&& __a0) |
| 895 | {return __tree_.__emplace_hint_unique(__p.__i_, _STD::forward<_A0>(__a0));} |
| 896 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 897 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 898 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 899 | template <class _A0, class ..._Args, |
| 900 | class = typename enable_if<is_convertible<_A0, key_type>::value>::type> |
| 901 | iterator |
| 902 | emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args); |
| 903 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 904 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 905 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 906 | template <class _P, |
| 907 | class = typename enable_if<is_convertible<_P, value_type>::value>::type> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 908 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 909 | pair<iterator, bool> insert(_P&& __p) |
| 910 | {return __tree_.__insert_unique(_STD::forward<_P>(__p));} |
| 911 | |
| 912 | template <class _P, |
| 913 | class = typename enable_if<is_convertible<_P, value_type>::value>::type> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 914 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 915 | iterator insert(const_iterator __pos, _P&& __p) |
| 916 | {return __tree_.__insert_unique(__pos.__i_, _STD::forward<_P>(__p));} |
| 917 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 918 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 919 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 920 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 921 | pair<iterator, bool> |
| 922 | insert(const value_type& __v) {return __tree_.__insert_unique(__v);} |
| 923 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 924 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 925 | iterator |
| 926 | insert(const_iterator __p, const value_type& __v) |
| 927 | {return __tree_.__insert_unique(__p.__i_, __v);} |
| 928 | |
| 929 | template <class _InputIterator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 930 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 931 | void insert(_InputIterator __f, _InputIterator __l) |
| 932 | { |
| 933 | for (const_iterator __e = cend(); __f != __l; ++__f) |
| 934 | insert(__e.__i_, *__f); |
| 935 | } |
| 936 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 937 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 938 | void insert(initializer_list<value_type> __il) |
| 939 | {insert(__il.begin(), __il.end());} |
| 940 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 941 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 942 | iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 943 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 944 | size_type erase(const key_type& __k) |
| 945 | {return __tree_.__erase_unique(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 946 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 947 | iterator erase(const_iterator __f, const_iterator __l) |
| 948 | {return __tree_.erase(__f.__i_, __l.__i_);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 949 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 950 | void clear() _NOEXCEPT {__tree_.clear();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 951 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 952 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 953 | void swap(map& __m) |
| 954 | _NOEXCEPT_(__is_nothrow_swappable<__base>::value) |
| 955 | {__tree_.swap(__m.__tree_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 956 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 957 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 958 | iterator find(const key_type& __k) {return __tree_.find(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 959 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 960 | const_iterator find(const key_type& __k) const {return __tree_.find(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 961 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 962 | size_type count(const key_type& __k) const |
| 963 | {return __tree_.__count_unique(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 964 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 965 | iterator lower_bound(const key_type& __k) |
| 966 | {return __tree_.lower_bound(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 967 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 968 | const_iterator lower_bound(const key_type& __k) const |
| 969 | {return __tree_.lower_bound(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 970 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 971 | iterator upper_bound(const key_type& __k) |
| 972 | {return __tree_.upper_bound(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 973 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 974 | const_iterator upper_bound(const key_type& __k) const |
| 975 | {return __tree_.upper_bound(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 976 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 977 | pair<iterator,iterator> equal_range(const key_type& __k) |
| 978 | {return __tree_.__equal_range_unique(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 979 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 980 | pair<const_iterator,const_iterator> equal_range(const key_type& __k) const |
| 981 | {return __tree_.__equal_range_unique(__k);} |
| 982 | |
| 983 | private: |
| 984 | typedef typename __base::__node __node; |
| 985 | typedef typename __base::__node_allocator __node_allocator; |
| 986 | typedef typename __base::__node_pointer __node_pointer; |
| 987 | typedef typename __base::__node_const_pointer __node_const_pointer; |
| 988 | typedef typename __base::__node_base_pointer __node_base_pointer; |
| 989 | typedef typename __base::__node_base_const_pointer __node_base_const_pointer; |
| 990 | typedef __map_node_destructor<__node_allocator> _D; |
| 991 | typedef unique_ptr<__node, _D> __node_holder; |
| 992 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 993 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 994 | __node_holder __construct_node(); |
| 995 | template <class _A0, |
| 996 | class = typename enable_if<is_convertible<_A0, value_type>::value>::type> |
| 997 | __node_holder __construct_node(_A0&& __a0); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 998 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 999 | template <class _A0, class ..._Args, |
| 1000 | class = typename enable_if<is_convertible<_A0, key_type>::value>::type> |
| 1001 | __node_holder __construct_node(_A0&& __a0, _Args&& ...__args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1002 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1003 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1004 | __node_holder __construct_node(const key_type& __k); |
| 1005 | #endif |
| 1006 | |
| 1007 | __node_base_pointer& |
| 1008 | __find_equal_key(__node_base_pointer& __parent, const key_type& __k); |
| 1009 | __node_base_pointer& |
| 1010 | __find_equal_key(const_iterator __hint, |
| 1011 | __node_base_pointer& __parent, const key_type& __k); |
| 1012 | __node_base_const_pointer |
| 1013 | __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const; |
| 1014 | }; |
| 1015 | |
| 1016 | // Find place to insert if __k doesn't exist |
| 1017 | // Set __parent to parent of null leaf |
| 1018 | // Return reference to null leaf |
| 1019 | // If __k exists, set parent to node of __k and return reference to node of __k |
| 1020 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1021 | typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer& |
| 1022 | map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent, |
| 1023 | const key_type& __k) |
| 1024 | { |
| 1025 | __node_pointer __nd = __tree_.__root(); |
| 1026 | if (__nd != nullptr) |
| 1027 | { |
| 1028 | while (true) |
| 1029 | { |
| 1030 | if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first)) |
| 1031 | { |
| 1032 | if (__nd->__left_ != nullptr) |
| 1033 | __nd = static_cast<__node_pointer>(__nd->__left_); |
| 1034 | else |
| 1035 | { |
| 1036 | __parent = __nd; |
| 1037 | return __parent->__left_; |
| 1038 | } |
| 1039 | } |
| 1040 | else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k)) |
| 1041 | { |
| 1042 | if (__nd->__right_ != nullptr) |
| 1043 | __nd = static_cast<__node_pointer>(__nd->__right_); |
| 1044 | else |
| 1045 | { |
| 1046 | __parent = __nd; |
| 1047 | return __parent->__right_; |
| 1048 | } |
| 1049 | } |
| 1050 | else |
| 1051 | { |
| 1052 | __parent = __nd; |
| 1053 | return __parent; |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | __parent = __tree_.__end_node(); |
| 1058 | return __parent->__left_; |
| 1059 | } |
| 1060 | |
| 1061 | // Find place to insert if __k doesn't exist |
| 1062 | // First check prior to __hint. |
| 1063 | // Next check after __hint. |
| 1064 | // Next do O(log N) search. |
| 1065 | // Set __parent to parent of null leaf |
| 1066 | // Return reference to null leaf |
| 1067 | // If __k exists, set parent to node of __k and return reference to node of __k |
| 1068 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1069 | typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer& |
| 1070 | map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(const_iterator __hint, |
| 1071 | __node_base_pointer& __parent, |
| 1072 | const key_type& __k) |
| 1073 | { |
| 1074 | if (__hint == end() || __tree_.value_comp().key_comp()(__k, __hint->first)) // check before |
| 1075 | { |
| 1076 | // __k < *__hint |
| 1077 | const_iterator __prior = __hint; |
| 1078 | if (__prior == begin() || __tree_.value_comp().key_comp()((--__prior)->first, __k)) |
| 1079 | { |
| 1080 | // *prev(__hint) < __k < *__hint |
| 1081 | if (__hint.__ptr_->__left_ == nullptr) |
| 1082 | { |
| 1083 | __parent = const_cast<__node_pointer&>(__hint.__ptr_); |
| 1084 | return __parent->__left_; |
| 1085 | } |
| 1086 | else |
| 1087 | { |
| 1088 | __parent = const_cast<__node_pointer&>(__prior.__ptr_); |
| 1089 | return __parent->__right_; |
| 1090 | } |
| 1091 | } |
| 1092 | // __k <= *prev(__hint) |
| 1093 | return __find_equal_key(__parent, __k); |
| 1094 | } |
| 1095 | else if (__tree_.value_comp().key_comp()(__hint->first, __k)) // check after |
| 1096 | { |
| 1097 | // *__hint < __k |
Howard Hinnant | 6cf5d8c | 2011-02-14 19:12:38 +0000 | [diff] [blame] | 1098 | const_iterator __next = _STD::next(__hint); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1099 | if (__next == end() || __tree_.value_comp().key_comp()(__k, __next->first)) |
| 1100 | { |
| 1101 | // *__hint < __k < *next(__hint) |
| 1102 | if (__hint.__ptr_->__right_ == nullptr) |
| 1103 | { |
| 1104 | __parent = const_cast<__node_pointer&>(__hint.__ptr_); |
| 1105 | return __parent->__right_; |
| 1106 | } |
| 1107 | else |
| 1108 | { |
| 1109 | __parent = const_cast<__node_pointer&>(__next.__ptr_); |
| 1110 | return __parent->__left_; |
| 1111 | } |
| 1112 | } |
| 1113 | // *next(__hint) <= __k |
| 1114 | return __find_equal_key(__parent, __k); |
| 1115 | } |
| 1116 | // else __k == *__hint |
| 1117 | __parent = const_cast<__node_pointer&>(__hint.__ptr_); |
| 1118 | return __parent; |
| 1119 | } |
| 1120 | |
| 1121 | // Find __k |
| 1122 | // Set __parent to parent of null leaf and |
| 1123 | // return reference to null leaf iv __k does not exist. |
| 1124 | // If __k exists, set parent to node of __k and return reference to node of __k |
| 1125 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1126 | typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer |
| 1127 | map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent, |
| 1128 | const key_type& __k) const |
| 1129 | { |
| 1130 | __node_const_pointer __nd = __tree_.__root(); |
| 1131 | if (__nd != nullptr) |
| 1132 | { |
| 1133 | while (true) |
| 1134 | { |
| 1135 | if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first)) |
| 1136 | { |
| 1137 | if (__nd->__left_ != nullptr) |
| 1138 | __nd = static_cast<__node_pointer>(__nd->__left_); |
| 1139 | else |
| 1140 | { |
| 1141 | __parent = __nd; |
| 1142 | return const_cast<const __node_base_const_pointer&>(__parent->__left_); |
| 1143 | } |
| 1144 | } |
| 1145 | else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k)) |
| 1146 | { |
| 1147 | if (__nd->__right_ != nullptr) |
| 1148 | __nd = static_cast<__node_pointer>(__nd->__right_); |
| 1149 | else |
| 1150 | { |
| 1151 | __parent = __nd; |
| 1152 | return const_cast<const __node_base_const_pointer&>(__parent->__right_); |
| 1153 | } |
| 1154 | } |
| 1155 | else |
| 1156 | { |
| 1157 | __parent = __nd; |
| 1158 | return __parent; |
| 1159 | } |
| 1160 | } |
| 1161 | } |
| 1162 | __parent = __tree_.__end_node(); |
| 1163 | return const_cast<const __node_base_const_pointer&>(__parent->__left_); |
| 1164 | } |
| 1165 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1166 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | |
| 1168 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1169 | map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a) |
| 1170 | : __tree_(_STD::move(__m.__tree_), __a) |
| 1171 | { |
| 1172 | if (__a != __m.get_allocator()) |
| 1173 | { |
| 1174 | const_iterator __e = cend(); |
| 1175 | while (!__m.empty()) |
| 1176 | __tree_.__insert_unique(__e.__i_, |
| 1177 | _STD::move(__m.__tree_.remove(__m.begin().__i_)->__value_)); |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1182 | typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder |
| 1183 | map<_Key, _Tp, _Compare, _Allocator>::__construct_node() |
| 1184 | { |
| 1185 | __node_allocator& __na = __tree_.__node_alloc(); |
| 1186 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1187 | __node_traits::construct(__na, _STD::addressof(__h->__value_.first)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1188 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1189 | __node_traits::construct(__na, _STD::addressof(__h->__value_.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1190 | __h.get_deleter().__second_constructed = true; |
| 1191 | return __h; |
| 1192 | } |
| 1193 | |
| 1194 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1195 | template <class _A0, |
| 1196 | class> |
| 1197 | typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder |
| 1198 | map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) |
| 1199 | { |
| 1200 | __node_allocator& __na = __tree_.__node_alloc(); |
| 1201 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1202 | __node_traits::construct(__na, _STD::addressof(__h->__value_), _STD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1203 | __h.get_deleter().__first_constructed = true; |
| 1204 | __h.get_deleter().__second_constructed = true; |
| 1205 | return __h; |
| 1206 | } |
| 1207 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1208 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1209 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1210 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1211 | template <class _A0, class ..._Args, |
| 1212 | class> |
| 1213 | typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder |
| 1214 | map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args) |
| 1215 | { |
| 1216 | __node_allocator& __na = __tree_.__node_alloc(); |
| 1217 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1218 | __node_traits::construct(__na, _STD::addressof(__h->__value_.first), _STD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1219 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1220 | __node_traits::construct(__na, _STD::addressof(__h->__value_.second), _STD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1221 | __h.get_deleter().__second_constructed = true; |
| 1222 | return __h; |
| 1223 | } |
| 1224 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1225 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1226 | |
| 1227 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1228 | |
| 1229 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1230 | typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder |
| 1231 | map<_Key, _Tp, _Compare, _Allocator>::__construct_node(const key_type& __k) |
| 1232 | { |
| 1233 | __node_allocator& __na = __tree_.__node_alloc(); |
| 1234 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1235 | __node_traits::construct(__na, _STD::addressof(__h->__value_.first), __k); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1236 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1237 | __node_traits::construct(__na, _STD::addressof(__h->__value_.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1238 | __h.get_deleter().__second_constructed = true; |
| 1239 | return _STD::move(__h); |
| 1240 | } |
| 1241 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1242 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1243 | |
| 1244 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1245 | _Tp& |
| 1246 | map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) |
| 1247 | { |
| 1248 | __node_base_pointer __parent; |
| 1249 | __node_base_pointer& __child = __find_equal_key(__parent, __k); |
| 1250 | __node_pointer __r = static_cast<__node_pointer>(__child); |
| 1251 | if (__child == nullptr) |
| 1252 | { |
| 1253 | __node_holder __h = __construct_node(__k); |
| 1254 | __tree_.__insert_node_at(__parent, __child, __h.get()); |
| 1255 | __r = __h.release(); |
| 1256 | } |
| 1257 | return __r->__value_.second; |
| 1258 | } |
| 1259 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1260 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1261 | |
| 1262 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1263 | _Tp& |
| 1264 | map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) |
| 1265 | { |
| 1266 | __node_base_pointer __parent; |
| 1267 | __node_base_pointer& __child = __find_equal_key(__parent, __k); |
| 1268 | __node_pointer __r = static_cast<__node_pointer>(__child); |
| 1269 | if (__child == nullptr) |
| 1270 | { |
| 1271 | __node_holder __h = __construct_node(_STD::move(__k)); |
| 1272 | __tree_.__insert_node_at(__parent, __child, __h.get()); |
| 1273 | __r = __h.release(); |
| 1274 | } |
| 1275 | return __r->__value_.second; |
| 1276 | } |
| 1277 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1278 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1279 | |
| 1280 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1281 | _Tp& |
| 1282 | map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) |
| 1283 | { |
| 1284 | __node_base_pointer __parent; |
| 1285 | __node_base_pointer& __child = __find_equal_key(__parent, __k); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1286 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1287 | if (__child == nullptr) |
| 1288 | throw out_of_range("map::at: key not found"); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1289 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1290 | return static_cast<__node_pointer>(__child)->__value_.second; |
| 1291 | } |
| 1292 | |
| 1293 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1294 | const _Tp& |
| 1295 | map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const |
| 1296 | { |
| 1297 | __node_base_const_pointer __parent; |
| 1298 | __node_base_const_pointer __child = __find_equal_key(__parent, __k); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1299 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1300 | if (__child == nullptr) |
| 1301 | throw out_of_range("map::at: key not found"); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1302 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1303 | return static_cast<__node_const_pointer>(__child)->__value_.second; |
| 1304 | } |
| 1305 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1306 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1307 | |
| 1308 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1309 | template <class _A0, class ..._Args, |
| 1310 | class //= typename enable_if<is_convertible<_A0, _Key>::value>::type |
| 1311 | > |
| 1312 | pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool> |
| 1313 | map<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args) |
| 1314 | { |
| 1315 | __node_holder __h = __construct_node(_STD::forward<_A0>(__a0), |
| 1316 | _STD::forward<_Args>(__args)...); |
| 1317 | pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get()); |
| 1318 | if (__r.second) |
| 1319 | __h.release(); |
| 1320 | return __r; |
| 1321 | } |
| 1322 | |
| 1323 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1324 | template <class _A0, class ..._Args, |
| 1325 | class //= typename enable_if<is_convertible<_A0, _Key>::value>::type |
| 1326 | > |
| 1327 | typename map<_Key, _Tp, _Compare, _Allocator>::iterator |
| 1328 | map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p, |
| 1329 | _A0&& __a0, _Args&& ...__args) |
| 1330 | { |
| 1331 | __node_holder __h = __construct_node(_STD::forward<_A0>(__a0), |
| 1332 | _STD::forward<_Args>(__args)...); |
| 1333 | iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get()); |
| 1334 | if (__r.__i_.__ptr_ == __h.get()) |
| 1335 | __h.release(); |
| 1336 | return __r; |
| 1337 | } |
| 1338 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1339 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1340 | |
| 1341 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1342 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1343 | bool |
| 1344 | operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1345 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1346 | { |
| 1347 | return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin()); |
| 1348 | } |
| 1349 | |
| 1350 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1351 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1352 | bool |
| 1353 | operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1354 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1355 | { |
| 1356 | return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
| 1357 | } |
| 1358 | |
| 1359 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1360 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1361 | bool |
| 1362 | operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1363 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1364 | { |
| 1365 | return !(__x == __y); |
| 1366 | } |
| 1367 | |
| 1368 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1369 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1370 | bool |
| 1371 | operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1372 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1373 | { |
| 1374 | return __y < __x; |
| 1375 | } |
| 1376 | |
| 1377 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1378 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1379 | bool |
| 1380 | operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1381 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1382 | { |
| 1383 | return !(__x < __y); |
| 1384 | } |
| 1385 | |
| 1386 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1387 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1388 | bool |
| 1389 | operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1390 | const map<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1391 | { |
| 1392 | return !(__y < __x); |
| 1393 | } |
| 1394 | |
| 1395 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1396 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1397 | void |
| 1398 | swap(map<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1399 | map<_Key, _Tp, _Compare, _Allocator>& __y) |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1400 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1401 | { |
| 1402 | __x.swap(__y); |
| 1403 | } |
| 1404 | |
| 1405 | template <class _Key, class _Tp, class _Compare = less<_Key>, |
| 1406 | class _Allocator = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1407 | class _LIBCPP_VISIBLE multimap |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1408 | { |
| 1409 | public: |
| 1410 | // types: |
| 1411 | typedef _Key key_type; |
| 1412 | typedef _Tp mapped_type; |
| 1413 | typedef pair<const key_type, mapped_type> value_type; |
| 1414 | typedef _Compare key_compare; |
| 1415 | typedef _Allocator allocator_type; |
| 1416 | typedef value_type& reference; |
| 1417 | typedef const value_type& const_reference; |
| 1418 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1419 | class _LIBCPP_VISIBLE value_compare |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1420 | : public binary_function<value_type, value_type, bool> |
| 1421 | { |
| 1422 | friend class multimap; |
| 1423 | protected: |
| 1424 | key_compare comp; |
| 1425 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1426 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1427 | value_compare(key_compare c) : comp(c) {} |
| 1428 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1429 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | bool operator()(const value_type& __x, const value_type& __y) const |
| 1431 | {return comp(__x.first, __y.first);} |
| 1432 | }; |
| 1433 | |
| 1434 | private: |
| 1435 | typedef pair<key_type, mapped_type> __value_type; |
| 1436 | typedef __map_value_compare<key_type, mapped_type, key_compare> __vc; |
| 1437 | typedef typename allocator_traits<allocator_type>::template |
| 1438 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1439 | rebind_alloc<__value_type> |
| 1440 | #else |
| 1441 | rebind_alloc<__value_type>::other |
| 1442 | #endif |
| 1443 | __allocator_type; |
| 1444 | typedef __tree<__value_type, __vc, __allocator_type> __base; |
| 1445 | typedef typename __base::__node_traits __node_traits; |
| 1446 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 1447 | |
| 1448 | __base __tree_; |
| 1449 | |
| 1450 | public: |
| 1451 | typedef typename __alloc_traits::pointer pointer; |
| 1452 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 1453 | typedef typename __alloc_traits::size_type size_type; |
| 1454 | typedef typename __alloc_traits::difference_type difference_type; |
| 1455 | typedef __map_iterator<typename __base::iterator> iterator; |
| 1456 | typedef __map_const_iterator<typename __base::const_iterator> const_iterator; |
| 1457 | typedef _STD::reverse_iterator<iterator> reverse_iterator; |
| 1458 | typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator; |
| 1459 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1460 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1461 | explicit multimap(const key_compare& __comp = key_compare()) |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1462 | _NOEXCEPT_( |
| 1463 | is_nothrow_default_constructible<allocator_type>::value && |
| 1464 | is_nothrow_default_constructible<key_compare>::value && |
| 1465 | is_nothrow_copy_constructible<key_compare>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1466 | : __tree_(__vc(__comp)) {} |
| 1467 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1468 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1469 | explicit multimap(const key_compare& __comp, const allocator_type& __a) |
| 1470 | : __tree_(__vc(__comp), __a) {} |
| 1471 | |
| 1472 | template <class _InputIterator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1473 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1474 | multimap(_InputIterator __f, _InputIterator __l, |
| 1475 | const key_compare& __comp = key_compare()) |
| 1476 | : __tree_(__vc(__comp)) |
| 1477 | { |
| 1478 | insert(__f, __l); |
| 1479 | } |
| 1480 | |
| 1481 | template <class _InputIterator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1482 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1483 | multimap(_InputIterator __f, _InputIterator __l, |
| 1484 | const key_compare& __comp, const allocator_type& __a) |
| 1485 | : __tree_(__vc(__comp), __a) |
| 1486 | { |
| 1487 | insert(__f, __l); |
| 1488 | } |
| 1489 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1490 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1491 | multimap(const multimap& __m) |
| 1492 | : __tree_(__m.__tree_.value_comp(), |
| 1493 | __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) |
| 1494 | { |
| 1495 | insert(__m.begin(), __m.end()); |
| 1496 | } |
| 1497 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1498 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1499 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1500 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1501 | multimap(multimap&& __m) |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1502 | _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1503 | : __tree_(_STD::move(__m.__tree_)) |
| 1504 | { |
| 1505 | } |
| 1506 | |
| 1507 | multimap(multimap&& __m, const allocator_type& __a); |
| 1508 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1509 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1510 | multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) |
| 1511 | : __tree_(__vc(__comp)) |
| 1512 | { |
| 1513 | insert(__il.begin(), __il.end()); |
| 1514 | } |
| 1515 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1517 | multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) |
| 1518 | : __tree_(__vc(__comp), __a) |
| 1519 | { |
| 1520 | insert(__il.begin(), __il.end()); |
| 1521 | } |
| 1522 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1523 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1524 | multimap& operator=(multimap&& __m) |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1525 | _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1526 | { |
| 1527 | __tree_ = _STD::move(__m.__tree_); |
| 1528 | return *this; |
| 1529 | } |
| 1530 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1531 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1532 | multimap& operator=(initializer_list<value_type> __il) |
| 1533 | { |
| 1534 | __tree_.__assign_multi(__il.begin(), __il.end()); |
| 1535 | return *this; |
| 1536 | } |
Howard Hinnant | bfd5530 | 2010-09-04 23:46:48 +0000 | [diff] [blame] | 1537 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1538 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1540 | explicit multimap(const allocator_type& __a) |
| 1541 | : __tree_(__a) |
| 1542 | { |
| 1543 | } |
| 1544 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1545 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1546 | multimap(const multimap& __m, const allocator_type& __a) |
| 1547 | : __tree_(__m.__tree_.value_comp(), __a) |
| 1548 | { |
| 1549 | insert(__m.begin(), __m.end()); |
| 1550 | } |
| 1551 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1552 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1553 | iterator begin() _NOEXCEPT {return __tree_.begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1554 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1555 | const_iterator begin() const _NOEXCEPT {return __tree_.begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1556 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1557 | iterator end() _NOEXCEPT {return __tree_.end();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1558 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1559 | const_iterator end() const _NOEXCEPT {return __tree_.end();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1560 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1561 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1562 | reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1563 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1564 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 1565 | {return const_reverse_iterator(end());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1566 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1567 | reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1568 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1569 | const_reverse_iterator rend() const _NOEXCEPT |
| 1570 | {return const_reverse_iterator(begin());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1571 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1572 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1573 | const_iterator cbegin() const _NOEXCEPT {return begin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1575 | const_iterator cend() const _NOEXCEPT {return end();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1577 | const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1579 | const_reverse_iterator crend() const _NOEXCEPT {return rend();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1580 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1581 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1582 | bool empty() const _NOEXCEPT {return __tree_.size() == 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1583 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1584 | size_type size() const _NOEXCEPT {return __tree_.size();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1585 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1586 | size_type max_size() const _NOEXCEPT {return __tree_.max_size();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1587 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1588 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1589 | allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1590 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1591 | key_compare key_comp() const {return __tree_.value_comp().key_comp();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1592 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1593 | value_compare value_comp() const |
| 1594 | {return value_compare(__tree_.value_comp().key_comp());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1595 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1596 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1597 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1598 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1599 | iterator emplace() {return __tree_.__emplace_multi();} |
| 1600 | |
| 1601 | template <class _A0, |
| 1602 | class = typename enable_if<is_convertible<_A0, value_type>::value>::type> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1603 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1604 | iterator |
| 1605 | emplace(_A0&& __a0) |
| 1606 | {return __tree_.__emplace_multi(_STD::forward<_A0>(__a0));} |
| 1607 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1608 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1609 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1610 | template <class _A0, class ..._Args, |
| 1611 | class = typename enable_if<is_convertible<_A0, key_type>::value>::type> |
| 1612 | iterator |
| 1613 | emplace(_A0&& __a0, _Args&& ...__args); |
| 1614 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1615 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1616 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1618 | iterator emplace_hint(const_iterator __p) |
| 1619 | {return __tree_.__emplace_hint_multi(__p.__i_);} |
| 1620 | |
| 1621 | template <class _A0, |
| 1622 | class = typename enable_if<is_convertible<_A0, value_type>::value>::type> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1623 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1624 | iterator |
| 1625 | emplace_hint(const_iterator __p, _A0&& __a0) |
| 1626 | {return __tree_.__emplace_hint_multi(__p.__i_, _STD::forward<_A0>(__a0));} |
| 1627 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1628 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1629 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1630 | template <class _A0, class ..._Args, |
| 1631 | class = typename enable_if<is_convertible<_A0, key_type>::value>::type> |
| 1632 | iterator |
| 1633 | emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args); |
| 1634 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1635 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1636 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1637 | template <class _P, |
| 1638 | class = typename enable_if<is_convertible<_P, value_type>::value>::type> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1639 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1640 | iterator insert(_P&& __p) |
| 1641 | {return __tree_.__insert_multi(_STD::forward<_P>(__p));} |
| 1642 | |
| 1643 | template <class _P, |
| 1644 | class = typename enable_if<is_convertible<_P, value_type>::value>::type> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1645 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1646 | iterator insert(const_iterator __pos, _P&& __p) |
| 1647 | {return __tree_.__insert_multi(__pos.__i_, _STD::forward<_P>(__p));} |
| 1648 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1649 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1650 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1651 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1652 | iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);} |
| 1653 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1654 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1655 | iterator insert(const_iterator __p, const value_type& __v) |
| 1656 | {return __tree_.__insert_multi(__p.__i_, __v);} |
| 1657 | |
| 1658 | template <class _InputIterator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1659 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1660 | void insert(_InputIterator __f, _InputIterator __l) |
| 1661 | { |
| 1662 | for (const_iterator __e = cend(); __f != __l; ++__f) |
| 1663 | __tree_.__insert_multi(__e.__i_, *__f); |
| 1664 | } |
| 1665 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1666 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1667 | void insert(initializer_list<value_type> __il) |
| 1668 | {insert(__il.begin(), __il.end());} |
| 1669 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1670 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1671 | iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1672 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1673 | size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1674 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1675 | iterator erase(const_iterator __f, const_iterator __l) |
| 1676 | {return __tree_.erase(__f.__i_, __l.__i_);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1677 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1678 | void clear() {__tree_.clear();} |
| 1679 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1680 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1681 | void swap(multimap& __m) |
| 1682 | _NOEXCEPT_(__is_nothrow_swappable<__base>::value) |
| 1683 | {__tree_.swap(__m.__tree_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1684 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1685 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1686 | iterator find(const key_type& __k) {return __tree_.find(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1687 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1688 | const_iterator find(const key_type& __k) const {return __tree_.find(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1689 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1690 | size_type count(const key_type& __k) const |
| 1691 | {return __tree_.__count_multi(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1692 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1693 | iterator lower_bound(const key_type& __k) |
| 1694 | {return __tree_.lower_bound(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1695 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1696 | const_iterator lower_bound(const key_type& __k) const |
| 1697 | {return __tree_.lower_bound(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1698 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1699 | iterator upper_bound(const key_type& __k) |
| 1700 | {return __tree_.upper_bound(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1701 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1702 | const_iterator upper_bound(const key_type& __k) const |
| 1703 | {return __tree_.upper_bound(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1704 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1705 | pair<iterator,iterator> equal_range(const key_type& __k) |
| 1706 | {return __tree_.__equal_range_multi(__k);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1707 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1708 | pair<const_iterator,const_iterator> equal_range(const key_type& __k) const |
| 1709 | {return __tree_.__equal_range_multi(__k);} |
| 1710 | |
| 1711 | private: |
| 1712 | typedef typename __base::__node __node; |
| 1713 | typedef typename __base::__node_allocator __node_allocator; |
| 1714 | typedef typename __base::__node_pointer __node_pointer; |
| 1715 | typedef typename __base::__node_const_pointer __node_const_pointer; |
| 1716 | typedef __map_node_destructor<__node_allocator> _D; |
| 1717 | typedef unique_ptr<__node, _D> __node_holder; |
| 1718 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1719 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1720 | __node_holder __construct_node(); |
| 1721 | template <class _A0, |
| 1722 | class = typename enable_if<is_convertible<_A0, value_type>::value>::type> |
| 1723 | __node_holder __construct_node(_A0&& __a0); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1724 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1725 | template <class _A0, class ..._Args, |
| 1726 | class = typename enable_if<is_convertible<_A0, key_type>::value>::type> |
| 1727 | __node_holder __construct_node(_A0&& __a0, _Args&& ...__args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1728 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1729 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1730 | }; |
| 1731 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1732 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1733 | |
| 1734 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1735 | multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a) |
| 1736 | : __tree_(_STD::move(__m.__tree_), __a) |
| 1737 | { |
| 1738 | if (__a != __m.get_allocator()) |
| 1739 | { |
| 1740 | const_iterator __e = cend(); |
| 1741 | while (!__m.empty()) |
| 1742 | __tree_.__insert_multi(__e.__i_, |
| 1743 | _STD::move(__m.__tree_.remove(__m.begin().__i_)->__value_)); |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1748 | typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder |
| 1749 | multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node() |
| 1750 | { |
| 1751 | __node_allocator& __na = __tree_.__node_alloc(); |
| 1752 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1753 | __node_traits::construct(__na, _STD::addressof(__h->__value_.first)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1754 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1755 | __node_traits::construct(__na, _STD::addressof(__h->__value_.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1756 | __h.get_deleter().__second_constructed = true; |
| 1757 | return __h; |
| 1758 | } |
| 1759 | |
| 1760 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1761 | template <class _A0, |
| 1762 | class // = typename enable_if<is_convertible<_A0, value_type>::value>::type |
| 1763 | > |
| 1764 | typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder |
| 1765 | multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) |
| 1766 | { |
| 1767 | __node_allocator& __na = __tree_.__node_alloc(); |
| 1768 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1769 | __node_traits::construct(__na, _STD::addressof(__h->__value_), _STD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1770 | __h.get_deleter().__first_constructed = true; |
| 1771 | __h.get_deleter().__second_constructed = true; |
| 1772 | return __h; |
| 1773 | } |
| 1774 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1775 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1776 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1777 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1778 | template <class _A0, class ..._Args, |
| 1779 | class // = typename enable_if<is_convertible<_A0, key_type>::value>::type |
| 1780 | > |
| 1781 | typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder |
| 1782 | multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args) |
| 1783 | { |
| 1784 | __node_allocator& __na = __tree_.__node_alloc(); |
| 1785 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1786 | __node_traits::construct(__na, _STD::addressof(__h->__value_.first), _STD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1787 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1788 | __node_traits::construct(__na, _STD::addressof(__h->__value_.second), _STD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1789 | __h.get_deleter().__second_constructed = true; |
| 1790 | return __h; |
| 1791 | } |
| 1792 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1793 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1794 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1795 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1796 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1797 | |
| 1798 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1799 | template <class _A0, class ..._Args, |
| 1800 | class //= typename enable_if<is_convertible<_A0, _Key>::value>::type |
| 1801 | > |
| 1802 | typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator |
| 1803 | multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args) |
| 1804 | { |
| 1805 | __node_holder __h = __construct_node(_STD::forward<_A0>(__a0), |
| 1806 | _STD::forward<_Args>(__args)...); |
| 1807 | iterator __r = __tree_.__node_insert_multi(__h.get()); |
| 1808 | __h.release(); |
| 1809 | return __r; |
| 1810 | } |
| 1811 | |
| 1812 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
| 1813 | template <class _A0, class ..._Args, |
| 1814 | class //= typename enable_if<is_convertible<_A0, _Key>::value>::type |
| 1815 | > |
| 1816 | typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator |
| 1817 | multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p, |
| 1818 | _A0&& __a0, |
| 1819 | _Args&& ...__args) |
| 1820 | { |
| 1821 | __node_holder __h = __construct_node(_STD::forward<_A0>(__a0), |
| 1822 | _STD::forward<_Args>(__args)...); |
| 1823 | iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get()); |
| 1824 | __h.release(); |
| 1825 | return __r; |
| 1826 | } |
| 1827 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1828 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1829 | |
| 1830 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1831 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1832 | bool |
| 1833 | operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1834 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1835 | { |
| 1836 | return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin()); |
| 1837 | } |
| 1838 | |
| 1839 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1840 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1841 | bool |
| 1842 | operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1843 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1844 | { |
| 1845 | return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
| 1846 | } |
| 1847 | |
| 1848 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1849 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1850 | bool |
| 1851 | operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1852 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1853 | { |
| 1854 | return !(__x == __y); |
| 1855 | } |
| 1856 | |
| 1857 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1858 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1859 | bool |
| 1860 | operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1861 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1862 | { |
| 1863 | return __y < __x; |
| 1864 | } |
| 1865 | |
| 1866 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1867 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1868 | bool |
| 1869 | operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1870 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1871 | { |
| 1872 | return !(__x < __y); |
| 1873 | } |
| 1874 | |
| 1875 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1876 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1877 | bool |
| 1878 | operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1879 | const multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
| 1880 | { |
| 1881 | return !(__y < __x); |
| 1882 | } |
| 1883 | |
| 1884 | template <class _Key, class _Tp, class _Compare, class _Allocator> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1885 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1886 | void |
| 1887 | swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, |
| 1888 | multimap<_Key, _Tp, _Compare, _Allocator>& __y) |
Howard Hinnant | 7686add | 2011-06-04 14:31:57 +0000 | [diff] [blame] | 1889 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1890 | { |
| 1891 | __x.swap(__y); |
| 1892 | } |
| 1893 | |
| 1894 | _LIBCPP_END_NAMESPACE_STD |
| 1895 | |
| 1896 | #endif // _LIBCPP_MAP |