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