map 96 KB

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