10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_MAP 110b57cec5SDimitry Andric#define _LIBCPP_MAP 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric map synopsis 160b57cec5SDimitry Andric 170b57cec5SDimitry Andricnamespace std 180b57cec5SDimitry Andric{ 190b57cec5SDimitry Andric 200b57cec5SDimitry Andrictemplate <class Key, class T, class Compare = less<Key>, 210b57cec5SDimitry Andric class Allocator = allocator<pair<const Key, T>>> 220b57cec5SDimitry Andricclass map 230b57cec5SDimitry Andric{ 240b57cec5SDimitry Andricpublic: 250b57cec5SDimitry Andric // types: 260b57cec5SDimitry Andric typedef Key key_type; 270b57cec5SDimitry Andric typedef T mapped_type; 280b57cec5SDimitry Andric typedef pair<const key_type, mapped_type> value_type; 290b57cec5SDimitry Andric typedef Compare key_compare; 300b57cec5SDimitry Andric typedef Allocator allocator_type; 310b57cec5SDimitry Andric typedef typename allocator_type::reference reference; 320b57cec5SDimitry Andric typedef typename allocator_type::const_reference const_reference; 330b57cec5SDimitry Andric typedef typename allocator_type::pointer pointer; 340b57cec5SDimitry Andric typedef typename allocator_type::const_pointer const_pointer; 350b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 360b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric typedef implementation-defined iterator; 390b57cec5SDimitry Andric typedef implementation-defined const_iterator; 400b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 410b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 420b57cec5SDimitry Andric typedef unspecified node_type; // C++17 430b57cec5SDimitry Andric typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric class value_compare 460b57cec5SDimitry Andric { 470b57cec5SDimitry Andric friend class map; 480b57cec5SDimitry Andric protected: 490b57cec5SDimitry Andric key_compare comp; 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric value_compare(key_compare c); 520b57cec5SDimitry Andric public: 53fe6060f1SDimitry Andric typedef bool result_type; // deprecated in C++17, removed in C++20 54fe6060f1SDimitry Andric typedef value_type first_argument_type; // deprecated in C++17, removed in C++20 55fe6060f1SDimitry Andric typedef value_type second_argument_type; // deprecated in C++17, removed in C++20 560b57cec5SDimitry Andric bool operator()(const value_type& x, const value_type& y) const; 570b57cec5SDimitry Andric }; 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric // construct/copy/destroy: 600b57cec5SDimitry Andric map() 610b57cec5SDimitry Andric noexcept( 620b57cec5SDimitry Andric is_nothrow_default_constructible<allocator_type>::value && 630b57cec5SDimitry Andric is_nothrow_default_constructible<key_compare>::value && 640b57cec5SDimitry Andric is_nothrow_copy_constructible<key_compare>::value); 650b57cec5SDimitry Andric explicit map(const key_compare& comp); 660b57cec5SDimitry Andric map(const key_compare& comp, const allocator_type& a); 670b57cec5SDimitry Andric template <class InputIterator> 680b57cec5SDimitry Andric map(InputIterator first, InputIterator last, 690b57cec5SDimitry Andric const key_compare& comp = key_compare()); 700b57cec5SDimitry Andric template <class InputIterator> 710b57cec5SDimitry Andric map(InputIterator first, InputIterator last, 720b57cec5SDimitry Andric const key_compare& comp, const allocator_type& a); 73*06c3fb27SDimitry Andric template<container-compatible-range<value_type> R> 74*06c3fb27SDimitry Andric map(from_range_t, R&& rg, const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23 750b57cec5SDimitry Andric map(const map& m); 760b57cec5SDimitry Andric map(map&& m) 770b57cec5SDimitry Andric noexcept( 780b57cec5SDimitry Andric is_nothrow_move_constructible<allocator_type>::value && 790b57cec5SDimitry Andric is_nothrow_move_constructible<key_compare>::value); 800b57cec5SDimitry Andric explicit map(const allocator_type& a); 810b57cec5SDimitry Andric map(const map& m, const allocator_type& a); 820b57cec5SDimitry Andric map(map&& m, const allocator_type& a); 830b57cec5SDimitry Andric map(initializer_list<value_type> il, const key_compare& comp = key_compare()); 840b57cec5SDimitry Andric map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); 850b57cec5SDimitry Andric template <class InputIterator> 860b57cec5SDimitry Andric map(InputIterator first, InputIterator last, const allocator_type& a) 870b57cec5SDimitry Andric : map(first, last, Compare(), a) {} // C++14 88*06c3fb27SDimitry Andric template<container-compatible-range<value_type> R> 89*06c3fb27SDimitry Andric map(from_range_t, R&& rg, const Allocator& a)) 90*06c3fb27SDimitry Andric : map(from_range, std::forward<R>(rg), Compare(), a) { } // C++23 910b57cec5SDimitry Andric map(initializer_list<value_type> il, const allocator_type& a) 920b57cec5SDimitry Andric : map(il, Compare(), a) {} // C++14 930b57cec5SDimitry Andric ~map(); 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric map& operator=(const map& m); 960b57cec5SDimitry Andric map& operator=(map&& m) 970b57cec5SDimitry Andric noexcept( 980b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value && 990b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value && 1000b57cec5SDimitry Andric is_nothrow_move_assignable<key_compare>::value); 1010b57cec5SDimitry Andric map& operator=(initializer_list<value_type> il); 1020b57cec5SDimitry Andric 1030b57cec5SDimitry Andric // iterators: 1040b57cec5SDimitry Andric iterator begin() noexcept; 1050b57cec5SDimitry Andric const_iterator begin() const noexcept; 1060b57cec5SDimitry Andric iterator end() noexcept; 1070b57cec5SDimitry Andric const_iterator end() const noexcept; 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 1100b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 1110b57cec5SDimitry Andric reverse_iterator rend() noexcept; 1120b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 1150b57cec5SDimitry Andric const_iterator cend() const noexcept; 1160b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 1170b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 1180b57cec5SDimitry Andric 1190b57cec5SDimitry Andric // capacity: 1200b57cec5SDimitry Andric bool empty() const noexcept; 1210b57cec5SDimitry Andric size_type size() const noexcept; 1220b57cec5SDimitry Andric size_type max_size() const noexcept; 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric // element access: 1250b57cec5SDimitry Andric mapped_type& operator[](const key_type& k); 1260b57cec5SDimitry Andric mapped_type& operator[](key_type&& k); 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andric mapped_type& at(const key_type& k); 1290b57cec5SDimitry Andric const mapped_type& at(const key_type& k) const; 1300b57cec5SDimitry Andric 1310b57cec5SDimitry Andric // modifiers: 1320b57cec5SDimitry Andric template <class... Args> 1330b57cec5SDimitry Andric pair<iterator, bool> emplace(Args&&... args); 1340b57cec5SDimitry Andric template <class... Args> 1350b57cec5SDimitry Andric iterator emplace_hint(const_iterator position, Args&&... args); 1360b57cec5SDimitry Andric pair<iterator, bool> insert(const value_type& v); 1370b57cec5SDimitry Andric pair<iterator, bool> insert( value_type&& v); // C++17 1380b57cec5SDimitry Andric template <class P> 1390b57cec5SDimitry Andric pair<iterator, bool> insert(P&& p); 1400b57cec5SDimitry Andric iterator insert(const_iterator position, const value_type& v); 1410b57cec5SDimitry Andric iterator insert(const_iterator position, value_type&& v); // C++17 1420b57cec5SDimitry Andric template <class P> 1430b57cec5SDimitry Andric iterator insert(const_iterator position, P&& p); 1440b57cec5SDimitry Andric template <class InputIterator> 1450b57cec5SDimitry Andric void insert(InputIterator first, InputIterator last); 146*06c3fb27SDimitry Andric template<container-compatible-range<value_type> R> 147*06c3fb27SDimitry Andric void insert_range(R&& rg); // C++23 1480b57cec5SDimitry Andric void insert(initializer_list<value_type> il); 1490b57cec5SDimitry Andric 1500b57cec5SDimitry Andric node_type extract(const_iterator position); // C++17 1510b57cec5SDimitry Andric node_type extract(const key_type& x); // C++17 1520b57cec5SDimitry Andric insert_return_type insert(node_type&& nh); // C++17 1530b57cec5SDimitry Andric iterator insert(const_iterator hint, node_type&& nh); // C++17 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric template <class... Args> 1560b57cec5SDimitry Andric pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17 1570b57cec5SDimitry Andric template <class... Args> 1580b57cec5SDimitry Andric pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17 1590b57cec5SDimitry Andric template <class... Args> 1600b57cec5SDimitry Andric iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17 1610b57cec5SDimitry Andric template <class... Args> 1620b57cec5SDimitry Andric iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17 1630b57cec5SDimitry Andric template <class M> 1640b57cec5SDimitry Andric pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17 1650b57cec5SDimitry Andric template <class M> 1660b57cec5SDimitry Andric pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17 1670b57cec5SDimitry Andric template <class M> 1680b57cec5SDimitry Andric iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17 1690b57cec5SDimitry Andric template <class M> 1700b57cec5SDimitry Andric iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17 1710b57cec5SDimitry Andric 1720b57cec5SDimitry Andric iterator erase(const_iterator position); 1730b57cec5SDimitry Andric iterator erase(iterator position); // C++14 1740b57cec5SDimitry Andric size_type erase(const key_type& k); 1750b57cec5SDimitry Andric iterator erase(const_iterator first, const_iterator last); 1760b57cec5SDimitry Andric void clear() noexcept; 1770b57cec5SDimitry Andric 1780b57cec5SDimitry Andric template<class C2> 1790b57cec5SDimitry Andric void merge(map<Key, T, C2, Allocator>& source); // C++17 1800b57cec5SDimitry Andric template<class C2> 1810b57cec5SDimitry Andric void merge(map<Key, T, C2, Allocator>&& source); // C++17 1820b57cec5SDimitry Andric template<class C2> 1830b57cec5SDimitry Andric void merge(multimap<Key, T, C2, Allocator>& source); // C++17 1840b57cec5SDimitry Andric template<class C2> 1850b57cec5SDimitry Andric void merge(multimap<Key, T, C2, Allocator>&& source); // C++17 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric void swap(map& m) 1880b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::is_always_equal::value && 1890b57cec5SDimitry Andric is_nothrow_swappable<key_compare>::value); // C++17 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andric // observers: 1920b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 1930b57cec5SDimitry Andric key_compare key_comp() const; 1940b57cec5SDimitry Andric value_compare value_comp() const; 1950b57cec5SDimitry Andric 1960b57cec5SDimitry Andric // map operations: 1970b57cec5SDimitry Andric iterator find(const key_type& k); 1980b57cec5SDimitry Andric const_iterator find(const key_type& k) const; 1990b57cec5SDimitry Andric template<typename K> 2000b57cec5SDimitry Andric iterator find(const K& x); // C++14 2010b57cec5SDimitry Andric template<typename K> 2020b57cec5SDimitry Andric const_iterator find(const K& x) const; // C++14 203fe6060f1SDimitry Andric 2040b57cec5SDimitry Andric template<typename K> 2050b57cec5SDimitry Andric size_type count(const K& x) const; // C++14 2060b57cec5SDimitry Andric size_type count(const key_type& k) const; 207fe6060f1SDimitry Andric 2080b57cec5SDimitry Andric bool contains(const key_type& x) const; // C++20 209fe6060f1SDimitry Andric template<class K> bool contains(const K& x) const; // C++20 210fe6060f1SDimitry Andric 2110b57cec5SDimitry Andric iterator lower_bound(const key_type& k); 2120b57cec5SDimitry Andric const_iterator lower_bound(const key_type& k) const; 2130b57cec5SDimitry Andric template<typename K> 2140b57cec5SDimitry Andric iterator lower_bound(const K& x); // C++14 2150b57cec5SDimitry Andric template<typename K> 2160b57cec5SDimitry Andric const_iterator lower_bound(const K& x) const; // C++14 2170b57cec5SDimitry Andric 2180b57cec5SDimitry Andric iterator upper_bound(const key_type& k); 2190b57cec5SDimitry Andric const_iterator upper_bound(const key_type& k) const; 2200b57cec5SDimitry Andric template<typename K> 2210b57cec5SDimitry Andric iterator upper_bound(const K& x); // C++14 2220b57cec5SDimitry Andric template<typename K> 2230b57cec5SDimitry Andric const_iterator upper_bound(const K& x) const; // C++14 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andric pair<iterator,iterator> equal_range(const key_type& k); 2260b57cec5SDimitry Andric pair<const_iterator,const_iterator> equal_range(const key_type& k) const; 2270b57cec5SDimitry Andric template<typename K> 2280b57cec5SDimitry Andric pair<iterator,iterator> equal_range(const K& x); // C++14 2290b57cec5SDimitry Andric template<typename K> 2300b57cec5SDimitry Andric pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14 2310b57cec5SDimitry Andric}; 2320b57cec5SDimitry Andric 233349cc55cSDimitry Andrictemplate <class InputIterator, 234349cc55cSDimitry Andric class Compare = less<iter_key_t<InputIterator>>, 235349cc55cSDimitry Andric class Allocator = allocator<iter_to_alloc_t<InputIterator>>> 236349cc55cSDimitry Andricmap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator()) 237349cc55cSDimitry Andric -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17 238349cc55cSDimitry Andric 239*06c3fb27SDimitry Andrictemplate<ranges::input_range R, class Compare = less<range-key-type<R>, 240*06c3fb27SDimitry Andric class Allocator = allocator<range-to-alloc-type<R>>> 241*06c3fb27SDimitry Andric map(from_range_t, R&&, Compare = Compare(), Allocator = Allocator()) 242*06c3fb27SDimitry Andric -> map<range-key-type<R>, range-mapped-type<R>, Compare, Allocator>; // C++23 243*06c3fb27SDimitry Andric 244349cc55cSDimitry Andrictemplate<class Key, class T, class Compare = less<Key>, 245349cc55cSDimitry Andric class Allocator = allocator<pair<const Key, T>>> 246349cc55cSDimitry Andricmap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator()) 247349cc55cSDimitry Andric -> map<Key, T, Compare, Allocator>; // C++17 248349cc55cSDimitry Andric 249349cc55cSDimitry Andrictemplate <class InputIterator, class Allocator> 250349cc55cSDimitry Andricmap(InputIterator, InputIterator, Allocator) 251349cc55cSDimitry Andric -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, less<iter_key_t<InputIterator>>, 252349cc55cSDimitry Andric Allocator>; // C++17 253349cc55cSDimitry Andric 254*06c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator> 255*06c3fb27SDimitry Andric map(from_range_t, R&&, Allocator) 256*06c3fb27SDimitry Andric -> map<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>, Allocator>; // C++23 257*06c3fb27SDimitry Andric 258349cc55cSDimitry Andrictemplate<class Key, class T, class Allocator> 259349cc55cSDimitry Andricmap(initializer_list<pair<const Key, T>>, Allocator) -> map<Key, T, less<Key>, Allocator>; // C++17 260349cc55cSDimitry Andric 2610b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 2620b57cec5SDimitry Andricbool 2630b57cec5SDimitry Andricoperator==(const map<Key, T, Compare, Allocator>& x, 2640b57cec5SDimitry Andric const map<Key, T, Compare, Allocator>& y); 2650b57cec5SDimitry Andric 2660b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 2670b57cec5SDimitry Andricbool 2680b57cec5SDimitry Andricoperator< (const map<Key, T, Compare, Allocator>& x, 269*06c3fb27SDimitry Andric const map<Key, T, Compare, Allocator>& y); // removed in C++20 2700b57cec5SDimitry Andric 2710b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 2720b57cec5SDimitry Andricbool 2730b57cec5SDimitry Andricoperator!=(const map<Key, T, Compare, Allocator>& x, 274*06c3fb27SDimitry Andric const map<Key, T, Compare, Allocator>& y); // removed in C++20 2750b57cec5SDimitry Andric 2760b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 2770b57cec5SDimitry Andricbool 2780b57cec5SDimitry Andricoperator> (const map<Key, T, Compare, Allocator>& x, 279*06c3fb27SDimitry Andric const map<Key, T, Compare, Allocator>& y); // removed in C++20 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 2820b57cec5SDimitry Andricbool 2830b57cec5SDimitry Andricoperator>=(const map<Key, T, Compare, Allocator>& x, 284*06c3fb27SDimitry Andric const map<Key, T, Compare, Allocator>& y); // removed in C++20 2850b57cec5SDimitry Andric 2860b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 2870b57cec5SDimitry Andricbool 2880b57cec5SDimitry Andricoperator<=(const map<Key, T, Compare, Allocator>& x, 289*06c3fb27SDimitry Andric const map<Key, T, Compare, Allocator>& y); // removed in C++20 290*06c3fb27SDimitry Andric 291*06c3fb27SDimitry Andrictemplate<class Key, class T, class Compare, class Allocator> 292*06c3fb27SDimitry Andric synth-three-way-result<pair<const Key, T>> 293*06c3fb27SDimitry Andric operator<=>(const map<Key, T, Compare, Allocator>& x, 294*06c3fb27SDimitry Andric const map<Key, T, Compare, Allocator>& y); // since C++20 2950b57cec5SDimitry Andric 2960b57cec5SDimitry Andric// specialized algorithms: 2970b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 2980b57cec5SDimitry Andricvoid 2990b57cec5SDimitry Andricswap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y) 3000b57cec5SDimitry Andric noexcept(noexcept(x.swap(y))); 3010b57cec5SDimitry Andric 3020b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator, class Predicate> 3035ffd83dbSDimitry Andrictypename map<Key, T, Compare, Allocator>::size_type 3045ffd83dbSDimitry Andricerase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20 3050b57cec5SDimitry Andric 3060b57cec5SDimitry Andric 3070b57cec5SDimitry Andrictemplate <class Key, class T, class Compare = less<Key>, 3080b57cec5SDimitry Andric class Allocator = allocator<pair<const Key, T>>> 3090b57cec5SDimitry Andricclass multimap 3100b57cec5SDimitry Andric{ 3110b57cec5SDimitry Andricpublic: 3120b57cec5SDimitry Andric // types: 3130b57cec5SDimitry Andric typedef Key key_type; 3140b57cec5SDimitry Andric typedef T mapped_type; 3150b57cec5SDimitry Andric typedef pair<const key_type,mapped_type> value_type; 3160b57cec5SDimitry Andric typedef Compare key_compare; 3170b57cec5SDimitry Andric typedef Allocator allocator_type; 3180b57cec5SDimitry Andric typedef typename allocator_type::reference reference; 3190b57cec5SDimitry Andric typedef typename allocator_type::const_reference const_reference; 3200b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 3210b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 3220b57cec5SDimitry Andric typedef typename allocator_type::pointer pointer; 3230b57cec5SDimitry Andric typedef typename allocator_type::const_pointer const_pointer; 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andric typedef implementation-defined iterator; 3260b57cec5SDimitry Andric typedef implementation-defined const_iterator; 3270b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 3280b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 3290b57cec5SDimitry Andric typedef unspecified node_type; // C++17 3300b57cec5SDimitry Andric 3310b57cec5SDimitry Andric class value_compare 3320b57cec5SDimitry Andric { 3330b57cec5SDimitry Andric friend class multimap; 3340b57cec5SDimitry Andric protected: 3350b57cec5SDimitry Andric key_compare comp; 3360b57cec5SDimitry Andric value_compare(key_compare c); 3370b57cec5SDimitry Andric public: 338fe6060f1SDimitry Andric typedef bool result_type; // deprecated in C++17, removed in C++20 339fe6060f1SDimitry Andric typedef value_type first_argument_type; // deprecated in C++17, removed in C++20 340fe6060f1SDimitry Andric typedef value_type second_argument_type; // deprecated in C++17, removed in C++20 3410b57cec5SDimitry Andric bool operator()(const value_type& x, const value_type& y) const; 3420b57cec5SDimitry Andric }; 3430b57cec5SDimitry Andric 3440b57cec5SDimitry Andric // construct/copy/destroy: 3450b57cec5SDimitry Andric multimap() 3460b57cec5SDimitry Andric noexcept( 3470b57cec5SDimitry Andric is_nothrow_default_constructible<allocator_type>::value && 3480b57cec5SDimitry Andric is_nothrow_default_constructible<key_compare>::value && 3490b57cec5SDimitry Andric is_nothrow_copy_constructible<key_compare>::value); 3500b57cec5SDimitry Andric explicit multimap(const key_compare& comp); 3510b57cec5SDimitry Andric multimap(const key_compare& comp, const allocator_type& a); 3520b57cec5SDimitry Andric template <class InputIterator> 3530b57cec5SDimitry Andric multimap(InputIterator first, InputIterator last, const key_compare& comp); 3540b57cec5SDimitry Andric template <class InputIterator> 3550b57cec5SDimitry Andric multimap(InputIterator first, InputIterator last, const key_compare& comp, 3560b57cec5SDimitry Andric const allocator_type& a); 357*06c3fb27SDimitry Andric template<container-compatible-range<value_type> R> 358*06c3fb27SDimitry Andric multimap(from_range_t, R&& rg, 359*06c3fb27SDimitry Andric const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23 3600b57cec5SDimitry Andric multimap(const multimap& m); 3610b57cec5SDimitry Andric multimap(multimap&& m) 3620b57cec5SDimitry Andric noexcept( 3630b57cec5SDimitry Andric is_nothrow_move_constructible<allocator_type>::value && 3640b57cec5SDimitry Andric is_nothrow_move_constructible<key_compare>::value); 3650b57cec5SDimitry Andric explicit multimap(const allocator_type& a); 3660b57cec5SDimitry Andric multimap(const multimap& m, const allocator_type& a); 3670b57cec5SDimitry Andric multimap(multimap&& m, const allocator_type& a); 3680b57cec5SDimitry Andric multimap(initializer_list<value_type> il, const key_compare& comp = key_compare()); 3690b57cec5SDimitry Andric multimap(initializer_list<value_type> il, const key_compare& comp, 3700b57cec5SDimitry Andric const allocator_type& a); 3710b57cec5SDimitry Andric template <class InputIterator> 3720b57cec5SDimitry Andric multimap(InputIterator first, InputIterator last, const allocator_type& a) 3730b57cec5SDimitry Andric : multimap(first, last, Compare(), a) {} // C++14 374*06c3fb27SDimitry Andric template<container-compatible-range<value_type> R> 375*06c3fb27SDimitry Andric multimap(from_range_t, R&& rg, const Allocator& a)) 376*06c3fb27SDimitry Andric : multimap(from_range, std::forward<R>(rg), Compare(), a) { } // C++23 3770b57cec5SDimitry Andric multimap(initializer_list<value_type> il, const allocator_type& a) 3780b57cec5SDimitry Andric : multimap(il, Compare(), a) {} // C++14 3790b57cec5SDimitry Andric ~multimap(); 3800b57cec5SDimitry Andric 3810b57cec5SDimitry Andric multimap& operator=(const multimap& m); 3820b57cec5SDimitry Andric multimap& operator=(multimap&& m) 3830b57cec5SDimitry Andric noexcept( 3840b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value && 3850b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value && 3860b57cec5SDimitry Andric is_nothrow_move_assignable<key_compare>::value); 3870b57cec5SDimitry Andric multimap& operator=(initializer_list<value_type> il); 3880b57cec5SDimitry Andric 3890b57cec5SDimitry Andric // iterators: 3900b57cec5SDimitry Andric iterator begin() noexcept; 3910b57cec5SDimitry Andric const_iterator begin() const noexcept; 3920b57cec5SDimitry Andric iterator end() noexcept; 3930b57cec5SDimitry Andric const_iterator end() const noexcept; 3940b57cec5SDimitry Andric 3950b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 3960b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 3970b57cec5SDimitry Andric reverse_iterator rend() noexcept; 3980b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 4010b57cec5SDimitry Andric const_iterator cend() const noexcept; 4020b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 4030b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andric // capacity: 4060b57cec5SDimitry Andric bool empty() const noexcept; 4070b57cec5SDimitry Andric size_type size() const noexcept; 4080b57cec5SDimitry Andric size_type max_size() const noexcept; 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andric // modifiers: 4110b57cec5SDimitry Andric template <class... Args> 4120b57cec5SDimitry Andric iterator emplace(Args&&... args); 4130b57cec5SDimitry Andric template <class... Args> 4140b57cec5SDimitry Andric iterator emplace_hint(const_iterator position, Args&&... args); 4150b57cec5SDimitry Andric iterator insert(const value_type& v); 4160b57cec5SDimitry Andric iterator insert( value_type&& v); // C++17 4170b57cec5SDimitry Andric template <class P> 4180b57cec5SDimitry Andric iterator insert(P&& p); 4190b57cec5SDimitry Andric iterator insert(const_iterator position, const value_type& v); 4200b57cec5SDimitry Andric iterator insert(const_iterator position, value_type&& v); // C++17 4210b57cec5SDimitry Andric template <class P> 4220b57cec5SDimitry Andric iterator insert(const_iterator position, P&& p); 4230b57cec5SDimitry Andric template <class InputIterator> 4240b57cec5SDimitry Andric void insert(InputIterator first, InputIterator last); 425*06c3fb27SDimitry Andric template<container-compatible-range<value_type> R> 426*06c3fb27SDimitry Andric void insert_range(R&& rg); // C++23 4270b57cec5SDimitry Andric void insert(initializer_list<value_type> il); 4280b57cec5SDimitry Andric 4290b57cec5SDimitry Andric node_type extract(const_iterator position); // C++17 4300b57cec5SDimitry Andric node_type extract(const key_type& x); // C++17 4310b57cec5SDimitry Andric iterator insert(node_type&& nh); // C++17 4320b57cec5SDimitry Andric iterator insert(const_iterator hint, node_type&& nh); // C++17 4330b57cec5SDimitry Andric 4340b57cec5SDimitry Andric iterator erase(const_iterator position); 4350b57cec5SDimitry Andric iterator erase(iterator position); // C++14 4360b57cec5SDimitry Andric size_type erase(const key_type& k); 4370b57cec5SDimitry Andric iterator erase(const_iterator first, const_iterator last); 4380b57cec5SDimitry Andric void clear() noexcept; 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andric template<class C2> 4410b57cec5SDimitry Andric void merge(multimap<Key, T, C2, Allocator>& source); // C++17 4420b57cec5SDimitry Andric template<class C2> 4430b57cec5SDimitry Andric void merge(multimap<Key, T, C2, Allocator>&& source); // C++17 4440b57cec5SDimitry Andric template<class C2> 4450b57cec5SDimitry Andric void merge(map<Key, T, C2, Allocator>& source); // C++17 4460b57cec5SDimitry Andric template<class C2> 4470b57cec5SDimitry Andric void merge(map<Key, T, C2, Allocator>&& source); // C++17 4480b57cec5SDimitry Andric 4490b57cec5SDimitry Andric void swap(multimap& m) 4500b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::is_always_equal::value && 4510b57cec5SDimitry Andric is_nothrow_swappable<key_compare>::value); // C++17 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric // observers: 4540b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 4550b57cec5SDimitry Andric key_compare key_comp() const; 4560b57cec5SDimitry Andric value_compare value_comp() const; 4570b57cec5SDimitry Andric 4580b57cec5SDimitry Andric // map operations: 4590b57cec5SDimitry Andric iterator find(const key_type& k); 4600b57cec5SDimitry Andric const_iterator find(const key_type& k) const; 4610b57cec5SDimitry Andric template<typename K> 4620b57cec5SDimitry Andric iterator find(const K& x); // C++14 4630b57cec5SDimitry Andric template<typename K> 4640b57cec5SDimitry Andric const_iterator find(const K& x) const; // C++14 465fe6060f1SDimitry Andric 4660b57cec5SDimitry Andric template<typename K> 4670b57cec5SDimitry Andric size_type count(const K& x) const; // C++14 4680b57cec5SDimitry Andric size_type count(const key_type& k) const; 469fe6060f1SDimitry Andric 4700b57cec5SDimitry Andric bool contains(const key_type& x) const; // C++20 471fe6060f1SDimitry Andric template<class K> bool contains(const K& x) const; // C++20 472fe6060f1SDimitry Andric 4730b57cec5SDimitry Andric iterator lower_bound(const key_type& k); 4740b57cec5SDimitry Andric const_iterator lower_bound(const key_type& k) const; 4750b57cec5SDimitry Andric template<typename K> 4760b57cec5SDimitry Andric iterator lower_bound(const K& x); // C++14 4770b57cec5SDimitry Andric template<typename K> 4780b57cec5SDimitry Andric const_iterator lower_bound(const K& x) const; // C++14 4790b57cec5SDimitry Andric 4800b57cec5SDimitry Andric iterator upper_bound(const key_type& k); 4810b57cec5SDimitry Andric const_iterator upper_bound(const key_type& k) const; 4820b57cec5SDimitry Andric template<typename K> 4830b57cec5SDimitry Andric iterator upper_bound(const K& x); // C++14 4840b57cec5SDimitry Andric template<typename K> 4850b57cec5SDimitry Andric const_iterator upper_bound(const K& x) const; // C++14 4860b57cec5SDimitry Andric 4870b57cec5SDimitry Andric pair<iterator,iterator> equal_range(const key_type& k); 4880b57cec5SDimitry Andric pair<const_iterator,const_iterator> equal_range(const key_type& k) const; 4890b57cec5SDimitry Andric template<typename K> 4900b57cec5SDimitry Andric pair<iterator,iterator> equal_range(const K& x); // C++14 4910b57cec5SDimitry Andric template<typename K> 4920b57cec5SDimitry Andric pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14 4930b57cec5SDimitry Andric}; 4940b57cec5SDimitry Andric 495349cc55cSDimitry Andrictemplate <class InputIterator, 496349cc55cSDimitry Andric class Compare = less<iter_key_t<InputIterator>>, 497349cc55cSDimitry Andric class Allocator = allocator<iter_to_alloc_t<InputIterator>>> 498349cc55cSDimitry Andricmultimap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator()) 499349cc55cSDimitry Andric -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17 500349cc55cSDimitry Andric 501*06c3fb27SDimitry Andrictemplate<ranges::input_range R, class Compare = less<range-key-type<R>>, 502*06c3fb27SDimitry Andric class Allocator = allocator<range-to-alloc-type<R>>> 503*06c3fb27SDimitry Andric multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator()) 504*06c3fb27SDimitry Andric -> multimap<range-key-type<R>, range-mapped-type<R>, Compare, Allocator>; // C++23 505*06c3fb27SDimitry Andric 506349cc55cSDimitry Andrictemplate<class Key, class T, class Compare = less<Key>, 507349cc55cSDimitry Andric class Allocator = allocator<pair<const Key, T>>> 508349cc55cSDimitry Andricmultimap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator()) 509349cc55cSDimitry Andric -> multimap<Key, T, Compare, Allocator>; // C++17 510349cc55cSDimitry Andric 511349cc55cSDimitry Andrictemplate <class InputIterator, class Allocator> 512349cc55cSDimitry Andricmultimap(InputIterator, InputIterator, Allocator) 513349cc55cSDimitry Andric -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, 514349cc55cSDimitry Andric less<iter_key_t<InputIterator>>, Allocator>; // C++17 515349cc55cSDimitry Andric 516*06c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator> 517*06c3fb27SDimitry Andric multimap(from_range_t, R&&, Allocator) 518*06c3fb27SDimitry Andric -> multimap<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>, Allocator>; // C++23 519*06c3fb27SDimitry Andric 520349cc55cSDimitry Andrictemplate<class Key, class T, class Allocator> 521349cc55cSDimitry Andricmultimap(initializer_list<pair<const Key, T>>, Allocator) 522349cc55cSDimitry Andric -> multimap<Key, T, less<Key>, Allocator>; // C++17 523349cc55cSDimitry Andric 5240b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 5250b57cec5SDimitry Andricbool 5260b57cec5SDimitry Andricoperator==(const multimap<Key, T, Compare, Allocator>& x, 5270b57cec5SDimitry Andric const multimap<Key, T, Compare, Allocator>& y); 5280b57cec5SDimitry Andric 5290b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 5300b57cec5SDimitry Andricbool 5310b57cec5SDimitry Andricoperator< (const multimap<Key, T, Compare, Allocator>& x, 532*06c3fb27SDimitry Andric const multimap<Key, T, Compare, Allocator>& y); // removed in C++20 5330b57cec5SDimitry Andric 5340b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 5350b57cec5SDimitry Andricbool 5360b57cec5SDimitry Andricoperator!=(const multimap<Key, T, Compare, Allocator>& x, 537*06c3fb27SDimitry Andric const multimap<Key, T, Compare, Allocator>& y); // removed in C++20 5380b57cec5SDimitry Andric 5390b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 5400b57cec5SDimitry Andricbool 5410b57cec5SDimitry Andricoperator> (const multimap<Key, T, Compare, Allocator>& x, 542*06c3fb27SDimitry Andric const multimap<Key, T, Compare, Allocator>& y); // removed in C++20 5430b57cec5SDimitry Andric 5440b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 5450b57cec5SDimitry Andricbool 5460b57cec5SDimitry Andricoperator>=(const multimap<Key, T, Compare, Allocator>& x, 547*06c3fb27SDimitry Andric const multimap<Key, T, Compare, Allocator>& y); // removed in C++20 5480b57cec5SDimitry Andric 5490b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 5500b57cec5SDimitry Andricbool 5510b57cec5SDimitry Andricoperator<=(const multimap<Key, T, Compare, Allocator>& x, 552*06c3fb27SDimitry Andric const multimap<Key, T, Compare, Allocator>& y); // removed in C++20 553*06c3fb27SDimitry Andric 554*06c3fb27SDimitry Andrictemplate<class Key, class T, class Compare, class Allocator> 555*06c3fb27SDimitry Andric synth-three-way-result<pair<const Key, T>> 556*06c3fb27SDimitry Andric operator<=>(const multimap<Key, T, Compare, Allocator>& x, 557*06c3fb27SDimitry Andric const multimap<Key, T, Compare, Allocator>& y); // since c++20 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andric// specialized algorithms: 5600b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator> 5610b57cec5SDimitry Andricvoid 5620b57cec5SDimitry Andricswap(multimap<Key, T, Compare, Allocator>& x, 5630b57cec5SDimitry Andric multimap<Key, T, Compare, Allocator>& y) 5640b57cec5SDimitry Andric noexcept(noexcept(x.swap(y))); 5650b57cec5SDimitry Andric 5660b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator, class Predicate> 5675ffd83dbSDimitry Andrictypename multimap<Key, T, Compare, Allocator>::size_type 5685ffd83dbSDimitry Andricerase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20 5690b57cec5SDimitry Andric 5700b57cec5SDimitry Andric} // std 5710b57cec5SDimitry Andric 5720b57cec5SDimitry Andric*/ 5730b57cec5SDimitry Andric 57481ad6265SDimitry Andric#include <__algorithm/equal.h> 57581ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h> 576*06c3fb27SDimitry Andric#include <__algorithm/lexicographical_compare_three_way.h> 57781ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 578*06c3fb27SDimitry Andric#include <__availability> 5790b57cec5SDimitry Andric#include <__config> 58081ad6265SDimitry Andric#include <__functional/binary_function.h> 581fe6060f1SDimitry Andric#include <__functional/is_transparent.h> 58281ad6265SDimitry Andric#include <__functional/operations.h> 58381ad6265SDimitry Andric#include <__iterator/erase_if_container.h> 584349cc55cSDimitry Andric#include <__iterator/iterator_traits.h> 585*06c3fb27SDimitry Andric#include <__iterator/ranges_iterator_traits.h> 58681ad6265SDimitry Andric#include <__iterator/reverse_iterator.h> 587*06c3fb27SDimitry Andric#include <__memory/addressof.h> 588bdd1243dSDimitry Andric#include <__memory/allocator.h> 589bdd1243dSDimitry Andric#include <__memory_resource/polymorphic_allocator.h> 5900b57cec5SDimitry Andric#include <__node_handle> 591*06c3fb27SDimitry Andric#include <__ranges/concepts.h> 592*06c3fb27SDimitry Andric#include <__ranges/container_compatible_range.h> 593*06c3fb27SDimitry Andric#include <__ranges/from_range.h> 594fe6060f1SDimitry Andric#include <__tree> 595bdd1243dSDimitry Andric#include <__type_traits/is_allocator.h> 596fe6060f1SDimitry Andric#include <__utility/forward.h> 597bdd1243dSDimitry Andric#include <__utility/piecewise_construct.h> 59881ad6265SDimitry Andric#include <__utility/swap.h> 599bdd1243dSDimitry Andric#include <tuple> 6000b57cec5SDimitry Andric#include <version> 6010b57cec5SDimitry Andric 60281ad6265SDimitry Andric// standard-mandated includes 60381ad6265SDimitry Andric 60481ad6265SDimitry Andric// [iterator.range] 60581ad6265SDimitry Andric#include <__iterator/access.h> 60681ad6265SDimitry Andric#include <__iterator/data.h> 60781ad6265SDimitry Andric#include <__iterator/empty.h> 60881ad6265SDimitry Andric#include <__iterator/reverse_access.h> 60981ad6265SDimitry Andric#include <__iterator/size.h> 61081ad6265SDimitry Andric 61181ad6265SDimitry Andric// [associative.map.syn] 61281ad6265SDimitry Andric#include <compare> 61381ad6265SDimitry Andric#include <initializer_list> 61481ad6265SDimitry Andric 6150b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 6160b57cec5SDimitry Andric# pragma GCC system_header 6170b57cec5SDimitry Andric#endif 6180b57cec5SDimitry Andric 6190b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 6200b57cec5SDimitry Andric 6210b57cec5SDimitry Andrictemplate <class _Key, class _CP, class _Compare, 6220b57cec5SDimitry Andric bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value> 6230b57cec5SDimitry Andricclass __map_value_compare 6240b57cec5SDimitry Andric : private _Compare 6250b57cec5SDimitry Andric{ 6260b57cec5SDimitry Andricpublic: 6270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6280b57cec5SDimitry Andric __map_value_compare() 6290b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) 6300b57cec5SDimitry Andric : _Compare() {} 6310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 632753f127fSDimitry Andric __map_value_compare(_Compare __c) 6330b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) 634753f127fSDimitry Andric : _Compare(__c) {} 6350b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6360b57cec5SDimitry Andric const _Compare& key_comp() const _NOEXCEPT {return *this;} 6370b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6380b57cec5SDimitry Andric bool operator()(const _CP& __x, const _CP& __y) const 6390b57cec5SDimitry Andric {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);} 6400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6410b57cec5SDimitry Andric bool operator()(const _CP& __x, const _Key& __y) const 6420b57cec5SDimitry Andric {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);} 6430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6440b57cec5SDimitry Andric bool operator()(const _Key& __x, const _CP& __y) const 6450b57cec5SDimitry Andric {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);} 646*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void swap(__map_value_compare& __y) 6470b57cec5SDimitry Andric _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) 6480b57cec5SDimitry Andric { 6490b57cec5SDimitry Andric using _VSTD::swap; 6500b57cec5SDimitry Andric swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y)); 6510b57cec5SDimitry Andric } 6520b57cec5SDimitry Andric 653*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 6540b57cec5SDimitry Andric template <typename _K2> 6550b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 656349cc55cSDimitry Andric bool operator()(const _K2& __x, const _CP& __y) const 6570b57cec5SDimitry Andric {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);} 6580b57cec5SDimitry Andric 6590b57cec5SDimitry Andric template <typename _K2> 6600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 661349cc55cSDimitry Andric bool operator()(const _CP& __x, const _K2& __y) const 6620b57cec5SDimitry Andric {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);} 6630b57cec5SDimitry Andric#endif 6640b57cec5SDimitry Andric}; 6650b57cec5SDimitry Andric 6660b57cec5SDimitry Andrictemplate <class _Key, class _CP, class _Compare> 6670b57cec5SDimitry Andricclass __map_value_compare<_Key, _CP, _Compare, false> 6680b57cec5SDimitry Andric{ 669bdd1243dSDimitry Andric _Compare __comp_; 6700b57cec5SDimitry Andric 6710b57cec5SDimitry Andricpublic: 6720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6730b57cec5SDimitry Andric __map_value_compare() 6740b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) 675bdd1243dSDimitry Andric : __comp_() {} 6760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 677753f127fSDimitry Andric __map_value_compare(_Compare __c) 6780b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) 679bdd1243dSDimitry Andric : __comp_(__c) {} 6800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 681bdd1243dSDimitry Andric const _Compare& key_comp() const _NOEXCEPT {return __comp_;} 6820b57cec5SDimitry Andric 6830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6840b57cec5SDimitry Andric bool operator()(const _CP& __x, const _CP& __y) const 685bdd1243dSDimitry Andric {return __comp_(__x.__get_value().first, __y.__get_value().first);} 6860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6870b57cec5SDimitry Andric bool operator()(const _CP& __x, const _Key& __y) const 688bdd1243dSDimitry Andric {return __comp_(__x.__get_value().first, __y);} 6890b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6900b57cec5SDimitry Andric bool operator()(const _Key& __x, const _CP& __y) const 691bdd1243dSDimitry Andric {return __comp_(__x, __y.__get_value().first);} 6920b57cec5SDimitry Andric void swap(__map_value_compare& __y) 6930b57cec5SDimitry Andric _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) 6940b57cec5SDimitry Andric { 6950b57cec5SDimitry Andric using _VSTD::swap; 696bdd1243dSDimitry Andric swap(__comp_, __y.__comp_); 6970b57cec5SDimitry Andric } 6980b57cec5SDimitry Andric 699*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 7000b57cec5SDimitry Andric template <typename _K2> 7010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 702349cc55cSDimitry Andric bool operator()(const _K2& __x, const _CP& __y) const 703bdd1243dSDimitry Andric {return __comp_(__x, __y.__get_value().first);} 7040b57cec5SDimitry Andric 7050b57cec5SDimitry Andric template <typename _K2> 7060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 707349cc55cSDimitry Andric bool operator()(const _CP& __x, const _K2& __y) const 708bdd1243dSDimitry Andric {return __comp_(__x.__get_value().first, __y);} 7090b57cec5SDimitry Andric#endif 7100b57cec5SDimitry Andric}; 7110b57cec5SDimitry Andric 7120b57cec5SDimitry Andrictemplate <class _Key, class _CP, class _Compare, bool __b> 7130b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 7140b57cec5SDimitry Andricvoid 7150b57cec5SDimitry Andricswap(__map_value_compare<_Key, _CP, _Compare, __b>& __x, 7160b57cec5SDimitry Andric __map_value_compare<_Key, _CP, _Compare, __b>& __y) 7170b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 7180b57cec5SDimitry Andric{ 7190b57cec5SDimitry Andric __x.swap(__y); 7200b57cec5SDimitry Andric} 7210b57cec5SDimitry Andric 7220b57cec5SDimitry Andrictemplate <class _Allocator> 7230b57cec5SDimitry Andricclass __map_node_destructor 7240b57cec5SDimitry Andric{ 7250b57cec5SDimitry Andric typedef _Allocator allocator_type; 7260b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 7270b57cec5SDimitry Andric 7280b57cec5SDimitry Andricpublic: 7290b57cec5SDimitry Andric typedef typename __alloc_traits::pointer pointer; 7300b57cec5SDimitry Andric 7310b57cec5SDimitry Andricprivate: 7320b57cec5SDimitry Andric allocator_type& __na_; 7330b57cec5SDimitry Andric 7340b57cec5SDimitry Andric __map_node_destructor& operator=(const __map_node_destructor&); 7350b57cec5SDimitry Andric 7360b57cec5SDimitry Andricpublic: 7370b57cec5SDimitry Andric bool __first_constructed; 7380b57cec5SDimitry Andric bool __second_constructed; 7390b57cec5SDimitry Andric 7400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7410b57cec5SDimitry Andric explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT 7420b57cec5SDimitry Andric : __na_(__na), 7430b57cec5SDimitry Andric __first_constructed(false), 7440b57cec5SDimitry Andric __second_constructed(false) 7450b57cec5SDimitry Andric {} 7460b57cec5SDimitry Andric 7470b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7490b57cec5SDimitry Andric __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT 7500b57cec5SDimitry Andric : __na_(__x.__na_), 7510b57cec5SDimitry Andric __first_constructed(__x.__value_constructed), 7520b57cec5SDimitry Andric __second_constructed(__x.__value_constructed) 7530b57cec5SDimitry Andric { 7540b57cec5SDimitry Andric __x.__value_constructed = false; 7550b57cec5SDimitry Andric } 7560b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 7570b57cec5SDimitry Andric 7580b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7590b57cec5SDimitry Andric void operator()(pointer __p) _NOEXCEPT 7600b57cec5SDimitry Andric { 7610b57cec5SDimitry Andric if (__second_constructed) 7620b57cec5SDimitry Andric __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second)); 7630b57cec5SDimitry Andric if (__first_constructed) 7640b57cec5SDimitry Andric __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first)); 7650b57cec5SDimitry Andric if (__p) 7660b57cec5SDimitry Andric __alloc_traits::deallocate(__na_, __p, 1); 7670b57cec5SDimitry Andric } 7680b57cec5SDimitry Andric}; 7690b57cec5SDimitry Andric 7700b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 7710b57cec5SDimitry Andric class map; 7720b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 7730b57cec5SDimitry Andric class multimap; 7740b57cec5SDimitry Andrictemplate <class _TreeIterator> class __map_const_iterator; 7750b57cec5SDimitry Andric 7760b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7770b57cec5SDimitry Andric 7780b57cec5SDimitry Andrictemplate <class _Key, class _Tp> 779fe6060f1SDimitry Andricstruct _LIBCPP_STANDALONE_DEBUG __value_type 7800b57cec5SDimitry Andric{ 7810b57cec5SDimitry Andric typedef _Key key_type; 7820b57cec5SDimitry Andric typedef _Tp mapped_type; 7830b57cec5SDimitry Andric typedef pair<const key_type, mapped_type> value_type; 7840b57cec5SDimitry Andric typedef pair<key_type&, mapped_type&> __nc_ref_pair_type; 7850b57cec5SDimitry Andric typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type; 7860b57cec5SDimitry Andric 7870b57cec5SDimitry Andricprivate: 788bdd1243dSDimitry Andric value_type __cc_; 7890b57cec5SDimitry Andric 7900b57cec5SDimitry Andricpublic: 7910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7920b57cec5SDimitry Andric value_type& __get_value() 7930b57cec5SDimitry Andric { 794*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 795bdd1243dSDimitry Andric return *_VSTD::launder(_VSTD::addressof(__cc_)); 7960b57cec5SDimitry Andric#else 797bdd1243dSDimitry Andric return __cc_; 7980b57cec5SDimitry Andric#endif 7990b57cec5SDimitry Andric } 8000b57cec5SDimitry Andric 8010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8020b57cec5SDimitry Andric const value_type& __get_value() const 8030b57cec5SDimitry Andric { 804*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 805bdd1243dSDimitry Andric return *_VSTD::launder(_VSTD::addressof(__cc_)); 8060b57cec5SDimitry Andric#else 807bdd1243dSDimitry Andric return __cc_; 8080b57cec5SDimitry Andric#endif 8090b57cec5SDimitry Andric } 8100b57cec5SDimitry Andric 8110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8120b57cec5SDimitry Andric __nc_ref_pair_type __ref() 8130b57cec5SDimitry Andric { 8140b57cec5SDimitry Andric value_type& __v = __get_value(); 8150b57cec5SDimitry Andric return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second); 8160b57cec5SDimitry Andric } 8170b57cec5SDimitry Andric 8180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8190b57cec5SDimitry Andric __nc_rref_pair_type __move() 8200b57cec5SDimitry Andric { 8210b57cec5SDimitry Andric value_type& __v = __get_value(); 8220b57cec5SDimitry Andric return __nc_rref_pair_type( 8230b57cec5SDimitry Andric _VSTD::move(const_cast<key_type&>(__v.first)), 8240b57cec5SDimitry Andric _VSTD::move(__v.second)); 8250b57cec5SDimitry Andric } 8260b57cec5SDimitry Andric 8270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8280b57cec5SDimitry Andric __value_type& operator=(const __value_type& __v) 8290b57cec5SDimitry Andric { 8300b57cec5SDimitry Andric __ref() = __v.__get_value(); 8310b57cec5SDimitry Andric return *this; 8320b57cec5SDimitry Andric } 8330b57cec5SDimitry Andric 8340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8350b57cec5SDimitry Andric __value_type& operator=(__value_type&& __v) 8360b57cec5SDimitry Andric { 8370b57cec5SDimitry Andric __ref() = __v.__move(); 8380b57cec5SDimitry Andric return *this; 8390b57cec5SDimitry Andric } 8400b57cec5SDimitry Andric 8410b57cec5SDimitry Andric template <class _ValueTp, 842753f127fSDimitry Andric class = __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value> 8430b57cec5SDimitry Andric > 8440b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8450b57cec5SDimitry Andric __value_type& operator=(_ValueTp&& __v) 8460b57cec5SDimitry Andric { 8470b57cec5SDimitry Andric __ref() = _VSTD::forward<_ValueTp>(__v); 8480b57cec5SDimitry Andric return *this; 8490b57cec5SDimitry Andric } 8500b57cec5SDimitry Andric 8510b57cec5SDimitry Andricprivate: 852349cc55cSDimitry Andric __value_type() = delete; 853349cc55cSDimitry Andric ~__value_type() = delete; 854349cc55cSDimitry Andric __value_type(const __value_type&) = delete; 855349cc55cSDimitry Andric __value_type(__value_type&&) = delete; 8560b57cec5SDimitry Andric}; 8570b57cec5SDimitry Andric 8580b57cec5SDimitry Andric#else 8590b57cec5SDimitry Andric 8600b57cec5SDimitry Andrictemplate <class _Key, class _Tp> 8610b57cec5SDimitry Andricstruct __value_type 8620b57cec5SDimitry Andric{ 8630b57cec5SDimitry Andric typedef _Key key_type; 8640b57cec5SDimitry Andric typedef _Tp mapped_type; 8650b57cec5SDimitry Andric typedef pair<const key_type, mapped_type> value_type; 8660b57cec5SDimitry Andric 8670b57cec5SDimitry Andricprivate: 868bdd1243dSDimitry Andric value_type __cc_; 8690b57cec5SDimitry Andric 8700b57cec5SDimitry Andricpublic: 8710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 872bdd1243dSDimitry Andric value_type& __get_value() { return __cc_; } 8730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 874bdd1243dSDimitry Andric const value_type& __get_value() const { return __cc_; } 8750b57cec5SDimitry Andric 8760b57cec5SDimitry Andricprivate: 8770b57cec5SDimitry Andric __value_type(); 8780b57cec5SDimitry Andric __value_type(__value_type const&); 8790b57cec5SDimitry Andric __value_type& operator=(__value_type const&); 8800b57cec5SDimitry Andric ~__value_type(); 8810b57cec5SDimitry Andric}; 8820b57cec5SDimitry Andric 8830b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 8840b57cec5SDimitry Andric 8850b57cec5SDimitry Andrictemplate <class _Tp> 8860b57cec5SDimitry Andricstruct __extract_key_value_types; 8870b57cec5SDimitry Andric 8880b57cec5SDimitry Andrictemplate <class _Key, class _Tp> 8890b57cec5SDimitry Andricstruct __extract_key_value_types<__value_type<_Key, _Tp> > 8900b57cec5SDimitry Andric{ 8910b57cec5SDimitry Andric typedef _Key const __key_type; 8920b57cec5SDimitry Andric typedef _Tp __mapped_type; 8930b57cec5SDimitry Andric}; 8940b57cec5SDimitry Andric 8950b57cec5SDimitry Andrictemplate <class _TreeIterator> 8960b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __map_iterator 8970b57cec5SDimitry Andric{ 8980b57cec5SDimitry Andric typedef typename _TreeIterator::_NodeTypes _NodeTypes; 8990b57cec5SDimitry Andric typedef typename _TreeIterator::__pointer_traits __pointer_traits; 9000b57cec5SDimitry Andric 9010b57cec5SDimitry Andric _TreeIterator __i_; 9020b57cec5SDimitry Andric 9030b57cec5SDimitry Andricpublic: 9040b57cec5SDimitry Andric typedef bidirectional_iterator_tag iterator_category; 9050b57cec5SDimitry Andric typedef typename _NodeTypes::__map_value_type value_type; 9060b57cec5SDimitry Andric typedef typename _TreeIterator::difference_type difference_type; 9070b57cec5SDimitry Andric typedef value_type& reference; 9080b57cec5SDimitry Andric typedef typename _NodeTypes::__map_value_type_pointer pointer; 9090b57cec5SDimitry Andric 9100b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9110b57cec5SDimitry Andric __map_iterator() _NOEXCEPT {} 9120b57cec5SDimitry Andric 9130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9140b57cec5SDimitry Andric __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} 9150b57cec5SDimitry Andric 9160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9170b57cec5SDimitry Andric reference operator*() const {return __i_->__get_value();} 9180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9190b57cec5SDimitry Andric pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} 9200b57cec5SDimitry Andric 9210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9220b57cec5SDimitry Andric __map_iterator& operator++() {++__i_; return *this;} 9230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9240b57cec5SDimitry Andric __map_iterator operator++(int) 9250b57cec5SDimitry Andric { 9260b57cec5SDimitry Andric __map_iterator __t(*this); 9270b57cec5SDimitry Andric ++(*this); 9280b57cec5SDimitry Andric return __t; 9290b57cec5SDimitry Andric } 9300b57cec5SDimitry Andric 9310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9320b57cec5SDimitry Andric __map_iterator& operator--() {--__i_; return *this;} 9330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9340b57cec5SDimitry Andric __map_iterator operator--(int) 9350b57cec5SDimitry Andric { 9360b57cec5SDimitry Andric __map_iterator __t(*this); 9370b57cec5SDimitry Andric --(*this); 9380b57cec5SDimitry Andric return __t; 9390b57cec5SDimitry Andric } 9400b57cec5SDimitry Andric 9410b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 9420b57cec5SDimitry Andric bool operator==(const __map_iterator& __x, const __map_iterator& __y) 9430b57cec5SDimitry Andric {return __x.__i_ == __y.__i_;} 9440b57cec5SDimitry Andric friend 9450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9460b57cec5SDimitry Andric bool operator!=(const __map_iterator& __x, const __map_iterator& __y) 9470b57cec5SDimitry Andric {return __x.__i_ != __y.__i_;} 9480b57cec5SDimitry Andric 9490b57cec5SDimitry Andric template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; 9500b57cec5SDimitry Andric template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; 9510b57cec5SDimitry Andric template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; 9520b57cec5SDimitry Andric}; 9530b57cec5SDimitry Andric 9540b57cec5SDimitry Andrictemplate <class _TreeIterator> 9550b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __map_const_iterator 9560b57cec5SDimitry Andric{ 9570b57cec5SDimitry Andric typedef typename _TreeIterator::_NodeTypes _NodeTypes; 9580b57cec5SDimitry Andric typedef typename _TreeIterator::__pointer_traits __pointer_traits; 9590b57cec5SDimitry Andric 9600b57cec5SDimitry Andric _TreeIterator __i_; 9610b57cec5SDimitry Andric 9620b57cec5SDimitry Andricpublic: 9630b57cec5SDimitry Andric typedef bidirectional_iterator_tag iterator_category; 9640b57cec5SDimitry Andric typedef typename _NodeTypes::__map_value_type value_type; 9650b57cec5SDimitry Andric typedef typename _TreeIterator::difference_type difference_type; 9660b57cec5SDimitry Andric typedef const value_type& reference; 9670b57cec5SDimitry Andric typedef typename _NodeTypes::__const_map_value_type_pointer pointer; 9680b57cec5SDimitry Andric 9690b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9700b57cec5SDimitry Andric __map_const_iterator() _NOEXCEPT {} 9710b57cec5SDimitry Andric 9720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9730b57cec5SDimitry Andric __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} 9740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9750b57cec5SDimitry Andric __map_const_iterator(__map_iterator< 9760b57cec5SDimitry Andric typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT 9770b57cec5SDimitry Andric : __i_(__i.__i_) {} 9780b57cec5SDimitry Andric 9790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9800b57cec5SDimitry Andric reference operator*() const {return __i_->__get_value();} 9810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9820b57cec5SDimitry Andric pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());} 9830b57cec5SDimitry Andric 9840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9850b57cec5SDimitry Andric __map_const_iterator& operator++() {++__i_; return *this;} 9860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9870b57cec5SDimitry Andric __map_const_iterator operator++(int) 9880b57cec5SDimitry Andric { 9890b57cec5SDimitry Andric __map_const_iterator __t(*this); 9900b57cec5SDimitry Andric ++(*this); 9910b57cec5SDimitry Andric return __t; 9920b57cec5SDimitry Andric } 9930b57cec5SDimitry Andric 9940b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9950b57cec5SDimitry Andric __map_const_iterator& operator--() {--__i_; return *this;} 9960b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9970b57cec5SDimitry Andric __map_const_iterator operator--(int) 9980b57cec5SDimitry Andric { 9990b57cec5SDimitry Andric __map_const_iterator __t(*this); 10000b57cec5SDimitry Andric --(*this); 10010b57cec5SDimitry Andric return __t; 10020b57cec5SDimitry Andric } 10030b57cec5SDimitry Andric 10040b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 10050b57cec5SDimitry Andric bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) 10060b57cec5SDimitry Andric {return __x.__i_ == __y.__i_;} 10070b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 10080b57cec5SDimitry Andric bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) 10090b57cec5SDimitry Andric {return __x.__i_ != __y.__i_;} 10100b57cec5SDimitry Andric 10110b57cec5SDimitry Andric template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; 10120b57cec5SDimitry Andric template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; 10130b57cec5SDimitry Andric template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; 10140b57cec5SDimitry Andric}; 10150b57cec5SDimitry Andric 10160b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare = less<_Key>, 10170b57cec5SDimitry Andric class _Allocator = allocator<pair<const _Key, _Tp> > > 10180b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS map 10190b57cec5SDimitry Andric{ 10200b57cec5SDimitry Andricpublic: 10210b57cec5SDimitry Andric // types: 10220b57cec5SDimitry Andric typedef _Key key_type; 10230b57cec5SDimitry Andric typedef _Tp mapped_type; 10240b57cec5SDimitry Andric typedef pair<const key_type, mapped_type> value_type; 102581ad6265SDimitry Andric typedef __type_identity_t<_Compare> key_compare; 102681ad6265SDimitry Andric typedef __type_identity_t<_Allocator> allocator_type; 10270b57cec5SDimitry Andric typedef value_type& reference; 10280b57cec5SDimitry Andric typedef const value_type& const_reference; 10290b57cec5SDimitry Andric 10300b57cec5SDimitry Andric static_assert((is_same<typename allocator_type::value_type, value_type>::value), 10310b57cec5SDimitry Andric "Allocator::value_type must be same type as value_type"); 10320b57cec5SDimitry Andric 10330b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS value_compare 103481ad6265SDimitry Andric : public __binary_function<value_type, value_type, bool> 10350b57cec5SDimitry Andric { 10360b57cec5SDimitry Andric friend class map; 10370b57cec5SDimitry Andric protected: 10380b57cec5SDimitry Andric key_compare comp; 10390b57cec5SDimitry Andric 1040753f127fSDimitry Andric _LIBCPP_INLINE_VISIBILITY value_compare(key_compare __c) : comp(__c) {} 10410b57cec5SDimitry Andric public: 10420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10430b57cec5SDimitry Andric bool operator()(const value_type& __x, const value_type& __y) const 10440b57cec5SDimitry Andric {return comp(__x.first, __y.first);} 10450b57cec5SDimitry Andric }; 10460b57cec5SDimitry Andric 10470b57cec5SDimitry Andricprivate: 10480b57cec5SDimitry Andric 10490b57cec5SDimitry Andric typedef _VSTD::__value_type<key_type, mapped_type> __value_type; 10500b57cec5SDimitry Andric typedef __map_value_compare<key_type, __value_type, key_compare> __vc; 1051bdd1243dSDimitry Andric typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type; 10520b57cec5SDimitry Andric typedef __tree<__value_type, __vc, __allocator_type> __base; 10530b57cec5SDimitry Andric typedef typename __base::__node_traits __node_traits; 10540b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 10550b57cec5SDimitry Andric 1056bdd1243dSDimitry Andric static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value, 1057bdd1243dSDimitry Andric "[allocator.requirements] states that rebinding an allocator to the same type should result in the " 1058bdd1243dSDimitry Andric "original allocator"); 1059bdd1243dSDimitry Andric 10600b57cec5SDimitry Andric __base __tree_; 10610b57cec5SDimitry Andric 10620b57cec5SDimitry Andricpublic: 10630b57cec5SDimitry Andric typedef typename __alloc_traits::pointer pointer; 10640b57cec5SDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 10650b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 10660b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 10670b57cec5SDimitry Andric typedef __map_iterator<typename __base::iterator> iterator; 10680b57cec5SDimitry Andric typedef __map_const_iterator<typename __base::const_iterator> const_iterator; 10690b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 10700b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 10710b57cec5SDimitry Andric 1072*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 10730b57cec5SDimitry Andric typedef __map_node_handle<typename __base::__node, allocator_type> node_type; 10740b57cec5SDimitry Andric typedef __insert_return_type<iterator, node_type> insert_return_type; 10750b57cec5SDimitry Andric#endif 10760b57cec5SDimitry Andric 10770b57cec5SDimitry Andric template <class _Key2, class _Value2, class _Comp2, class _Alloc2> 10780b57cec5SDimitry Andric friend class _LIBCPP_TEMPLATE_VIS map; 10790b57cec5SDimitry Andric template <class _Key2, class _Value2, class _Comp2, class _Alloc2> 10800b57cec5SDimitry Andric friend class _LIBCPP_TEMPLATE_VIS multimap; 10810b57cec5SDimitry Andric 10820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10830b57cec5SDimitry Andric map() 10840b57cec5SDimitry Andric _NOEXCEPT_( 10850b57cec5SDimitry Andric is_nothrow_default_constructible<allocator_type>::value && 10860b57cec5SDimitry Andric is_nothrow_default_constructible<key_compare>::value && 10870b57cec5SDimitry Andric is_nothrow_copy_constructible<key_compare>::value) 10880b57cec5SDimitry Andric : __tree_(__vc(key_compare())) {} 10890b57cec5SDimitry Andric 10900b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10910b57cec5SDimitry Andric explicit map(const key_compare& __comp) 10920b57cec5SDimitry Andric _NOEXCEPT_( 10930b57cec5SDimitry Andric is_nothrow_default_constructible<allocator_type>::value && 10940b57cec5SDimitry Andric is_nothrow_copy_constructible<key_compare>::value) 10950b57cec5SDimitry Andric : __tree_(__vc(__comp)) {} 10960b57cec5SDimitry Andric 10970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10980b57cec5SDimitry Andric explicit map(const key_compare& __comp, const allocator_type& __a) 10990b57cec5SDimitry Andric : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} 11000b57cec5SDimitry Andric 11010b57cec5SDimitry Andric template <class _InputIterator> 11020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11030b57cec5SDimitry Andric map(_InputIterator __f, _InputIterator __l, 11040b57cec5SDimitry Andric const key_compare& __comp = key_compare()) 11050b57cec5SDimitry Andric : __tree_(__vc(__comp)) 11060b57cec5SDimitry Andric { 11070b57cec5SDimitry Andric insert(__f, __l); 11080b57cec5SDimitry Andric } 11090b57cec5SDimitry Andric 11100b57cec5SDimitry Andric template <class _InputIterator> 11110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11120b57cec5SDimitry Andric map(_InputIterator __f, _InputIterator __l, 11130b57cec5SDimitry Andric const key_compare& __comp, const allocator_type& __a) 11140b57cec5SDimitry Andric : __tree_(__vc(__comp), typename __base::allocator_type(__a)) 11150b57cec5SDimitry Andric { 11160b57cec5SDimitry Andric insert(__f, __l); 11170b57cec5SDimitry Andric } 11180b57cec5SDimitry Andric 1119*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1120*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<value_type> _Range> 1121*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1122*06c3fb27SDimitry Andric map(from_range_t, _Range&& __range, const key_compare& __comp = key_compare(), 1123*06c3fb27SDimitry Andric const allocator_type& __a = allocator_type()) 1124*06c3fb27SDimitry Andric : __tree_(__vc(__comp), typename __base::allocator_type(__a)) { 1125*06c3fb27SDimitry Andric insert_range(std::forward<_Range>(__range)); 1126*06c3fb27SDimitry Andric } 1127*06c3fb27SDimitry Andric#endif 1128*06c3fb27SDimitry Andric 1129*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 11300b57cec5SDimitry Andric template <class _InputIterator> 11310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11320b57cec5SDimitry Andric map(_InputIterator __f, _InputIterator __l, const allocator_type& __a) 11330b57cec5SDimitry Andric : map(__f, __l, key_compare(), __a) {} 11340b57cec5SDimitry Andric#endif 11350b57cec5SDimitry Andric 1136*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1137*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<value_type> _Range> 1138*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1139*06c3fb27SDimitry Andric map(from_range_t, _Range&& __range, const allocator_type& __a) 1140*06c3fb27SDimitry Andric : map(from_range, std::forward<_Range>(__range), key_compare(), __a) {} 1141*06c3fb27SDimitry Andric#endif 1142*06c3fb27SDimitry Andric 11430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11440b57cec5SDimitry Andric map(const map& __m) 11450b57cec5SDimitry Andric : __tree_(__m.__tree_) 11460b57cec5SDimitry Andric { 11470b57cec5SDimitry Andric insert(__m.begin(), __m.end()); 11480b57cec5SDimitry Andric } 11490b57cec5SDimitry Andric 11500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11510b57cec5SDimitry Andric map& operator=(const map& __m) 11520b57cec5SDimitry Andric { 11530b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 11540b57cec5SDimitry Andric __tree_ = __m.__tree_; 11550b57cec5SDimitry Andric#else 1156349cc55cSDimitry Andric if (this != _VSTD::addressof(__m)) { 11570b57cec5SDimitry Andric __tree_.clear(); 11580b57cec5SDimitry Andric __tree_.value_comp() = __m.__tree_.value_comp(); 11590b57cec5SDimitry Andric __tree_.__copy_assign_alloc(__m.__tree_); 11600b57cec5SDimitry Andric insert(__m.begin(), __m.end()); 11610b57cec5SDimitry Andric } 11620b57cec5SDimitry Andric#endif 11630b57cec5SDimitry Andric return *this; 11640b57cec5SDimitry Andric } 11650b57cec5SDimitry Andric 11660b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 11670b57cec5SDimitry Andric 11680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11690b57cec5SDimitry Andric map(map&& __m) 11700b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) 11710b57cec5SDimitry Andric : __tree_(_VSTD::move(__m.__tree_)) 11720b57cec5SDimitry Andric { 11730b57cec5SDimitry Andric } 11740b57cec5SDimitry Andric 1175*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI map(map&& __m, const allocator_type& __a); 11760b57cec5SDimitry Andric 11770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11780b57cec5SDimitry Andric map& operator=(map&& __m) 11790b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) 11800b57cec5SDimitry Andric { 11810b57cec5SDimitry Andric __tree_ = _VSTD::move(__m.__tree_); 11820b57cec5SDimitry Andric return *this; 11830b57cec5SDimitry Andric } 11840b57cec5SDimitry Andric 11850b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11860b57cec5SDimitry Andric map(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) 11870b57cec5SDimitry Andric : __tree_(__vc(__comp)) 11880b57cec5SDimitry Andric { 11890b57cec5SDimitry Andric insert(__il.begin(), __il.end()); 11900b57cec5SDimitry Andric } 11910b57cec5SDimitry Andric 11920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11930b57cec5SDimitry Andric map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) 11940b57cec5SDimitry Andric : __tree_(__vc(__comp), typename __base::allocator_type(__a)) 11950b57cec5SDimitry Andric { 11960b57cec5SDimitry Andric insert(__il.begin(), __il.end()); 11970b57cec5SDimitry Andric } 11980b57cec5SDimitry Andric 1199*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 12000b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12010b57cec5SDimitry Andric map(initializer_list<value_type> __il, const allocator_type& __a) 12020b57cec5SDimitry Andric : map(__il, key_compare(), __a) {} 12030b57cec5SDimitry Andric#endif 12040b57cec5SDimitry Andric 12050b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12060b57cec5SDimitry Andric map& operator=(initializer_list<value_type> __il) 12070b57cec5SDimitry Andric { 12080b57cec5SDimitry Andric __tree_.__assign_unique(__il.begin(), __il.end()); 12090b57cec5SDimitry Andric return *this; 12100b57cec5SDimitry Andric } 12110b57cec5SDimitry Andric 12120b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 12130b57cec5SDimitry Andric 12140b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12150b57cec5SDimitry Andric explicit map(const allocator_type& __a) 12160b57cec5SDimitry Andric : __tree_(typename __base::allocator_type(__a)) 12170b57cec5SDimitry Andric { 12180b57cec5SDimitry Andric } 12190b57cec5SDimitry Andric 12200b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12210b57cec5SDimitry Andric map(const map& __m, const allocator_type& __a) 12220b57cec5SDimitry Andric : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) 12230b57cec5SDimitry Andric { 12240b57cec5SDimitry Andric insert(__m.begin(), __m.end()); 12250b57cec5SDimitry Andric } 12260b57cec5SDimitry Andric 12270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12280b57cec5SDimitry Andric ~map() { 12290b57cec5SDimitry Andric static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); 12300b57cec5SDimitry Andric } 12310b57cec5SDimitry Andric 12320b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12330b57cec5SDimitry Andric iterator begin() _NOEXCEPT {return __tree_.begin();} 12340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12350b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT {return __tree_.begin();} 12360b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12370b57cec5SDimitry Andric iterator end() _NOEXCEPT {return __tree_.end();} 12380b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12390b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT {return __tree_.end();} 12400b57cec5SDimitry Andric 12410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12420b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 12430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12440b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 12450b57cec5SDimitry Andric {return const_reverse_iterator(end());} 12460b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12470b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 12480b57cec5SDimitry Andric {return reverse_iterator(begin());} 12490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12500b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 12510b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 12520b57cec5SDimitry Andric 12530b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12540b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT {return begin();} 12550b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12560b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT {return end();} 12570b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12580b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 12590b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12600b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT {return rend();} 12610b57cec5SDimitry Andric 12620b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 12630b57cec5SDimitry Andric bool empty() const _NOEXCEPT {return __tree_.size() == 0;} 12640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12650b57cec5SDimitry Andric size_type size() const _NOEXCEPT {return __tree_.size();} 12660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12670b57cec5SDimitry Andric size_type max_size() const _NOEXCEPT {return __tree_.max_size();} 12680b57cec5SDimitry Andric 1269*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k); 12700b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1271*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k); 12720b57cec5SDimitry Andric#endif 12730b57cec5SDimitry Andric 1274*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __k); 1275*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __k) const; 12760b57cec5SDimitry Andric 12770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12780b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} 12790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12800b57cec5SDimitry Andric key_compare key_comp() const {return __tree_.value_comp().key_comp();} 12810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12820b57cec5SDimitry Andric value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());} 12830b57cec5SDimitry Andric 12840b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 12850b57cec5SDimitry Andric template <class ..._Args> 12860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12870b57cec5SDimitry Andric pair<iterator, bool> emplace(_Args&& ...__args) { 12880b57cec5SDimitry Andric return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...); 12890b57cec5SDimitry Andric } 12900b57cec5SDimitry Andric 12910b57cec5SDimitry Andric template <class ..._Args> 12920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12930b57cec5SDimitry Andric iterator emplace_hint(const_iterator __p, _Args&& ...__args) { 12940b57cec5SDimitry Andric return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...); 12950b57cec5SDimitry Andric } 12960b57cec5SDimitry Andric 12970b57cec5SDimitry Andric template <class _Pp, 1298753f127fSDimitry Andric class = __enable_if_t<is_constructible<value_type, _Pp>::value> > 12990b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13000b57cec5SDimitry Andric pair<iterator, bool> insert(_Pp&& __p) 13010b57cec5SDimitry Andric {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));} 13020b57cec5SDimitry Andric 13030b57cec5SDimitry Andric template <class _Pp, 1304753f127fSDimitry Andric class = __enable_if_t<is_constructible<value_type, _Pp>::value> > 13050b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13060b57cec5SDimitry Andric iterator insert(const_iterator __pos, _Pp&& __p) 13070b57cec5SDimitry Andric {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));} 13080b57cec5SDimitry Andric 13090b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 13100b57cec5SDimitry Andric 13110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13120b57cec5SDimitry Andric pair<iterator, bool> 13130b57cec5SDimitry Andric insert(const value_type& __v) {return __tree_.__insert_unique(__v);} 13140b57cec5SDimitry Andric 13150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13160b57cec5SDimitry Andric iterator 13170b57cec5SDimitry Andric insert(const_iterator __p, const value_type& __v) 13180b57cec5SDimitry Andric {return __tree_.__insert_unique(__p.__i_, __v);} 13190b57cec5SDimitry Andric 13200b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 13210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13220b57cec5SDimitry Andric pair<iterator, bool> 13230b57cec5SDimitry Andric insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));} 13240b57cec5SDimitry Andric 13250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13260b57cec5SDimitry Andric iterator insert(const_iterator __p, value_type&& __v) 13270b57cec5SDimitry Andric {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));} 13280b57cec5SDimitry Andric 13290b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13300b57cec5SDimitry Andric void insert(initializer_list<value_type> __il) 13310b57cec5SDimitry Andric {insert(__il.begin(), __il.end());} 13320b57cec5SDimitry Andric#endif 13330b57cec5SDimitry Andric 13340b57cec5SDimitry Andric template <class _InputIterator> 13350b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13360b57cec5SDimitry Andric void insert(_InputIterator __f, _InputIterator __l) 13370b57cec5SDimitry Andric { 13380b57cec5SDimitry Andric for (const_iterator __e = cend(); __f != __l; ++__f) 13390b57cec5SDimitry Andric insert(__e.__i_, *__f); 13400b57cec5SDimitry Andric } 13410b57cec5SDimitry Andric 1342*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1343*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<value_type> _Range> 1344*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1345*06c3fb27SDimitry Andric void insert_range(_Range&& __range) { 1346*06c3fb27SDimitry Andric const_iterator __end = cend(); 1347*06c3fb27SDimitry Andric for (auto&& __element : __range) { 1348*06c3fb27SDimitry Andric insert(__end.__i_, std::forward<decltype(__element)>(__element)); 1349*06c3fb27SDimitry Andric } 1350*06c3fb27SDimitry Andric } 1351*06c3fb27SDimitry Andric#endif 1352*06c3fb27SDimitry Andric 1353*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 13540b57cec5SDimitry Andric 13550b57cec5SDimitry Andric template <class... _Args> 13560b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13570b57cec5SDimitry Andric pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) 13580b57cec5SDimitry Andric { 13590b57cec5SDimitry Andric return __tree_.__emplace_unique_key_args(__k, 13600b57cec5SDimitry Andric _VSTD::piecewise_construct, 13610b57cec5SDimitry Andric _VSTD::forward_as_tuple(__k), 13620b57cec5SDimitry Andric _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); 13630b57cec5SDimitry Andric } 13640b57cec5SDimitry Andric 13650b57cec5SDimitry Andric template <class... _Args> 13660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13670b57cec5SDimitry Andric pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) 13680b57cec5SDimitry Andric { 13690b57cec5SDimitry Andric return __tree_.__emplace_unique_key_args(__k, 13700b57cec5SDimitry Andric _VSTD::piecewise_construct, 13710b57cec5SDimitry Andric _VSTD::forward_as_tuple(_VSTD::move(__k)), 13720b57cec5SDimitry Andric _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); 13730b57cec5SDimitry Andric } 13740b57cec5SDimitry Andric 13750b57cec5SDimitry Andric template <class... _Args> 13760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13770b57cec5SDimitry Andric iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) 13780b57cec5SDimitry Andric { 13790b57cec5SDimitry Andric return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, 13800b57cec5SDimitry Andric _VSTD::piecewise_construct, 13810b57cec5SDimitry Andric _VSTD::forward_as_tuple(__k), 1382e8d8bef9SDimitry Andric _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first; 13830b57cec5SDimitry Andric } 13840b57cec5SDimitry Andric 13850b57cec5SDimitry Andric template <class... _Args> 13860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13870b57cec5SDimitry Andric iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) 13880b57cec5SDimitry Andric { 13890b57cec5SDimitry Andric return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, 13900b57cec5SDimitry Andric _VSTD::piecewise_construct, 13910b57cec5SDimitry Andric _VSTD::forward_as_tuple(_VSTD::move(__k)), 1392e8d8bef9SDimitry Andric _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first; 13930b57cec5SDimitry Andric } 13940b57cec5SDimitry Andric 13950b57cec5SDimitry Andric template <class _Vp> 13960b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13970b57cec5SDimitry Andric pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) 13980b57cec5SDimitry Andric { 13990b57cec5SDimitry Andric iterator __p = lower_bound(__k); 14000b57cec5SDimitry Andric if ( __p != end() && !key_comp()(__k, __p->first)) 14010b57cec5SDimitry Andric { 14020b57cec5SDimitry Andric __p->second = _VSTD::forward<_Vp>(__v); 14030b57cec5SDimitry Andric return _VSTD::make_pair(__p, false); 14040b57cec5SDimitry Andric } 14050b57cec5SDimitry Andric return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true); 14060b57cec5SDimitry Andric } 14070b57cec5SDimitry Andric 14080b57cec5SDimitry Andric template <class _Vp> 14090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14100b57cec5SDimitry Andric pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) 14110b57cec5SDimitry Andric { 14120b57cec5SDimitry Andric iterator __p = lower_bound(__k); 14130b57cec5SDimitry Andric if ( __p != end() && !key_comp()(__k, __p->first)) 14140b57cec5SDimitry Andric { 14150b57cec5SDimitry Andric __p->second = _VSTD::forward<_Vp>(__v); 14160b57cec5SDimitry Andric return _VSTD::make_pair(__p, false); 14170b57cec5SDimitry Andric } 14180b57cec5SDimitry Andric return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true); 14190b57cec5SDimitry Andric } 14200b57cec5SDimitry Andric 14210b57cec5SDimitry Andric template <class _Vp> 1422e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h, 1423e8d8bef9SDimitry Andric const key_type& __k, 1424e8d8bef9SDimitry Andric _Vp&& __v) { 1425e8d8bef9SDimitry Andric auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args( 1426e8d8bef9SDimitry Andric __h.__i_, __k, __k, _VSTD::forward<_Vp>(__v)); 1427e8d8bef9SDimitry Andric 1428e8d8bef9SDimitry Andric if (!__inserted) 1429e8d8bef9SDimitry Andric __r->__get_value().second = _VSTD::forward<_Vp>(__v); 1430e8d8bef9SDimitry Andric 1431e8d8bef9SDimitry Andric return __r; 14320b57cec5SDimitry Andric } 14330b57cec5SDimitry Andric 14340b57cec5SDimitry Andric template <class _Vp> 1435e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h, 1436e8d8bef9SDimitry Andric key_type&& __k, 1437e8d8bef9SDimitry Andric _Vp&& __v) { 1438e8d8bef9SDimitry Andric auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args( 1439e8d8bef9SDimitry Andric __h.__i_, __k, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)); 1440e8d8bef9SDimitry Andric 1441e8d8bef9SDimitry Andric if (!__inserted) 1442e8d8bef9SDimitry Andric __r->__get_value().second = _VSTD::forward<_Vp>(__v); 1443e8d8bef9SDimitry Andric 1444e8d8bef9SDimitry Andric return __r; 14450b57cec5SDimitry Andric } 14460b57cec5SDimitry Andric 1447*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 17 14480b57cec5SDimitry Andric 14490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14500b57cec5SDimitry Andric iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} 14510b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14520b57cec5SDimitry Andric iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} 14530b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14540b57cec5SDimitry Andric size_type erase(const key_type& __k) 14550b57cec5SDimitry Andric {return __tree_.__erase_unique(__k);} 14560b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14570b57cec5SDimitry Andric iterator erase(const_iterator __f, const_iterator __l) 14580b57cec5SDimitry Andric {return __tree_.erase(__f.__i_, __l.__i_);} 14590b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14600b57cec5SDimitry Andric void clear() _NOEXCEPT {__tree_.clear();} 14610b57cec5SDimitry Andric 1462*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 14630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14640b57cec5SDimitry Andric insert_return_type insert(node_type&& __nh) 14650b57cec5SDimitry Andric { 1466*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(), 14670b57cec5SDimitry Andric "node_type with incompatible allocator passed to map::insert()"); 14680b57cec5SDimitry Andric return __tree_.template __node_handle_insert_unique< 14690b57cec5SDimitry Andric node_type, insert_return_type>(_VSTD::move(__nh)); 14700b57cec5SDimitry Andric } 14710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14720b57cec5SDimitry Andric iterator insert(const_iterator __hint, node_type&& __nh) 14730b57cec5SDimitry Andric { 1474*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(), 14750b57cec5SDimitry Andric "node_type with incompatible allocator passed to map::insert()"); 14760b57cec5SDimitry Andric return __tree_.template __node_handle_insert_unique<node_type>( 14770b57cec5SDimitry Andric __hint.__i_, _VSTD::move(__nh)); 14780b57cec5SDimitry Andric } 14790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14800b57cec5SDimitry Andric node_type extract(key_type const& __key) 14810b57cec5SDimitry Andric { 14820b57cec5SDimitry Andric return __tree_.template __node_handle_extract<node_type>(__key); 14830b57cec5SDimitry Andric } 14840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14850b57cec5SDimitry Andric node_type extract(const_iterator __it) 14860b57cec5SDimitry Andric { 14870b57cec5SDimitry Andric return __tree_.template __node_handle_extract<node_type>(__it.__i_); 14880b57cec5SDimitry Andric } 14890b57cec5SDimitry Andric template <class _Compare2> 14900b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14910b57cec5SDimitry Andric void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) 14920b57cec5SDimitry Andric { 1493*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(), 14940b57cec5SDimitry Andric "merging container with incompatible allocator"); 14950b57cec5SDimitry Andric __tree_.__node_handle_merge_unique(__source.__tree_); 14960b57cec5SDimitry Andric } 14970b57cec5SDimitry Andric template <class _Compare2> 14980b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14990b57cec5SDimitry Andric void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) 15000b57cec5SDimitry Andric { 1501*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(), 15020b57cec5SDimitry Andric "merging container with incompatible allocator"); 15030b57cec5SDimitry Andric __tree_.__node_handle_merge_unique(__source.__tree_); 15040b57cec5SDimitry Andric } 15050b57cec5SDimitry Andric template <class _Compare2> 15060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15070b57cec5SDimitry Andric void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) 15080b57cec5SDimitry Andric { 1509*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(), 15100b57cec5SDimitry Andric "merging container with incompatible allocator"); 15110b57cec5SDimitry Andric __tree_.__node_handle_merge_unique(__source.__tree_); 15120b57cec5SDimitry Andric } 15130b57cec5SDimitry Andric template <class _Compare2> 15140b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15150b57cec5SDimitry Andric void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) 15160b57cec5SDimitry Andric { 1517*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(), 15180b57cec5SDimitry Andric "merging container with incompatible allocator"); 15190b57cec5SDimitry Andric __tree_.__node_handle_merge_unique(__source.__tree_); 15200b57cec5SDimitry Andric } 15210b57cec5SDimitry Andric#endif 15220b57cec5SDimitry Andric 15230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15240b57cec5SDimitry Andric void swap(map& __m) 15250b57cec5SDimitry Andric _NOEXCEPT_(__is_nothrow_swappable<__base>::value) 15260b57cec5SDimitry Andric {__tree_.swap(__m.__tree_);} 15270b57cec5SDimitry Andric 15280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15290b57cec5SDimitry Andric iterator find(const key_type& __k) {return __tree_.find(__k);} 15300b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15310b57cec5SDimitry Andric const_iterator find(const key_type& __k) const {return __tree_.find(__k);} 1532*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 15330b57cec5SDimitry Andric template <typename _K2> 15340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1535753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator> 15360b57cec5SDimitry Andric find(const _K2& __k) {return __tree_.find(__k);} 15370b57cec5SDimitry Andric template <typename _K2> 15380b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1539753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator> 15400b57cec5SDimitry Andric find(const _K2& __k) const {return __tree_.find(__k);} 15410b57cec5SDimitry Andric#endif 15420b57cec5SDimitry Andric 15430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15440b57cec5SDimitry Andric size_type count(const key_type& __k) const 15450b57cec5SDimitry Andric {return __tree_.__count_unique(__k);} 1546*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 15470b57cec5SDimitry Andric template <typename _K2> 15480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1549753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, size_type> 15500b57cec5SDimitry Andric count(const _K2& __k) const {return __tree_.__count_multi(__k);} 15510b57cec5SDimitry Andric#endif 15520b57cec5SDimitry Andric 1553*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 15540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15550b57cec5SDimitry Andric bool contains(const key_type& __k) const {return find(__k) != end();} 1556fe6060f1SDimitry Andric template <typename _K2> 1557fe6060f1SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1558753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, bool> 1559fe6060f1SDimitry Andric contains(const _K2& __k) const { return find(__k) != end(); } 1560*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 15610b57cec5SDimitry Andric 15620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15630b57cec5SDimitry Andric iterator lower_bound(const key_type& __k) 15640b57cec5SDimitry Andric {return __tree_.lower_bound(__k);} 15650b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15660b57cec5SDimitry Andric const_iterator lower_bound(const key_type& __k) const 15670b57cec5SDimitry Andric {return __tree_.lower_bound(__k);} 1568*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 15690b57cec5SDimitry Andric template <typename _K2> 15700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1571753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator> 15720b57cec5SDimitry Andric lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} 15730b57cec5SDimitry Andric 15740b57cec5SDimitry Andric template <typename _K2> 15750b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1576753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator> 15770b57cec5SDimitry Andric lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} 15780b57cec5SDimitry Andric#endif 15790b57cec5SDimitry Andric 15800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15810b57cec5SDimitry Andric iterator upper_bound(const key_type& __k) 15820b57cec5SDimitry Andric {return __tree_.upper_bound(__k);} 15830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15840b57cec5SDimitry Andric const_iterator upper_bound(const key_type& __k) const 15850b57cec5SDimitry Andric {return __tree_.upper_bound(__k);} 1586*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 15870b57cec5SDimitry Andric template <typename _K2> 15880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1589753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator> 15900b57cec5SDimitry Andric upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} 15910b57cec5SDimitry Andric template <typename _K2> 15920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1593753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator> 15940b57cec5SDimitry Andric upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} 15950b57cec5SDimitry Andric#endif 15960b57cec5SDimitry Andric 15970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15980b57cec5SDimitry Andric pair<iterator,iterator> equal_range(const key_type& __k) 15990b57cec5SDimitry Andric {return __tree_.__equal_range_unique(__k);} 16000b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 16010b57cec5SDimitry Andric pair<const_iterator,const_iterator> equal_range(const key_type& __k) const 16020b57cec5SDimitry Andric {return __tree_.__equal_range_unique(__k);} 1603*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 16040b57cec5SDimitry Andric template <typename _K2> 16050b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1606753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<iterator,iterator>> 16070b57cec5SDimitry Andric equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} 16080b57cec5SDimitry Andric template <typename _K2> 16090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1610753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<const_iterator,const_iterator>> 16110b57cec5SDimitry Andric equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} 16120b57cec5SDimitry Andric#endif 16130b57cec5SDimitry Andric 16140b57cec5SDimitry Andricprivate: 16150b57cec5SDimitry Andric typedef typename __base::__node __node; 16160b57cec5SDimitry Andric typedef typename __base::__node_allocator __node_allocator; 16170b57cec5SDimitry Andric typedef typename __base::__node_pointer __node_pointer; 16180b57cec5SDimitry Andric typedef typename __base::__node_base_pointer __node_base_pointer; 16190b57cec5SDimitry Andric typedef typename __base::__parent_pointer __parent_pointer; 16200b57cec5SDimitry Andric 16210b57cec5SDimitry Andric typedef __map_node_destructor<__node_allocator> _Dp; 16220b57cec5SDimitry Andric typedef unique_ptr<__node, _Dp> __node_holder; 16230b57cec5SDimitry Andric 16240b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 1625*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node_with_key(const key_type& __k); 16260b57cec5SDimitry Andric#endif 16270b57cec5SDimitry Andric}; 16280b57cec5SDimitry Andric 1629349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 16300b57cec5SDimitry Andrictemplate<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>, 16310b57cec5SDimitry Andric class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, 1632*06c3fb27SDimitry Andric class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>, 1633349cc55cSDimitry Andric class = enable_if_t<!__is_allocator<_Compare>::value, void>, 1634349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 16350b57cec5SDimitry Andricmap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) 16360b57cec5SDimitry Andric -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>; 16370b57cec5SDimitry Andric 1638*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1639*06c3fb27SDimitry Andrictemplate <ranges::input_range _Range, class _Compare = less<__range_key_type<_Range>>, 1640*06c3fb27SDimitry Andric class _Allocator = allocator<__range_to_alloc_type<_Range>>, 1641*06c3fb27SDimitry Andric class = enable_if_t<!__is_allocator<_Compare>::value, void>, 1642*06c3fb27SDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 1643*06c3fb27SDimitry Andricmap(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) 1644*06c3fb27SDimitry Andric -> map<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>; 1645*06c3fb27SDimitry Andric#endif 1646*06c3fb27SDimitry Andric 16470b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>, 16480b57cec5SDimitry Andric class _Allocator = allocator<pair<const _Key, _Tp>>, 1649349cc55cSDimitry Andric class = enable_if_t<!__is_allocator<_Compare>::value, void>, 1650349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 16510b57cec5SDimitry Andricmap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator()) 16520b57cec5SDimitry Andric -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>; 16530b57cec5SDimitry Andric 16540b57cec5SDimitry Andrictemplate<class _InputIterator, class _Allocator, 1655*06c3fb27SDimitry Andric class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>, 1656349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 16570b57cec5SDimitry Andricmap(_InputIterator, _InputIterator, _Allocator) 16580b57cec5SDimitry Andric -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, 16590b57cec5SDimitry Andric less<__iter_key_type<_InputIterator>>, _Allocator>; 16600b57cec5SDimitry Andric 1661*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1662*06c3fb27SDimitry Andrictemplate <ranges::input_range _Range, class _Allocator, 1663*06c3fb27SDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 1664*06c3fb27SDimitry Andricmap(from_range_t, _Range&&, _Allocator) 1665*06c3fb27SDimitry Andric -> map<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>; 1666*06c3fb27SDimitry Andric#endif 1667*06c3fb27SDimitry Andric 16680b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Allocator, 1669349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 16700b57cec5SDimitry Andricmap(initializer_list<pair<_Key, _Tp>>, _Allocator) 16710b57cec5SDimitry Andric -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>; 16720b57cec5SDimitry Andric#endif 16730b57cec5SDimitry Andric 16740b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 16750b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 16760b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a) 16770b57cec5SDimitry Andric : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) 16780b57cec5SDimitry Andric{ 16790b57cec5SDimitry Andric if (__a != __m.get_allocator()) 16800b57cec5SDimitry Andric { 16810b57cec5SDimitry Andric const_iterator __e = cend(); 16820b57cec5SDimitry Andric while (!__m.empty()) 16830b57cec5SDimitry Andric __tree_.__insert_unique(__e.__i_, 16840b57cec5SDimitry Andric __m.__tree_.remove(__m.begin().__i_)->__value_.__move()); 16850b57cec5SDimitry Andric } 16860b57cec5SDimitry Andric} 16870b57cec5SDimitry Andric 16880b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 16890b57cec5SDimitry Andric_Tp& 16900b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) 16910b57cec5SDimitry Andric{ 16920b57cec5SDimitry Andric return __tree_.__emplace_unique_key_args(__k, 16930b57cec5SDimitry Andric _VSTD::piecewise_construct, 16940b57cec5SDimitry Andric _VSTD::forward_as_tuple(__k), 16950b57cec5SDimitry Andric _VSTD::forward_as_tuple()).first->__get_value().second; 16960b57cec5SDimitry Andric} 16970b57cec5SDimitry Andric 16980b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 16990b57cec5SDimitry Andric_Tp& 17000b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) 17010b57cec5SDimitry Andric{ 17020b57cec5SDimitry Andric return __tree_.__emplace_unique_key_args(__k, 17030b57cec5SDimitry Andric _VSTD::piecewise_construct, 17040b57cec5SDimitry Andric _VSTD::forward_as_tuple(_VSTD::move(__k)), 17050b57cec5SDimitry Andric _VSTD::forward_as_tuple()).first->__get_value().second; 17060b57cec5SDimitry Andric} 17070b57cec5SDimitry Andric 17080b57cec5SDimitry Andric#else // _LIBCPP_CXX03_LANG 17090b57cec5SDimitry Andric 17100b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 17110b57cec5SDimitry Andrictypename map<_Key, _Tp, _Compare, _Allocator>::__node_holder 17120b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k) 17130b57cec5SDimitry Andric{ 17140b57cec5SDimitry Andric __node_allocator& __na = __tree_.__node_alloc(); 17150b57cec5SDimitry Andric __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); 17160b57cec5SDimitry Andric __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k); 17170b57cec5SDimitry Andric __h.get_deleter().__first_constructed = true; 17180b57cec5SDimitry Andric __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second)); 17190b57cec5SDimitry Andric __h.get_deleter().__second_constructed = true; 1720e8d8bef9SDimitry Andric return __h; 17210b57cec5SDimitry Andric} 17220b57cec5SDimitry Andric 17230b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 17240b57cec5SDimitry Andric_Tp& 17250b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) 17260b57cec5SDimitry Andric{ 17270b57cec5SDimitry Andric __parent_pointer __parent; 17280b57cec5SDimitry Andric __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); 17290b57cec5SDimitry Andric __node_pointer __r = static_cast<__node_pointer>(__child); 17300b57cec5SDimitry Andric if (__child == nullptr) 17310b57cec5SDimitry Andric { 17320b57cec5SDimitry Andric __node_holder __h = __construct_node_with_key(__k); 17330b57cec5SDimitry Andric __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); 17340b57cec5SDimitry Andric __r = __h.release(); 17350b57cec5SDimitry Andric } 17360b57cec5SDimitry Andric return __r->__value_.__get_value().second; 17370b57cec5SDimitry Andric} 17380b57cec5SDimitry Andric 17390b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 17400b57cec5SDimitry Andric 17410b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 17420b57cec5SDimitry Andric_Tp& 17430b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) 17440b57cec5SDimitry Andric{ 17450b57cec5SDimitry Andric __parent_pointer __parent; 17460b57cec5SDimitry Andric __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); 17470b57cec5SDimitry Andric if (__child == nullptr) 17480b57cec5SDimitry Andric __throw_out_of_range("map::at: key not found"); 17490b57cec5SDimitry Andric return static_cast<__node_pointer>(__child)->__value_.__get_value().second; 17500b57cec5SDimitry Andric} 17510b57cec5SDimitry Andric 17520b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 17530b57cec5SDimitry Andricconst _Tp& 17540b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const 17550b57cec5SDimitry Andric{ 17560b57cec5SDimitry Andric __parent_pointer __parent; 17570b57cec5SDimitry Andric __node_base_pointer __child = __tree_.__find_equal(__parent, __k); 17580b57cec5SDimitry Andric if (__child == nullptr) 17590b57cec5SDimitry Andric __throw_out_of_range("map::at: key not found"); 17600b57cec5SDimitry Andric return static_cast<__node_pointer>(__child)->__value_.__get_value().second; 17610b57cec5SDimitry Andric} 17620b57cec5SDimitry Andric 17630b57cec5SDimitry Andric 17640b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 17650b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 17660b57cec5SDimitry Andricbool 17670b57cec5SDimitry Andricoperator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, 17680b57cec5SDimitry Andric const map<_Key, _Tp, _Compare, _Allocator>& __y) 17690b57cec5SDimitry Andric{ 17700b57cec5SDimitry Andric return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 17710b57cec5SDimitry Andric} 17720b57cec5SDimitry Andric 1773*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 1774*06c3fb27SDimitry Andric 17750b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 17760b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 17770b57cec5SDimitry Andricbool 17780b57cec5SDimitry Andricoperator< (const map<_Key, _Tp, _Compare, _Allocator>& __x, 17790b57cec5SDimitry Andric const map<_Key, _Tp, _Compare, _Allocator>& __y) 17800b57cec5SDimitry Andric{ 17810b57cec5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 17820b57cec5SDimitry Andric} 17830b57cec5SDimitry Andric 17840b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 17850b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 17860b57cec5SDimitry Andricbool 17870b57cec5SDimitry Andricoperator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x, 17880b57cec5SDimitry Andric const map<_Key, _Tp, _Compare, _Allocator>& __y) 17890b57cec5SDimitry Andric{ 17900b57cec5SDimitry Andric return !(__x == __y); 17910b57cec5SDimitry Andric} 17920b57cec5SDimitry Andric 17930b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 17940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 17950b57cec5SDimitry Andricbool 17960b57cec5SDimitry Andricoperator> (const map<_Key, _Tp, _Compare, _Allocator>& __x, 17970b57cec5SDimitry Andric const map<_Key, _Tp, _Compare, _Allocator>& __y) 17980b57cec5SDimitry Andric{ 17990b57cec5SDimitry Andric return __y < __x; 18000b57cec5SDimitry Andric} 18010b57cec5SDimitry Andric 18020b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 18030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 18040b57cec5SDimitry Andricbool 18050b57cec5SDimitry Andricoperator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x, 18060b57cec5SDimitry Andric const map<_Key, _Tp, _Compare, _Allocator>& __y) 18070b57cec5SDimitry Andric{ 18080b57cec5SDimitry Andric return !(__x < __y); 18090b57cec5SDimitry Andric} 18100b57cec5SDimitry Andric 18110b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 18120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 18130b57cec5SDimitry Andricbool 18140b57cec5SDimitry Andricoperator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, 18150b57cec5SDimitry Andric const map<_Key, _Tp, _Compare, _Allocator>& __y) 18160b57cec5SDimitry Andric{ 18170b57cec5SDimitry Andric return !(__y < __x); 18180b57cec5SDimitry Andric} 18190b57cec5SDimitry Andric 1820*06c3fb27SDimitry Andric#else // #if _LIBCPP_STD_VER <= 17 1821*06c3fb27SDimitry Andric 1822*06c3fb27SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 1823*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<pair<const _Key, _Tp>> 1824*06c3fb27SDimitry Andricoperator<=>(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) { 1825*06c3fb27SDimitry Andric return std::lexicographical_compare_three_way( 1826*06c3fb27SDimitry Andric __x.begin(), 1827*06c3fb27SDimitry Andric __x.end(), 1828*06c3fb27SDimitry Andric __y.begin(), 1829*06c3fb27SDimitry Andric __y.end(), 1830*06c3fb27SDimitry Andric std::__synth_three_way<pair<const _Key, _Tp>, pair<const _Key, _Tp>>); 1831*06c3fb27SDimitry Andric} 1832*06c3fb27SDimitry Andric 1833*06c3fb27SDimitry Andric#endif // #if _LIBCPP_STD_VER <= 17 1834*06c3fb27SDimitry Andric 18350b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 18360b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 18370b57cec5SDimitry Andricvoid 18380b57cec5SDimitry Andricswap(map<_Key, _Tp, _Compare, _Allocator>& __x, 18390b57cec5SDimitry Andric map<_Key, _Tp, _Compare, _Allocator>& __y) 18400b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 18410b57cec5SDimitry Andric{ 18420b57cec5SDimitry Andric __x.swap(__y); 18430b57cec5SDimitry Andric} 18440b57cec5SDimitry Andric 1845*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 18465ffd83dbSDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator, 18475ffd83dbSDimitry Andric class _Predicate> 18480b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 18495ffd83dbSDimitry Andric typename map<_Key, _Tp, _Compare, _Allocator>::size_type 18505ffd83dbSDimitry Andric erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) { 1851fe6060f1SDimitry Andric return _VSTD::__libcpp_erase_if_container(__c, __pred); 18525ffd83dbSDimitry Andric} 18530b57cec5SDimitry Andric#endif 18540b57cec5SDimitry Andric 18550b57cec5SDimitry Andric 18560b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare = less<_Key>, 18570b57cec5SDimitry Andric class _Allocator = allocator<pair<const _Key, _Tp> > > 18580b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS multimap 18590b57cec5SDimitry Andric{ 18600b57cec5SDimitry Andricpublic: 18610b57cec5SDimitry Andric // types: 18620b57cec5SDimitry Andric typedef _Key key_type; 18630b57cec5SDimitry Andric typedef _Tp mapped_type; 18640b57cec5SDimitry Andric typedef pair<const key_type, mapped_type> value_type; 186581ad6265SDimitry Andric typedef __type_identity_t<_Compare> key_compare; 186681ad6265SDimitry Andric typedef __type_identity_t<_Allocator> allocator_type; 18670b57cec5SDimitry Andric typedef value_type& reference; 18680b57cec5SDimitry Andric typedef const value_type& const_reference; 18690b57cec5SDimitry Andric 18700b57cec5SDimitry Andric static_assert((is_same<typename allocator_type::value_type, value_type>::value), 18710b57cec5SDimitry Andric "Allocator::value_type must be same type as value_type"); 18720b57cec5SDimitry Andric 18730b57cec5SDimitry Andric class _LIBCPP_TEMPLATE_VIS value_compare 187481ad6265SDimitry Andric : public __binary_function<value_type, value_type, bool> 18750b57cec5SDimitry Andric { 18760b57cec5SDimitry Andric friend class multimap; 18770b57cec5SDimitry Andric protected: 18780b57cec5SDimitry Andric key_compare comp; 18790b57cec5SDimitry Andric 18800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1881753f127fSDimitry Andric value_compare(key_compare __c) : comp(__c) {} 18820b57cec5SDimitry Andric public: 18830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 18840b57cec5SDimitry Andric bool operator()(const value_type& __x, const value_type& __y) const 18850b57cec5SDimitry Andric {return comp(__x.first, __y.first);} 18860b57cec5SDimitry Andric }; 18870b57cec5SDimitry Andric 18880b57cec5SDimitry Andricprivate: 18890b57cec5SDimitry Andric 18900b57cec5SDimitry Andric typedef _VSTD::__value_type<key_type, mapped_type> __value_type; 18910b57cec5SDimitry Andric typedef __map_value_compare<key_type, __value_type, key_compare> __vc; 1892bdd1243dSDimitry Andric typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type; 18930b57cec5SDimitry Andric typedef __tree<__value_type, __vc, __allocator_type> __base; 18940b57cec5SDimitry Andric typedef typename __base::__node_traits __node_traits; 18950b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 18960b57cec5SDimitry Andric 1897bdd1243dSDimitry Andric static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value, 1898bdd1243dSDimitry Andric "[allocator.requirements] states that rebinding an allocator to the same type should result in the " 1899bdd1243dSDimitry Andric "original allocator"); 1900bdd1243dSDimitry Andric 19010b57cec5SDimitry Andric __base __tree_; 19020b57cec5SDimitry Andric 19030b57cec5SDimitry Andricpublic: 19040b57cec5SDimitry Andric typedef typename __alloc_traits::pointer pointer; 19050b57cec5SDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 19060b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 19070b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 19080b57cec5SDimitry Andric typedef __map_iterator<typename __base::iterator> iterator; 19090b57cec5SDimitry Andric typedef __map_const_iterator<typename __base::const_iterator> const_iterator; 19100b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 19110b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 19120b57cec5SDimitry Andric 1913*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 19140b57cec5SDimitry Andric typedef __map_node_handle<typename __base::__node, allocator_type> node_type; 19150b57cec5SDimitry Andric#endif 19160b57cec5SDimitry Andric 19170b57cec5SDimitry Andric template <class _Key2, class _Value2, class _Comp2, class _Alloc2> 19180b57cec5SDimitry Andric friend class _LIBCPP_TEMPLATE_VIS map; 19190b57cec5SDimitry Andric template <class _Key2, class _Value2, class _Comp2, class _Alloc2> 19200b57cec5SDimitry Andric friend class _LIBCPP_TEMPLATE_VIS multimap; 19210b57cec5SDimitry Andric 19220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19230b57cec5SDimitry Andric multimap() 19240b57cec5SDimitry Andric _NOEXCEPT_( 19250b57cec5SDimitry Andric is_nothrow_default_constructible<allocator_type>::value && 19260b57cec5SDimitry Andric is_nothrow_default_constructible<key_compare>::value && 19270b57cec5SDimitry Andric is_nothrow_copy_constructible<key_compare>::value) 19280b57cec5SDimitry Andric : __tree_(__vc(key_compare())) {} 19290b57cec5SDimitry Andric 19300b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19310b57cec5SDimitry Andric explicit multimap(const key_compare& __comp) 19320b57cec5SDimitry Andric _NOEXCEPT_( 19330b57cec5SDimitry Andric is_nothrow_default_constructible<allocator_type>::value && 19340b57cec5SDimitry Andric is_nothrow_copy_constructible<key_compare>::value) 19350b57cec5SDimitry Andric : __tree_(__vc(__comp)) {} 19360b57cec5SDimitry Andric 19370b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19380b57cec5SDimitry Andric explicit multimap(const key_compare& __comp, const allocator_type& __a) 19390b57cec5SDimitry Andric : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} 19400b57cec5SDimitry Andric 19410b57cec5SDimitry Andric template <class _InputIterator> 19420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19430b57cec5SDimitry Andric multimap(_InputIterator __f, _InputIterator __l, 19440b57cec5SDimitry Andric const key_compare& __comp = key_compare()) 19450b57cec5SDimitry Andric : __tree_(__vc(__comp)) 19460b57cec5SDimitry Andric { 19470b57cec5SDimitry Andric insert(__f, __l); 19480b57cec5SDimitry Andric } 19490b57cec5SDimitry Andric 19500b57cec5SDimitry Andric template <class _InputIterator> 19510b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19520b57cec5SDimitry Andric multimap(_InputIterator __f, _InputIterator __l, 19530b57cec5SDimitry Andric const key_compare& __comp, const allocator_type& __a) 19540b57cec5SDimitry Andric : __tree_(__vc(__comp), typename __base::allocator_type(__a)) 19550b57cec5SDimitry Andric { 19560b57cec5SDimitry Andric insert(__f, __l); 19570b57cec5SDimitry Andric } 19580b57cec5SDimitry Andric 1959*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1960*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<value_type> _Range> 1961*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1962*06c3fb27SDimitry Andric multimap(from_range_t, _Range&& __range, const key_compare& __comp = key_compare(), 1963*06c3fb27SDimitry Andric const allocator_type& __a = allocator_type()) 1964*06c3fb27SDimitry Andric : __tree_(__vc(__comp), typename __base::allocator_type(__a)) { 1965*06c3fb27SDimitry Andric insert_range(std::forward<_Range>(__range)); 1966*06c3fb27SDimitry Andric } 1967*06c3fb27SDimitry Andric#endif 1968*06c3fb27SDimitry Andric 1969*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 19700b57cec5SDimitry Andric template <class _InputIterator> 19710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19720b57cec5SDimitry Andric multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a) 19730b57cec5SDimitry Andric : multimap(__f, __l, key_compare(), __a) {} 19740b57cec5SDimitry Andric#endif 19750b57cec5SDimitry Andric 1976*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1977*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<value_type> _Range> 1978*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1979*06c3fb27SDimitry Andric multimap(from_range_t, _Range&& __range, const allocator_type& __a) 1980*06c3fb27SDimitry Andric : multimap(from_range, std::forward<_Range>(__range), key_compare(), __a) {} 1981*06c3fb27SDimitry Andric#endif 1982*06c3fb27SDimitry Andric 19830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19840b57cec5SDimitry Andric multimap(const multimap& __m) 19850b57cec5SDimitry Andric : __tree_(__m.__tree_.value_comp(), 19860b57cec5SDimitry Andric __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) 19870b57cec5SDimitry Andric { 19880b57cec5SDimitry Andric insert(__m.begin(), __m.end()); 19890b57cec5SDimitry Andric } 19900b57cec5SDimitry Andric 19910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19920b57cec5SDimitry Andric multimap& operator=(const multimap& __m) 19930b57cec5SDimitry Andric { 19940b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 19950b57cec5SDimitry Andric __tree_ = __m.__tree_; 19960b57cec5SDimitry Andric#else 1997349cc55cSDimitry Andric if (this != _VSTD::addressof(__m)) { 19980b57cec5SDimitry Andric __tree_.clear(); 19990b57cec5SDimitry Andric __tree_.value_comp() = __m.__tree_.value_comp(); 20000b57cec5SDimitry Andric __tree_.__copy_assign_alloc(__m.__tree_); 20010b57cec5SDimitry Andric insert(__m.begin(), __m.end()); 20020b57cec5SDimitry Andric } 20030b57cec5SDimitry Andric#endif 20040b57cec5SDimitry Andric return *this; 20050b57cec5SDimitry Andric } 20060b57cec5SDimitry Andric 20070b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 20080b57cec5SDimitry Andric 20090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20100b57cec5SDimitry Andric multimap(multimap&& __m) 20110b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) 20120b57cec5SDimitry Andric : __tree_(_VSTD::move(__m.__tree_)) 20130b57cec5SDimitry Andric { 20140b57cec5SDimitry Andric } 20150b57cec5SDimitry Andric 2016*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m, const allocator_type& __a); 20170b57cec5SDimitry Andric 20180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20190b57cec5SDimitry Andric multimap& operator=(multimap&& __m) 20200b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) 20210b57cec5SDimitry Andric { 20220b57cec5SDimitry Andric __tree_ = _VSTD::move(__m.__tree_); 20230b57cec5SDimitry Andric return *this; 20240b57cec5SDimitry Andric } 20250b57cec5SDimitry Andric 20260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20270b57cec5SDimitry Andric multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) 20280b57cec5SDimitry Andric : __tree_(__vc(__comp)) 20290b57cec5SDimitry Andric { 20300b57cec5SDimitry Andric insert(__il.begin(), __il.end()); 20310b57cec5SDimitry Andric } 20320b57cec5SDimitry Andric 20330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20340b57cec5SDimitry Andric multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a) 20350b57cec5SDimitry Andric : __tree_(__vc(__comp), typename __base::allocator_type(__a)) 20360b57cec5SDimitry Andric { 20370b57cec5SDimitry Andric insert(__il.begin(), __il.end()); 20380b57cec5SDimitry Andric } 20390b57cec5SDimitry Andric 2040*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 20410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20420b57cec5SDimitry Andric multimap(initializer_list<value_type> __il, const allocator_type& __a) 20430b57cec5SDimitry Andric : multimap(__il, key_compare(), __a) {} 20440b57cec5SDimitry Andric#endif 20450b57cec5SDimitry Andric 20460b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20470b57cec5SDimitry Andric multimap& operator=(initializer_list<value_type> __il) 20480b57cec5SDimitry Andric { 20490b57cec5SDimitry Andric __tree_.__assign_multi(__il.begin(), __il.end()); 20500b57cec5SDimitry Andric return *this; 20510b57cec5SDimitry Andric } 20520b57cec5SDimitry Andric 20530b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 20540b57cec5SDimitry Andric 20550b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20560b57cec5SDimitry Andric explicit multimap(const allocator_type& __a) 20570b57cec5SDimitry Andric : __tree_(typename __base::allocator_type(__a)) 20580b57cec5SDimitry Andric { 20590b57cec5SDimitry Andric } 20600b57cec5SDimitry Andric 20610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20620b57cec5SDimitry Andric multimap(const multimap& __m, const allocator_type& __a) 20630b57cec5SDimitry Andric : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) 20640b57cec5SDimitry Andric { 20650b57cec5SDimitry Andric insert(__m.begin(), __m.end()); 20660b57cec5SDimitry Andric } 20670b57cec5SDimitry Andric 20680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20690b57cec5SDimitry Andric ~multimap() { 20700b57cec5SDimitry Andric static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); 20710b57cec5SDimitry Andric } 20720b57cec5SDimitry Andric 20730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20740b57cec5SDimitry Andric iterator begin() _NOEXCEPT {return __tree_.begin();} 20750b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20760b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT {return __tree_.begin();} 20770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20780b57cec5SDimitry Andric iterator end() _NOEXCEPT {return __tree_.end();} 20790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20800b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT {return __tree_.end();} 20810b57cec5SDimitry Andric 20820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20830b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 20840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20850b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 20860b57cec5SDimitry Andric {return const_reverse_iterator(end());} 20870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20880b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 20890b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20900b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 20910b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 20920b57cec5SDimitry Andric 20930b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20940b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT {return begin();} 20950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20960b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT {return end();} 20970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20980b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 20990b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21000b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT {return rend();} 21010b57cec5SDimitry Andric 21020b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 21030b57cec5SDimitry Andric bool empty() const _NOEXCEPT {return __tree_.size() == 0;} 21040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21050b57cec5SDimitry Andric size_type size() const _NOEXCEPT {return __tree_.size();} 21060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21070b57cec5SDimitry Andric size_type max_size() const _NOEXCEPT {return __tree_.max_size();} 21080b57cec5SDimitry Andric 21090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21100b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} 21110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21120b57cec5SDimitry Andric key_compare key_comp() const {return __tree_.value_comp().key_comp();} 21130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21140b57cec5SDimitry Andric value_compare value_comp() const 21150b57cec5SDimitry Andric {return value_compare(__tree_.value_comp().key_comp());} 21160b57cec5SDimitry Andric 21170b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 21180b57cec5SDimitry Andric 21190b57cec5SDimitry Andric template <class ..._Args> 21200b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21210b57cec5SDimitry Andric iterator emplace(_Args&& ...__args) { 21220b57cec5SDimitry Andric return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...); 21230b57cec5SDimitry Andric } 21240b57cec5SDimitry Andric 21250b57cec5SDimitry Andric template <class ..._Args> 21260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21270b57cec5SDimitry Andric iterator emplace_hint(const_iterator __p, _Args&& ...__args) { 21280b57cec5SDimitry Andric return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...); 21290b57cec5SDimitry Andric } 21300b57cec5SDimitry Andric 21310b57cec5SDimitry Andric template <class _Pp, 2132753f127fSDimitry Andric class = __enable_if_t<is_constructible<value_type, _Pp>::value>> 21330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21340b57cec5SDimitry Andric iterator insert(_Pp&& __p) 21350b57cec5SDimitry Andric {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));} 21360b57cec5SDimitry Andric 21370b57cec5SDimitry Andric template <class _Pp, 2138753f127fSDimitry Andric class = __enable_if_t<is_constructible<value_type, _Pp>::value>> 21390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21400b57cec5SDimitry Andric iterator insert(const_iterator __pos, _Pp&& __p) 21410b57cec5SDimitry Andric {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));} 21420b57cec5SDimitry Andric 21430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21440b57cec5SDimitry Andric iterator insert(value_type&& __v) 21450b57cec5SDimitry Andric {return __tree_.__insert_multi(_VSTD::move(__v));} 21460b57cec5SDimitry Andric 21470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21480b57cec5SDimitry Andric iterator insert(const_iterator __p, value_type&& __v) 21490b57cec5SDimitry Andric {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));} 21500b57cec5SDimitry Andric 21510b57cec5SDimitry Andric 21520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21530b57cec5SDimitry Andric void insert(initializer_list<value_type> __il) 21540b57cec5SDimitry Andric {insert(__il.begin(), __il.end());} 21550b57cec5SDimitry Andric 21560b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 21570b57cec5SDimitry Andric 21580b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21590b57cec5SDimitry Andric iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);} 21600b57cec5SDimitry Andric 21610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21620b57cec5SDimitry Andric iterator insert(const_iterator __p, const value_type& __v) 21630b57cec5SDimitry Andric {return __tree_.__insert_multi(__p.__i_, __v);} 21640b57cec5SDimitry Andric 21650b57cec5SDimitry Andric template <class _InputIterator> 21660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21670b57cec5SDimitry Andric void insert(_InputIterator __f, _InputIterator __l) 21680b57cec5SDimitry Andric { 21690b57cec5SDimitry Andric for (const_iterator __e = cend(); __f != __l; ++__f) 21700b57cec5SDimitry Andric __tree_.__insert_multi(__e.__i_, *__f); 21710b57cec5SDimitry Andric } 21720b57cec5SDimitry Andric 2173*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 2174*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<value_type> _Range> 2175*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 2176*06c3fb27SDimitry Andric void insert_range(_Range&& __range) { 2177*06c3fb27SDimitry Andric const_iterator __end = cend(); 2178*06c3fb27SDimitry Andric for (auto&& __element : __range) { 2179*06c3fb27SDimitry Andric __tree_.__insert_multi(__end.__i_, std::forward<decltype(__element)>(__element)); 2180*06c3fb27SDimitry Andric } 2181*06c3fb27SDimitry Andric } 2182*06c3fb27SDimitry Andric#endif 2183*06c3fb27SDimitry Andric 21840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21850b57cec5SDimitry Andric iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} 21860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21870b57cec5SDimitry Andric iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} 21880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21890b57cec5SDimitry Andric size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);} 21900b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21910b57cec5SDimitry Andric iterator erase(const_iterator __f, const_iterator __l) 21920b57cec5SDimitry Andric {return __tree_.erase(__f.__i_, __l.__i_);} 21930b57cec5SDimitry Andric 2194*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 21950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21960b57cec5SDimitry Andric iterator insert(node_type&& __nh) 21970b57cec5SDimitry Andric { 2198*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(), 21990b57cec5SDimitry Andric "node_type with incompatible allocator passed to multimap::insert()"); 22000b57cec5SDimitry Andric return __tree_.template __node_handle_insert_multi<node_type>( 22010b57cec5SDimitry Andric _VSTD::move(__nh)); 22020b57cec5SDimitry Andric } 22030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22040b57cec5SDimitry Andric iterator insert(const_iterator __hint, node_type&& __nh) 22050b57cec5SDimitry Andric { 2206*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(), 22070b57cec5SDimitry Andric "node_type with incompatible allocator passed to multimap::insert()"); 22080b57cec5SDimitry Andric return __tree_.template __node_handle_insert_multi<node_type>( 22090b57cec5SDimitry Andric __hint.__i_, _VSTD::move(__nh)); 22100b57cec5SDimitry Andric } 22110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22120b57cec5SDimitry Andric node_type extract(key_type const& __key) 22130b57cec5SDimitry Andric { 22140b57cec5SDimitry Andric return __tree_.template __node_handle_extract<node_type>(__key); 22150b57cec5SDimitry Andric } 22160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22170b57cec5SDimitry Andric node_type extract(const_iterator __it) 22180b57cec5SDimitry Andric { 22190b57cec5SDimitry Andric return __tree_.template __node_handle_extract<node_type>( 22200b57cec5SDimitry Andric __it.__i_); 22210b57cec5SDimitry Andric } 22220b57cec5SDimitry Andric template <class _Compare2> 22230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22240b57cec5SDimitry Andric void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) 22250b57cec5SDimitry Andric { 2226*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(), 22270b57cec5SDimitry Andric "merging container with incompatible allocator"); 22280b57cec5SDimitry Andric return __tree_.__node_handle_merge_multi(__source.__tree_); 22290b57cec5SDimitry Andric } 22300b57cec5SDimitry Andric template <class _Compare2> 22310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22320b57cec5SDimitry Andric void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) 22330b57cec5SDimitry Andric { 2234*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(), 22350b57cec5SDimitry Andric "merging container with incompatible allocator"); 22360b57cec5SDimitry Andric return __tree_.__node_handle_merge_multi(__source.__tree_); 22370b57cec5SDimitry Andric } 22380b57cec5SDimitry Andric template <class _Compare2> 22390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22400b57cec5SDimitry Andric void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) 22410b57cec5SDimitry Andric { 2242*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(), 22430b57cec5SDimitry Andric "merging container with incompatible allocator"); 22440b57cec5SDimitry Andric return __tree_.__node_handle_merge_multi(__source.__tree_); 22450b57cec5SDimitry Andric } 22460b57cec5SDimitry Andric template <class _Compare2> 22470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22480b57cec5SDimitry Andric void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) 22490b57cec5SDimitry Andric { 2250*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(), 22510b57cec5SDimitry Andric "merging container with incompatible allocator"); 22520b57cec5SDimitry Andric return __tree_.__node_handle_merge_multi(__source.__tree_); 22530b57cec5SDimitry Andric } 22540b57cec5SDimitry Andric#endif 22550b57cec5SDimitry Andric 22560b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22570b57cec5SDimitry Andric void clear() _NOEXCEPT {__tree_.clear();} 22580b57cec5SDimitry Andric 22590b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22600b57cec5SDimitry Andric void swap(multimap& __m) 22610b57cec5SDimitry Andric _NOEXCEPT_(__is_nothrow_swappable<__base>::value) 22620b57cec5SDimitry Andric {__tree_.swap(__m.__tree_);} 22630b57cec5SDimitry Andric 22640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22650b57cec5SDimitry Andric iterator find(const key_type& __k) {return __tree_.find(__k);} 22660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22670b57cec5SDimitry Andric const_iterator find(const key_type& __k) const {return __tree_.find(__k);} 2268*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 22690b57cec5SDimitry Andric template <typename _K2> 22700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2271753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator> 22720b57cec5SDimitry Andric find(const _K2& __k) {return __tree_.find(__k);} 22730b57cec5SDimitry Andric template <typename _K2> 22740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2275753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator> 22760b57cec5SDimitry Andric find(const _K2& __k) const {return __tree_.find(__k);} 22770b57cec5SDimitry Andric#endif 22780b57cec5SDimitry Andric 22790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22800b57cec5SDimitry Andric size_type count(const key_type& __k) const 22810b57cec5SDimitry Andric {return __tree_.__count_multi(__k);} 2282*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 22830b57cec5SDimitry Andric template <typename _K2> 22840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2285753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, size_type> 22860b57cec5SDimitry Andric count(const _K2& __k) const {return __tree_.__count_multi(__k);} 22870b57cec5SDimitry Andric#endif 22880b57cec5SDimitry Andric 2289*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 22900b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22910b57cec5SDimitry Andric bool contains(const key_type& __k) const {return find(__k) != end();} 2292fe6060f1SDimitry Andric template <typename _K2> 2293fe6060f1SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2294753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, bool> 2295fe6060f1SDimitry Andric contains(const _K2& __k) const { return find(__k) != end(); } 2296*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 22970b57cec5SDimitry Andric 22980b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22990b57cec5SDimitry Andric iterator lower_bound(const key_type& __k) 23000b57cec5SDimitry Andric {return __tree_.lower_bound(__k);} 23010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23020b57cec5SDimitry Andric const_iterator lower_bound(const key_type& __k) const 23030b57cec5SDimitry Andric {return __tree_.lower_bound(__k);} 2304*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 23050b57cec5SDimitry Andric template <typename _K2> 23060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2307753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator> 23080b57cec5SDimitry Andric lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} 23090b57cec5SDimitry Andric 23100b57cec5SDimitry Andric template <typename _K2> 23110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2312753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator> 23130b57cec5SDimitry Andric lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} 23140b57cec5SDimitry Andric#endif 23150b57cec5SDimitry Andric 23160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23170b57cec5SDimitry Andric iterator upper_bound(const key_type& __k) 23180b57cec5SDimitry Andric {return __tree_.upper_bound(__k);} 23190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23200b57cec5SDimitry Andric const_iterator upper_bound(const key_type& __k) const 23210b57cec5SDimitry Andric {return __tree_.upper_bound(__k);} 2322*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 23230b57cec5SDimitry Andric template <typename _K2> 23240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2325753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator> 23260b57cec5SDimitry Andric upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} 23270b57cec5SDimitry Andric template <typename _K2> 23280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2329753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator> 23300b57cec5SDimitry Andric upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} 23310b57cec5SDimitry Andric#endif 23320b57cec5SDimitry Andric 23330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23340b57cec5SDimitry Andric pair<iterator,iterator> equal_range(const key_type& __k) 23350b57cec5SDimitry Andric {return __tree_.__equal_range_multi(__k);} 23360b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23370b57cec5SDimitry Andric pair<const_iterator,const_iterator> equal_range(const key_type& __k) const 23380b57cec5SDimitry Andric {return __tree_.__equal_range_multi(__k);} 2339*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 23400b57cec5SDimitry Andric template <typename _K2> 23410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2342753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<iterator,iterator>> 23430b57cec5SDimitry Andric equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} 23440b57cec5SDimitry Andric template <typename _K2> 23450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2346753f127fSDimitry Andric __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<const_iterator,const_iterator>> 23470b57cec5SDimitry Andric equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} 23480b57cec5SDimitry Andric#endif 23490b57cec5SDimitry Andric 23500b57cec5SDimitry Andricprivate: 23510b57cec5SDimitry Andric typedef typename __base::__node __node; 23520b57cec5SDimitry Andric typedef typename __base::__node_allocator __node_allocator; 23530b57cec5SDimitry Andric typedef typename __base::__node_pointer __node_pointer; 23540b57cec5SDimitry Andric 23550b57cec5SDimitry Andric typedef __map_node_destructor<__node_allocator> _Dp; 23560b57cec5SDimitry Andric typedef unique_ptr<__node, _Dp> __node_holder; 23570b57cec5SDimitry Andric}; 23580b57cec5SDimitry Andric 2359349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 23600b57cec5SDimitry Andrictemplate<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>, 23610b57cec5SDimitry Andric class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, 2362*06c3fb27SDimitry Andric class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>, 2363349cc55cSDimitry Andric class = enable_if_t<!__is_allocator<_Compare>::value, void>, 2364349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 23650b57cec5SDimitry Andricmultimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) 23660b57cec5SDimitry Andric -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>; 23670b57cec5SDimitry Andric 2368*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 2369*06c3fb27SDimitry Andrictemplate <ranges::input_range _Range, class _Compare = less<__range_key_type<_Range>>, 2370*06c3fb27SDimitry Andric class _Allocator = allocator<__range_to_alloc_type<_Range>>, 2371*06c3fb27SDimitry Andric class = enable_if_t<!__is_allocator<_Compare>::value, void>, 2372*06c3fb27SDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 2373*06c3fb27SDimitry Andricmultimap(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) 2374*06c3fb27SDimitry Andric -> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>; 2375*06c3fb27SDimitry Andric#endif 2376*06c3fb27SDimitry Andric 23770b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>, 23780b57cec5SDimitry Andric class _Allocator = allocator<pair<const _Key, _Tp>>, 2379349cc55cSDimitry Andric class = enable_if_t<!__is_allocator<_Compare>::value, void>, 2380349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 23810b57cec5SDimitry Andricmultimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator()) 23820b57cec5SDimitry Andric -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>; 23830b57cec5SDimitry Andric 23840b57cec5SDimitry Andrictemplate<class _InputIterator, class _Allocator, 2385*06c3fb27SDimitry Andric class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>, 2386349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 23870b57cec5SDimitry Andricmultimap(_InputIterator, _InputIterator, _Allocator) 23880b57cec5SDimitry Andric -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, 23890b57cec5SDimitry Andric less<__iter_key_type<_InputIterator>>, _Allocator>; 23900b57cec5SDimitry Andric 2391*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 2392*06c3fb27SDimitry Andrictemplate <ranges::input_range _Range, class _Allocator, 2393*06c3fb27SDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 2394*06c3fb27SDimitry Andricmultimap(from_range_t, _Range&&, _Allocator) 2395*06c3fb27SDimitry Andric -> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>; 2396*06c3fb27SDimitry Andric#endif 2397*06c3fb27SDimitry Andric 23980b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Allocator, 2399349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value, void>> 24000b57cec5SDimitry Andricmultimap(initializer_list<pair<_Key, _Tp>>, _Allocator) 24010b57cec5SDimitry Andric -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>; 24020b57cec5SDimitry Andric#endif 24030b57cec5SDimitry Andric 24040b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 24050b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 24060b57cec5SDimitry Andricmultimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a) 24070b57cec5SDimitry Andric : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) 24080b57cec5SDimitry Andric{ 24090b57cec5SDimitry Andric if (__a != __m.get_allocator()) 24100b57cec5SDimitry Andric { 24110b57cec5SDimitry Andric const_iterator __e = cend(); 24120b57cec5SDimitry Andric while (!__m.empty()) 24130b57cec5SDimitry Andric __tree_.__insert_multi(__e.__i_, 24140b57cec5SDimitry Andric _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move())); 24150b57cec5SDimitry Andric } 24160b57cec5SDimitry Andric} 24170b57cec5SDimitry Andric#endif 24180b57cec5SDimitry Andric 24190b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 24200b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24210b57cec5SDimitry Andricbool 24220b57cec5SDimitry Andricoperator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 24230b57cec5SDimitry Andric const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 24240b57cec5SDimitry Andric{ 24250b57cec5SDimitry Andric return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 24260b57cec5SDimitry Andric} 24270b57cec5SDimitry Andric 2428*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 2429*06c3fb27SDimitry Andric 24300b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 24310b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24320b57cec5SDimitry Andricbool 24330b57cec5SDimitry Andricoperator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 24340b57cec5SDimitry Andric const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 24350b57cec5SDimitry Andric{ 24360b57cec5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 24370b57cec5SDimitry Andric} 24380b57cec5SDimitry Andric 24390b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 24400b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24410b57cec5SDimitry Andricbool 24420b57cec5SDimitry Andricoperator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 24430b57cec5SDimitry Andric const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 24440b57cec5SDimitry Andric{ 24450b57cec5SDimitry Andric return !(__x == __y); 24460b57cec5SDimitry Andric} 24470b57cec5SDimitry Andric 24480b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 24490b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24500b57cec5SDimitry Andricbool 24510b57cec5SDimitry Andricoperator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 24520b57cec5SDimitry Andric const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 24530b57cec5SDimitry Andric{ 24540b57cec5SDimitry Andric return __y < __x; 24550b57cec5SDimitry Andric} 24560b57cec5SDimitry Andric 24570b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 24580b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24590b57cec5SDimitry Andricbool 24600b57cec5SDimitry Andricoperator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 24610b57cec5SDimitry Andric const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 24620b57cec5SDimitry Andric{ 24630b57cec5SDimitry Andric return !(__x < __y); 24640b57cec5SDimitry Andric} 24650b57cec5SDimitry Andric 24660b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 24670b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24680b57cec5SDimitry Andricbool 24690b57cec5SDimitry Andricoperator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 24700b57cec5SDimitry Andric const multimap<_Key, _Tp, _Compare, _Allocator>& __y) 24710b57cec5SDimitry Andric{ 24720b57cec5SDimitry Andric return !(__y < __x); 24730b57cec5SDimitry Andric} 24740b57cec5SDimitry Andric 2475*06c3fb27SDimitry Andric#else // #if _LIBCPP_STD_VER <= 17 2476*06c3fb27SDimitry Andric 2477*06c3fb27SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 2478*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<pair<const _Key, _Tp>> 2479*06c3fb27SDimitry Andricoperator<=>(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, 2480*06c3fb27SDimitry Andric const multimap<_Key, _Tp, _Compare, _Allocator>& __y) { 2481*06c3fb27SDimitry Andric return std::lexicographical_compare_three_way( 2482*06c3fb27SDimitry Andric __x.begin(), 2483*06c3fb27SDimitry Andric __x.end(), 2484*06c3fb27SDimitry Andric __y.begin(), 2485*06c3fb27SDimitry Andric __y.end(), 2486*06c3fb27SDimitry Andric std::__synth_three_way<pair<const _Key, _Tp>, pair<const _Key, _Tp>>); 2487*06c3fb27SDimitry Andric} 2488*06c3fb27SDimitry Andric 2489*06c3fb27SDimitry Andric#endif // #if _LIBCPP_STD_VER <= 17 2490*06c3fb27SDimitry Andric 24910b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator> 24920b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24930b57cec5SDimitry Andricvoid 24940b57cec5SDimitry Andricswap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, 24950b57cec5SDimitry Andric multimap<_Key, _Tp, _Compare, _Allocator>& __y) 24960b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 24970b57cec5SDimitry Andric{ 24980b57cec5SDimitry Andric __x.swap(__y); 24990b57cec5SDimitry Andric} 25000b57cec5SDimitry Andric 2501*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 25025ffd83dbSDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator, 25035ffd83dbSDimitry Andric class _Predicate> 25040b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 25055ffd83dbSDimitry Andric typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type 25065ffd83dbSDimitry Andric erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, 25075ffd83dbSDimitry Andric _Predicate __pred) { 2508fe6060f1SDimitry Andric return _VSTD::__libcpp_erase_if_container(__c, __pred); 25095ffd83dbSDimitry Andric} 25100b57cec5SDimitry Andric#endif 25110b57cec5SDimitry Andric 25120b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 25130b57cec5SDimitry Andric 2514*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 2515bdd1243dSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 2516bdd1243dSDimitry Andricnamespace pmr { 2517bdd1243dSDimitry Andrictemplate <class _KeyT, class _ValueT, class _CompareT = std::less<_KeyT>> 2518*06c3fb27SDimitry Andricusing map _LIBCPP_AVAILABILITY_PMR = std::map<_KeyT, _ValueT, _CompareT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>; 2519bdd1243dSDimitry Andric 2520bdd1243dSDimitry Andrictemplate <class _KeyT, class _ValueT, class _CompareT = std::less<_KeyT>> 2521*06c3fb27SDimitry Andricusing multimap _LIBCPP_AVAILABILITY_PMR = std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>; 2522bdd1243dSDimitry Andric} // namespace pmr 2523bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD 2524bdd1243dSDimitry Andric#endif 2525bdd1243dSDimitry Andric 2526bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 2527bdd1243dSDimitry Andric# include <concepts> 2528*06c3fb27SDimitry Andric# include <cstdlib> 2529bdd1243dSDimitry Andric# include <functional> 2530bdd1243dSDimitry Andric# include <iterator> 2531*06c3fb27SDimitry Andric# include <type_traits> 2532bdd1243dSDimitry Andric# include <utility> 2533bdd1243dSDimitry Andric#endif 2534bdd1243dSDimitry Andric 25350b57cec5SDimitry Andric#endif // _LIBCPP_MAP 2536