set 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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_SET
  10. #define _LIBCPP_SET
  11. /*
  12. set synopsis
  13. namespace std
  14. {
  15. template <class Key, class Compare = less<Key>,
  16. class Allocator = allocator<Key>>
  17. class set
  18. {
  19. public:
  20. // types:
  21. typedef Key key_type;
  22. typedef key_type value_type;
  23. typedef Compare key_compare;
  24. typedef key_compare value_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::size_type size_type;
  29. typedef typename allocator_type::difference_type difference_type;
  30. typedef typename allocator_type::pointer pointer;
  31. typedef typename allocator_type::const_pointer const_pointer;
  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. // construct/copy/destroy:
  39. set()
  40. noexcept(
  41. is_nothrow_default_constructible<allocator_type>::value &&
  42. is_nothrow_default_constructible<key_compare>::value &&
  43. is_nothrow_copy_constructible<key_compare>::value);
  44. explicit set(const value_compare& comp);
  45. set(const value_compare& comp, const allocator_type& a);
  46. template <class InputIterator>
  47. set(InputIterator first, InputIterator last,
  48. const value_compare& comp = value_compare());
  49. template <class InputIterator>
  50. set(InputIterator first, InputIterator last, const value_compare& comp,
  51. const allocator_type& a);
  52. template<container-compatible-range<value_type> R>
  53. set(from_range_t, R&& rg, const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
  54. set(const set& s);
  55. set(set&& s)
  56. noexcept(
  57. is_nothrow_move_constructible<allocator_type>::value &&
  58. is_nothrow_move_constructible<key_compare>::value);
  59. explicit set(const allocator_type& a);
  60. set(const set& s, const allocator_type& a);
  61. set(set&& s, const allocator_type& a);
  62. set(initializer_list<value_type> il, const value_compare& comp = value_compare());
  63. set(initializer_list<value_type> il, const value_compare& comp,
  64. const allocator_type& a);
  65. template <class InputIterator>
  66. set(InputIterator first, InputIterator last, const allocator_type& a)
  67. : set(first, last, Compare(), a) {} // C++14
  68. template<container-compatible-range<value_type> R>
  69. set(from_range_t, R&& rg, const Allocator& a))
  70. : set(from_range, std::forward<R>(rg), Compare(), a) { } // C++23
  71. set(initializer_list<value_type> il, const allocator_type& a)
  72. : set(il, Compare(), a) {} // C++14
  73. ~set();
  74. set& operator=(const set& s);
  75. set& operator=(set&& s)
  76. noexcept(
  77. allocator_type::propagate_on_container_move_assignment::value &&
  78. is_nothrow_move_assignable<allocator_type>::value &&
  79. is_nothrow_move_assignable<key_compare>::value);
  80. set& operator=(initializer_list<value_type> il);
  81. // iterators:
  82. iterator begin() noexcept;
  83. const_iterator begin() const noexcept;
  84. iterator end() noexcept;
  85. const_iterator end() const noexcept;
  86. reverse_iterator rbegin() noexcept;
  87. const_reverse_iterator rbegin() const noexcept;
  88. reverse_iterator rend() noexcept;
  89. const_reverse_iterator rend() const noexcept;
  90. const_iterator cbegin() const noexcept;
  91. const_iterator cend() const noexcept;
  92. const_reverse_iterator crbegin() const noexcept;
  93. const_reverse_iterator crend() const noexcept;
  94. // capacity:
  95. bool empty() const noexcept;
  96. size_type size() const noexcept;
  97. size_type max_size() const noexcept;
  98. // modifiers:
  99. template <class... Args>
  100. pair<iterator, bool> emplace(Args&&... args);
  101. template <class... Args>
  102. iterator emplace_hint(const_iterator position, Args&&... args);
  103. pair<iterator,bool> insert(const value_type& v);
  104. pair<iterator,bool> insert(value_type&& v);
  105. iterator insert(const_iterator position, const value_type& v);
  106. iterator insert(const_iterator position, value_type&& v);
  107. template <class InputIterator>
  108. void insert(InputIterator first, InputIterator last);
  109. template<container-compatible-range<value_type> R>
  110. void insert_range(R&& rg); // C++23
  111. void insert(initializer_list<value_type> il);
  112. node_type extract(const_iterator position); // C++17
  113. node_type extract(const key_type& x); // C++17
  114. insert_return_type insert(node_type&& nh); // C++17
  115. iterator insert(const_iterator hint, node_type&& nh); // C++17
  116. iterator erase(const_iterator position);
  117. iterator erase(iterator position); // C++14
  118. size_type erase(const key_type& k);
  119. iterator erase(const_iterator first, const_iterator last);
  120. void clear() noexcept;
  121. template<class C2>
  122. void merge(set<Key, C2, Allocator>& source); // C++17
  123. template<class C2>
  124. void merge(set<Key, C2, Allocator>&& source); // C++17
  125. template<class C2>
  126. void merge(multiset<Key, C2, Allocator>& source); // C++17
  127. template<class C2>
  128. void merge(multiset<Key, C2, Allocator>&& source); // C++17
  129. void swap(set& s)
  130. noexcept(
  131. __is_nothrow_swappable<key_compare>::value &&
  132. (!allocator_type::propagate_on_container_swap::value ||
  133. __is_nothrow_swappable<allocator_type>::value));
  134. // observers:
  135. allocator_type get_allocator() const noexcept;
  136. key_compare key_comp() const;
  137. value_compare value_comp() const;
  138. // set operations:
  139. iterator find(const key_type& k);
  140. const_iterator find(const key_type& k) const;
  141. template<typename K>
  142. iterator find(const K& x);
  143. template<typename K>
  144. const_iterator find(const K& x) const; // C++14
  145. template<typename K>
  146. size_type count(const K& x) const; // C++14
  147. size_type count(const key_type& k) const;
  148. bool contains(const key_type& x) const; // C++20
  149. template<class K> bool contains(const K& x) const; // C++20
  150. iterator lower_bound(const key_type& k);
  151. const_iterator lower_bound(const key_type& k) const;
  152. template<typename K>
  153. iterator lower_bound(const K& x); // C++14
  154. template<typename K>
  155. const_iterator lower_bound(const K& x) const; // C++14
  156. iterator upper_bound(const key_type& k);
  157. const_iterator upper_bound(const key_type& k) const;
  158. template<typename K>
  159. iterator upper_bound(const K& x); // C++14
  160. template<typename K>
  161. const_iterator upper_bound(const K& x) const; // C++14
  162. pair<iterator,iterator> equal_range(const key_type& k);
  163. pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
  164. template<typename K>
  165. pair<iterator,iterator> equal_range(const K& x); // C++14
  166. template<typename K>
  167. pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
  168. };
  169. template <class InputIterator,
  170. class Compare = less<typename iterator_traits<InputIterator>::value_type>,
  171. class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
  172. set(InputIterator, InputIterator,
  173. Compare = Compare(), Allocator = Allocator())
  174. -> set<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
  175. template<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>,
  176. class Allocator = allocator<ranges::range_value_t<R>>>
  177. set(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
  178. -> set<ranges::range_value_t<R>, Compare, Allocator>; // C++23
  179. template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
  180. set(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
  181. -> set<Key, Compare, Allocator>; // C++17
  182. template<class InputIterator, class Allocator>
  183. set(InputIterator, InputIterator, Allocator)
  184. -> set<typename iterator_traits<InputIterator>::value_type,
  185. less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
  186. template<ranges::input_range R, class Allocator>
  187. set(from_range_t, R&&, Allocator)
  188. -> set<ranges::range_value_t<R>, less<ranges::range_value_t<R>>, Allocator>; // C++23
  189. template<class Key, class Allocator>
  190. set(initializer_list<Key>, Allocator) -> set<Key, less<Key>, Allocator>; // C++17
  191. template <class Key, class Compare, class Allocator>
  192. bool
  193. operator==(const set<Key, Compare, Allocator>& x,
  194. const set<Key, Compare, Allocator>& y);
  195. template <class Key, class Compare, class Allocator>
  196. bool
  197. operator< (const set<Key, Compare, Allocator>& x,
  198. const set<Key, Compare, Allocator>& y); // removed in C++20
  199. template <class Key, class Compare, class Allocator>
  200. bool
  201. operator!=(const set<Key, Compare, Allocator>& x,
  202. const set<Key, Compare, Allocator>& y); // removed in C++20
  203. template <class Key, class Compare, class Allocator>
  204. bool
  205. operator> (const set<Key, Compare, Allocator>& x,
  206. const set<Key, Compare, Allocator>& y); // removed in C++20
  207. template <class Key, class Compare, class Allocator>
  208. bool
  209. operator>=(const set<Key, Compare, Allocator>& x,
  210. const set<Key, Compare, Allocator>& y); // removed in C++20
  211. template <class Key, class Compare, class Allocator>
  212. bool
  213. operator<=(const set<Key, Compare, Allocator>& x,
  214. const set<Key, Compare, Allocator>& y); // removed in C++20
  215. template<class Key, class Compare, class Allocator>
  216. synth-three-way-result<Key> operator<=>(const set<Key, Compare, Allocator>& x,
  217. const set<Key, Compare, Allocator>& y); // since C++20
  218. // specialized algorithms:
  219. template <class Key, class Compare, class Allocator>
  220. void
  221. swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
  222. noexcept(noexcept(x.swap(y)));
  223. template <class Key, class Compare, class Allocator, class Predicate>
  224. typename set<Key, Compare, Allocator>::size_type
  225. erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
  226. template <class Key, class Compare = less<Key>,
  227. class Allocator = allocator<Key>>
  228. class multiset
  229. {
  230. public:
  231. // types:
  232. typedef Key key_type;
  233. typedef key_type value_type;
  234. typedef Compare key_compare;
  235. typedef key_compare value_compare;
  236. typedef Allocator allocator_type;
  237. typedef typename allocator_type::reference reference;
  238. typedef typename allocator_type::const_reference const_reference;
  239. typedef typename allocator_type::size_type size_type;
  240. typedef typename allocator_type::difference_type difference_type;
  241. typedef typename allocator_type::pointer pointer;
  242. typedef typename allocator_type::const_pointer const_pointer;
  243. typedef implementation-defined iterator;
  244. typedef implementation-defined const_iterator;
  245. typedef std::reverse_iterator<iterator> reverse_iterator;
  246. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  247. typedef unspecified node_type; // C++17
  248. // construct/copy/destroy:
  249. multiset()
  250. noexcept(
  251. is_nothrow_default_constructible<allocator_type>::value &&
  252. is_nothrow_default_constructible<key_compare>::value &&
  253. is_nothrow_copy_constructible<key_compare>::value);
  254. explicit multiset(const value_compare& comp);
  255. multiset(const value_compare& comp, const allocator_type& a);
  256. template <class InputIterator>
  257. multiset(InputIterator first, InputIterator last,
  258. const value_compare& comp = value_compare());
  259. template <class InputIterator>
  260. multiset(InputIterator first, InputIterator last,
  261. const value_compare& comp, const allocator_type& a);
  262. template<container-compatible-range<value_type> R>
  263. multiset(from_range_t, R&& rg,
  264. const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
  265. multiset(const multiset& s);
  266. multiset(multiset&& s)
  267. noexcept(
  268. is_nothrow_move_constructible<allocator_type>::value &&
  269. is_nothrow_move_constructible<key_compare>::value);
  270. explicit multiset(const allocator_type& a);
  271. multiset(const multiset& s, const allocator_type& a);
  272. multiset(multiset&& s, const allocator_type& a);
  273. multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
  274. multiset(initializer_list<value_type> il, const value_compare& comp,
  275. const allocator_type& a);
  276. template <class InputIterator>
  277. multiset(InputIterator first, InputIterator last, const allocator_type& a)
  278. : set(first, last, Compare(), a) {} // C++14
  279. template<container-compatible-range<value_type> R>
  280. multiset(from_range_t, R&& rg, const Allocator& a))
  281. : multiset(from_range, std::forward<R>(rg), Compare(), a) { } // C++23
  282. multiset(initializer_list<value_type> il, const allocator_type& a)
  283. : set(il, Compare(), a) {} // C++14
  284. ~multiset();
  285. multiset& operator=(const multiset& s);
  286. multiset& operator=(multiset&& s)
  287. noexcept(
  288. allocator_type::propagate_on_container_move_assignment::value &&
  289. is_nothrow_move_assignable<allocator_type>::value &&
  290. is_nothrow_move_assignable<key_compare>::value);
  291. multiset& operator=(initializer_list<value_type> il);
  292. // iterators:
  293. iterator begin() noexcept;
  294. const_iterator begin() const noexcept;
  295. iterator end() noexcept;
  296. const_iterator end() const noexcept;
  297. reverse_iterator rbegin() noexcept;
  298. const_reverse_iterator rbegin() const noexcept;
  299. reverse_iterator rend() noexcept;
  300. const_reverse_iterator rend() const noexcept;
  301. const_iterator cbegin() const noexcept;
  302. const_iterator cend() const noexcept;
  303. const_reverse_iterator crbegin() const noexcept;
  304. const_reverse_iterator crend() const noexcept;
  305. // capacity:
  306. bool empty() const noexcept;
  307. size_type size() const noexcept;
  308. size_type max_size() const noexcept;
  309. // modifiers:
  310. template <class... Args>
  311. iterator emplace(Args&&... args);
  312. template <class... Args>
  313. iterator emplace_hint(const_iterator position, Args&&... args);
  314. iterator insert(const value_type& v);
  315. iterator insert(value_type&& v);
  316. iterator insert(const_iterator position, const value_type& v);
  317. iterator insert(const_iterator position, value_type&& v);
  318. template <class InputIterator>
  319. void insert(InputIterator first, InputIterator last);
  320. template<container-compatible-range<value_type> R>
  321. void insert_range(R&& rg); // C++23
  322. void insert(initializer_list<value_type> il);
  323. node_type extract(const_iterator position); // C++17
  324. node_type extract(const key_type& x); // C++17
  325. iterator insert(node_type&& nh); // C++17
  326. iterator insert(const_iterator hint, node_type&& nh); // C++17
  327. iterator erase(const_iterator position);
  328. iterator erase(iterator position); // C++14
  329. size_type erase(const key_type& k);
  330. iterator erase(const_iterator first, const_iterator last);
  331. void clear() noexcept;
  332. template<class C2>
  333. void merge(multiset<Key, C2, Allocator>& source); // C++17
  334. template<class C2>
  335. void merge(multiset<Key, C2, Allocator>&& source); // C++17
  336. template<class C2>
  337. void merge(set<Key, C2, Allocator>& source); // C++17
  338. template<class C2>
  339. void merge(set<Key, C2, Allocator>&& source); // C++17
  340. void swap(multiset& s)
  341. noexcept(
  342. __is_nothrow_swappable<key_compare>::value &&
  343. (!allocator_type::propagate_on_container_swap::value ||
  344. __is_nothrow_swappable<allocator_type>::value));
  345. // observers:
  346. allocator_type get_allocator() const noexcept;
  347. key_compare key_comp() const;
  348. value_compare value_comp() const;
  349. // set operations:
  350. iterator find(const key_type& k);
  351. const_iterator find(const key_type& k) const;
  352. template<typename K>
  353. iterator find(const K& x);
  354. template<typename K>
  355. const_iterator find(const K& x) const; // C++14
  356. template<typename K>
  357. size_type count(const K& x) const; // C++14
  358. size_type count(const key_type& k) const;
  359. bool contains(const key_type& x) const; // C++20
  360. template<class K> bool contains(const K& x) const; // C++20
  361. iterator lower_bound(const key_type& k);
  362. const_iterator lower_bound(const key_type& k) const;
  363. template<typename K>
  364. iterator lower_bound(const K& x); // C++14
  365. template<typename K>
  366. const_iterator lower_bound(const K& x) const; // C++14
  367. iterator upper_bound(const key_type& k);
  368. const_iterator upper_bound(const key_type& k) const;
  369. template<typename K>
  370. iterator upper_bound(const K& x); // C++14
  371. template<typename K>
  372. const_iterator upper_bound(const K& x) const; // C++14
  373. pair<iterator,iterator> equal_range(const key_type& k);
  374. pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
  375. template<typename K>
  376. pair<iterator,iterator> equal_range(const K& x); // C++14
  377. template<typename K>
  378. pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
  379. };
  380. template <class InputIterator,
  381. class Compare = less<typename iterator_traits<InputIterator>::value_type>,
  382. class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
  383. multiset(InputIterator, InputIterator,
  384. Compare = Compare(), Allocator = Allocator())
  385. -> multiset<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
  386. template<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>,
  387. class Allocator = allocator<ranges::range_value_t<R>>>
  388. multiset(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
  389. -> multiset<ranges::range_value_t<R>, Compare, Allocator>;
  390. template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
  391. multiset(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
  392. -> multiset<Key, Compare, Allocator>; // C++17
  393. template<class InputIterator, class Allocator>
  394. multiset(InputIterator, InputIterator, Allocator)
  395. -> multiset<typename iterator_traits<InputIterator>::value_type,
  396. less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
  397. template<ranges::input_range R, class Allocator>
  398. multiset(from_range_t, R&&, Allocator)
  399. -> multiset<ranges::range_value_t<R>, less<ranges::range_value_t<R>>, Allocator>;
  400. template<class Key, class Allocator>
  401. multiset(initializer_list<Key>, Allocator) -> multiset<Key, less<Key>, Allocator>; // C++17
  402. template <class Key, class Compare, class Allocator>
  403. bool
  404. operator==(const multiset<Key, Compare, Allocator>& x,
  405. const multiset<Key, Compare, Allocator>& y);
  406. template <class Key, class Compare, class Allocator>
  407. bool
  408. operator< (const multiset<Key, Compare, Allocator>& x,
  409. const multiset<Key, Compare, Allocator>& y); // removed in C++20
  410. template <class Key, class Compare, class Allocator>
  411. bool
  412. operator!=(const multiset<Key, Compare, Allocator>& x,
  413. const multiset<Key, Compare, Allocator>& y); // removed in C++20
  414. template <class Key, class Compare, class Allocator>
  415. bool
  416. operator> (const multiset<Key, Compare, Allocator>& x,
  417. const multiset<Key, Compare, Allocator>& y); // removed in C++20
  418. template <class Key, class Compare, class Allocator>
  419. bool
  420. operator>=(const multiset<Key, Compare, Allocator>& x,
  421. const multiset<Key, Compare, Allocator>& y); // removed in C++20
  422. template <class Key, class Compare, class Allocator>
  423. bool
  424. operator<=(const multiset<Key, Compare, Allocator>& x,
  425. const multiset<Key, Compare, Allocator>& y); // removed in C++20
  426. template<class Key, class Compare, class Allocator>
  427. synth-three-way-result<Key> operator<=>(const multiset<Key, Compare, Allocator>& x,
  428. const multiset<Key, Compare, Allocator>& y); // since C++20
  429. // specialized algorithms:
  430. template <class Key, class Compare, class Allocator>
  431. void
  432. swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
  433. noexcept(noexcept(x.swap(y)));
  434. template <class Key, class Compare, class Allocator, class Predicate>
  435. typename multiset<Key, Compare, Allocator>::size_type
  436. erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
  437. } // std
  438. */
  439. #include <__algorithm/equal.h>
  440. #include <__algorithm/lexicographical_compare.h>
  441. #include <__algorithm/lexicographical_compare_three_way.h>
  442. #include <__assert>
  443. #include <__availability>
  444. #include <__config>
  445. #include <__functional/is_transparent.h>
  446. #include <__functional/operations.h>
  447. #include <__iterator/erase_if_container.h>
  448. #include <__iterator/iterator_traits.h>
  449. #include <__iterator/ranges_iterator_traits.h>
  450. #include <__iterator/reverse_iterator.h>
  451. #include <__memory/allocator.h>
  452. #include <__memory_resource/polymorphic_allocator.h>
  453. #include <__node_handle>
  454. #include <__ranges/concepts.h>
  455. #include <__ranges/container_compatible_range.h>
  456. #include <__ranges/from_range.h>
  457. #include <__tree>
  458. #include <__type_traits/is_allocator.h>
  459. #include <__utility/forward.h>
  460. #include <version>
  461. // standard-mandated includes
  462. // [iterator.range]
  463. #include <__iterator/access.h>
  464. #include <__iterator/data.h>
  465. #include <__iterator/empty.h>
  466. #include <__iterator/reverse_access.h>
  467. #include <__iterator/size.h>
  468. // [associative.set.syn]
  469. #include <compare>
  470. #include <initializer_list>
  471. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  472. # pragma GCC system_header
  473. #endif
  474. _LIBCPP_PUSH_MACROS
  475. #include <__undef_macros>
  476. _LIBCPP_BEGIN_NAMESPACE_STD
  477. template <class _Key, class _Compare, class _Allocator>
  478. class multiset;
  479. template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
  480. class _LIBCPP_TEMPLATE_VIS set {
  481. public:
  482. // types:
  483. typedef _Key key_type;
  484. typedef key_type value_type;
  485. typedef __type_identity_t<_Compare> key_compare;
  486. typedef key_compare value_compare;
  487. typedef __type_identity_t<_Allocator> allocator_type;
  488. typedef value_type& reference;
  489. typedef const value_type& const_reference;
  490. static_assert((is_same<typename allocator_type::value_type, value_type>::value),
  491. "Allocator::value_type must be same type as value_type");
  492. private:
  493. typedef __tree<value_type, value_compare, allocator_type> __base;
  494. typedef allocator_traits<allocator_type> __alloc_traits;
  495. static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
  496. "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
  497. "original allocator");
  498. __base __tree_;
  499. public:
  500. typedef typename __base::pointer pointer;
  501. typedef typename __base::const_pointer const_pointer;
  502. typedef typename __base::size_type size_type;
  503. typedef typename __base::difference_type difference_type;
  504. typedef typename __base::const_iterator iterator;
  505. typedef typename __base::const_iterator const_iterator;
  506. typedef std::reverse_iterator<iterator> reverse_iterator;
  507. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  508. #if _LIBCPP_STD_VER >= 17
  509. typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
  510. typedef __insert_return_type<iterator, node_type> insert_return_type;
  511. #endif
  512. template <class _Key2, class _Compare2, class _Alloc2>
  513. friend class _LIBCPP_TEMPLATE_VIS set;
  514. template <class _Key2, class _Compare2, class _Alloc2>
  515. friend class _LIBCPP_TEMPLATE_VIS multiset;
  516. _LIBCPP_HIDE_FROM_ABI set() _NOEXCEPT_(
  517. is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
  518. is_nothrow_copy_constructible<key_compare>::value)
  519. : __tree_(value_compare()) {}
  520. _LIBCPP_HIDE_FROM_ABI explicit set(const value_compare& __comp) _NOEXCEPT_(
  521. is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_copy_constructible<key_compare>::value)
  522. : __tree_(__comp) {}
  523. _LIBCPP_HIDE_FROM_ABI explicit set(const value_compare& __comp, const allocator_type& __a) : __tree_(__comp, __a) {}
  524. template <class _InputIterator>
  525. _LIBCPP_HIDE_FROM_ABI set(_InputIterator __f, _InputIterator __l, const value_compare& __comp = value_compare())
  526. : __tree_(__comp) {
  527. insert(__f, __l);
  528. }
  529. template <class _InputIterator>
  530. _LIBCPP_HIDE_FROM_ABI
  531. set(_InputIterator __f, _InputIterator __l, const value_compare& __comp, const allocator_type& __a)
  532. : __tree_(__comp, __a) {
  533. insert(__f, __l);
  534. }
  535. #if _LIBCPP_STD_VER >= 23
  536. template <_ContainerCompatibleRange<value_type> _Range>
  537. _LIBCPP_HIDE_FROM_ABI
  538. set(from_range_t,
  539. _Range&& __range,
  540. const key_compare& __comp = key_compare(),
  541. const allocator_type& __a = allocator_type())
  542. : __tree_(__comp, __a) {
  543. insert_range(std::forward<_Range>(__range));
  544. }
  545. #endif
  546. #if _LIBCPP_STD_VER >= 14
  547. template <class _InputIterator>
  548. _LIBCPP_HIDE_FROM_ABI set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
  549. : set(__f, __l, key_compare(), __a) {}
  550. #endif
  551. #if _LIBCPP_STD_VER >= 23
  552. template <_ContainerCompatibleRange<value_type> _Range>
  553. _LIBCPP_HIDE_FROM_ABI set(from_range_t, _Range&& __range, const allocator_type& __a)
  554. : set(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
  555. #endif
  556. _LIBCPP_HIDE_FROM_ABI set(const set& __s) : __tree_(__s.__tree_) { insert(__s.begin(), __s.end()); }
  557. _LIBCPP_HIDE_FROM_ABI set& operator=(const set& __s) {
  558. __tree_ = __s.__tree_;
  559. return *this;
  560. }
  561. #ifndef _LIBCPP_CXX03_LANG
  562. _LIBCPP_HIDE_FROM_ABI set(set&& __s) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
  563. : __tree_(std::move(__s.__tree_)) {}
  564. #endif // _LIBCPP_CXX03_LANG
  565. _LIBCPP_HIDE_FROM_ABI explicit set(const allocator_type& __a) : __tree_(__a) {}
  566. _LIBCPP_HIDE_FROM_ABI set(const set& __s, const allocator_type& __a) : __tree_(__s.__tree_.value_comp(), __a) {
  567. insert(__s.begin(), __s.end());
  568. }
  569. #ifndef _LIBCPP_CXX03_LANG
  570. _LIBCPP_HIDE_FROM_ABI set(set&& __s, const allocator_type& __a);
  571. _LIBCPP_HIDE_FROM_ABI set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
  572. : __tree_(__comp) {
  573. insert(__il.begin(), __il.end());
  574. }
  575. _LIBCPP_HIDE_FROM_ABI set(initializer_list<value_type> __il, const value_compare& __comp, const allocator_type& __a)
  576. : __tree_(__comp, __a) {
  577. insert(__il.begin(), __il.end());
  578. }
  579. # if _LIBCPP_STD_VER >= 14
  580. _LIBCPP_HIDE_FROM_ABI set(initializer_list<value_type> __il, const allocator_type& __a)
  581. : set(__il, key_compare(), __a) {}
  582. # endif
  583. _LIBCPP_HIDE_FROM_ABI set& operator=(initializer_list<value_type> __il) {
  584. __tree_.__assign_unique(__il.begin(), __il.end());
  585. return *this;
  586. }
  587. _LIBCPP_HIDE_FROM_ABI set& operator=(set&& __s) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) {
  588. __tree_ = std::move(__s.__tree_);
  589. return *this;
  590. }
  591. #endif // _LIBCPP_CXX03_LANG
  592. _LIBCPP_HIDE_FROM_ABI ~set() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
  593. _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
  594. _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
  595. _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __tree_.end(); }
  596. _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __tree_.end(); }
  597. _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
  598. _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
  599. _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
  600. _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
  601. _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
  602. _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
  603. _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
  604. _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
  605. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
  606. _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
  607. _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
  608. // modifiers:
  609. #ifndef _LIBCPP_CXX03_LANG
  610. template <class... _Args>
  611. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
  612. return __tree_.__emplace_unique(std::forward<_Args>(__args)...);
  613. }
  614. template <class... _Args>
  615. _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
  616. return __tree_.__emplace_hint_unique(__p, std::forward<_Args>(__args)...);
  617. }
  618. #endif // _LIBCPP_CXX03_LANG
  619. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
  620. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
  621. return __tree_.__insert_unique(__p, __v);
  622. }
  623. template <class _InputIterator>
  624. _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
  625. for (const_iterator __e = cend(); __f != __l; ++__f)
  626. __tree_.__insert_unique(__e, *__f);
  627. }
  628. #if _LIBCPP_STD_VER >= 23
  629. template <_ContainerCompatibleRange<value_type> _Range>
  630. _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
  631. const_iterator __end = cend();
  632. for (auto&& __element : __range) {
  633. __tree_.__insert_unique(__end, std::forward<decltype(__element)>(__element));
  634. }
  635. }
  636. #endif
  637. #ifndef _LIBCPP_CXX03_LANG
  638. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
  639. return __tree_.__insert_unique(std::move(__v));
  640. }
  641. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
  642. return __tree_.__insert_unique(__p, std::move(__v));
  643. }
  644. _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
  645. #endif // _LIBCPP_CXX03_LANG
  646. _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p); }
  647. _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_unique(__k); }
  648. _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) { return __tree_.erase(__f, __l); }
  649. _LIBCPP_REINITIALIZES_OBJECT
  650. _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
  651. #if _LIBCPP_STD_VER >= 17
  652. _LIBCPP_HIDE_FROM_ABI insert_return_type insert(node_type&& __nh) {
  653. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  654. "node_type with incompatible allocator passed to set::insert()");
  655. return __tree_.template __node_handle_insert_unique< node_type, insert_return_type>(std::move(__nh));
  656. }
  657. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
  658. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  659. "node_type with incompatible allocator passed to set::insert()");
  660. return __tree_.template __node_handle_insert_unique<node_type>(__hint, std::move(__nh));
  661. }
  662. _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
  663. return __tree_.template __node_handle_extract<node_type>(__key);
  664. }
  665. _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
  666. return __tree_.template __node_handle_extract<node_type>(__it);
  667. }
  668. template <class _Compare2>
  669. _LIBCPP_HIDE_FROM_ABI void merge(set<key_type, _Compare2, allocator_type>& __source) {
  670. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  671. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  672. __tree_.__node_handle_merge_unique(__source.__tree_);
  673. }
  674. template <class _Compare2>
  675. _LIBCPP_HIDE_FROM_ABI void merge(set<key_type, _Compare2, allocator_type>&& __source) {
  676. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  677. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  678. __tree_.__node_handle_merge_unique(__source.__tree_);
  679. }
  680. template <class _Compare2>
  681. _LIBCPP_HIDE_FROM_ABI void merge(multiset<key_type, _Compare2, allocator_type>& __source) {
  682. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  683. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  684. __tree_.__node_handle_merge_unique(__source.__tree_);
  685. }
  686. template <class _Compare2>
  687. _LIBCPP_HIDE_FROM_ABI void merge(multiset<key_type, _Compare2, allocator_type>&& __source) {
  688. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  689. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  690. __tree_.__node_handle_merge_unique(__source.__tree_);
  691. }
  692. #endif
  693. _LIBCPP_HIDE_FROM_ABI void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {
  694. __tree_.swap(__s.__tree_);
  695. }
  696. _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return __tree_.__alloc(); }
  697. _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp(); }
  698. _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return __tree_.value_comp(); }
  699. // set operations:
  700. _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
  701. _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
  702. #if _LIBCPP_STD_VER >= 14
  703. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  704. _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
  705. return __tree_.find(__k);
  706. }
  707. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  708. _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
  709. return __tree_.find(__k);
  710. }
  711. #endif
  712. _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_unique(__k); }
  713. #if _LIBCPP_STD_VER >= 14
  714. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  715. _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
  716. return __tree_.__count_multi(__k);
  717. }
  718. #endif
  719. #if _LIBCPP_STD_VER >= 20
  720. _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
  721. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  722. _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
  723. return find(__k) != end();
  724. }
  725. #endif // _LIBCPP_STD_VER >= 20
  726. _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
  727. _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
  728. #if _LIBCPP_STD_VER >= 14
  729. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  730. _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
  731. return __tree_.lower_bound(__k);
  732. }
  733. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  734. _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
  735. return __tree_.lower_bound(__k);
  736. }
  737. #endif
  738. _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
  739. _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
  740. #if _LIBCPP_STD_VER >= 14
  741. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  742. _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
  743. return __tree_.upper_bound(__k);
  744. }
  745. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  746. _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
  747. return __tree_.upper_bound(__k);
  748. }
  749. #endif
  750. _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
  751. return __tree_.__equal_range_unique(__k);
  752. }
  753. _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
  754. return __tree_.__equal_range_unique(__k);
  755. }
  756. #if _LIBCPP_STD_VER >= 14
  757. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  758. _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
  759. return __tree_.__equal_range_multi(__k);
  760. }
  761. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  762. _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
  763. return __tree_.__equal_range_multi(__k);
  764. }
  765. #endif
  766. };
  767. #if _LIBCPP_STD_VER >= 17
  768. template <class _InputIterator,
  769. class _Compare = less<__iter_value_type<_InputIterator>>,
  770. class _Allocator = allocator<__iter_value_type<_InputIterator>>,
  771. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
  772. class = enable_if_t<__is_allocator<_Allocator>::value, void>,
  773. class = enable_if_t<!__is_allocator<_Compare>::value, void>>
  774. set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
  775. -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
  776. # if _LIBCPP_STD_VER >= 23
  777. template <ranges::input_range _Range,
  778. class _Compare = less<ranges::range_value_t<_Range>>,
  779. class _Allocator = allocator<ranges::range_value_t<_Range>>,
  780. class = enable_if_t<__is_allocator<_Allocator>::value, void>,
  781. class = enable_if_t<!__is_allocator<_Compare>::value, void>>
  782. set(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
  783. -> set<ranges::range_value_t<_Range>, _Compare, _Allocator>;
  784. # endif
  785. template <class _Key,
  786. class _Compare = less<_Key>,
  787. class _Allocator = allocator<_Key>,
  788. class = enable_if_t<!__is_allocator<_Compare>::value, void>,
  789. class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  790. set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator()) -> set<_Key, _Compare, _Allocator>;
  791. template <class _InputIterator,
  792. class _Allocator,
  793. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
  794. class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  795. set(_InputIterator, _InputIterator, _Allocator)
  796. -> set<__iter_value_type<_InputIterator>, less<__iter_value_type<_InputIterator>>, _Allocator>;
  797. # if _LIBCPP_STD_VER >= 23
  798. template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  799. set(from_range_t, _Range&&, _Allocator)
  800. -> set<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
  801. # endif
  802. template <class _Key, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  803. set(initializer_list<_Key>, _Allocator) -> set<_Key, less<_Key>, _Allocator>;
  804. #endif
  805. #ifndef _LIBCPP_CXX03_LANG
  806. template <class _Key, class _Compare, class _Allocator>
  807. set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a) : __tree_(std::move(__s.__tree_), __a) {
  808. if (__a != __s.get_allocator()) {
  809. const_iterator __e = cend();
  810. while (!__s.empty())
  811. insert(__e, std::move(__s.__tree_.remove(__s.begin())->__value_));
  812. }
  813. }
  814. #endif // _LIBCPP_CXX03_LANG
  815. template <class _Key, class _Compare, class _Allocator>
  816. inline _LIBCPP_HIDE_FROM_ABI bool
  817. operator==(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
  818. return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
  819. }
  820. #if _LIBCPP_STD_VER <= 17
  821. template <class _Key, class _Compare, class _Allocator>
  822. inline _LIBCPP_HIDE_FROM_ABI bool
  823. operator<(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
  824. return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
  825. }
  826. template <class _Key, class _Compare, class _Allocator>
  827. inline _LIBCPP_HIDE_FROM_ABI bool
  828. operator!=(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
  829. return !(__x == __y);
  830. }
  831. template <class _Key, class _Compare, class _Allocator>
  832. inline _LIBCPP_HIDE_FROM_ABI bool
  833. operator>(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
  834. return __y < __x;
  835. }
  836. template <class _Key, class _Compare, class _Allocator>
  837. inline _LIBCPP_HIDE_FROM_ABI bool
  838. operator>=(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
  839. return !(__x < __y);
  840. }
  841. template <class _Key, class _Compare, class _Allocator>
  842. inline _LIBCPP_HIDE_FROM_ABI bool
  843. operator<=(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
  844. return !(__y < __x);
  845. }
  846. #else // _LIBCPP_STD_VER <= 17
  847. template <class _Key, class _Allocator>
  848. _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key>
  849. operator<=>(const set<_Key, _Allocator>& __x, const set<_Key, _Allocator>& __y) {
  850. return std::lexicographical_compare_three_way(
  851. __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Key, _Key>);
  852. }
  853. #endif // _LIBCPP_STD_VER <= 17
  854. // specialized algorithms:
  855. template <class _Key, class _Compare, class _Allocator>
  856. inline _LIBCPP_HIDE_FROM_ABI void swap(set<_Key, _Compare, _Allocator>& __x, set<_Key, _Compare, _Allocator>& __y)
  857. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
  858. __x.swap(__y);
  859. }
  860. #if _LIBCPP_STD_VER >= 20
  861. template <class _Key, class _Compare, class _Allocator, class _Predicate>
  862. inline _LIBCPP_HIDE_FROM_ABI typename set<_Key, _Compare, _Allocator>::size_type
  863. erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
  864. return std::__libcpp_erase_if_container(__c, __pred);
  865. }
  866. #endif
  867. template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
  868. class _LIBCPP_TEMPLATE_VIS multiset {
  869. public:
  870. // types:
  871. typedef _Key key_type;
  872. typedef key_type value_type;
  873. typedef __type_identity_t<_Compare> key_compare;
  874. typedef key_compare value_compare;
  875. typedef __type_identity_t<_Allocator> allocator_type;
  876. typedef value_type& reference;
  877. typedef const value_type& const_reference;
  878. static_assert((is_same<typename allocator_type::value_type, value_type>::value),
  879. "Allocator::value_type must be same type as value_type");
  880. private:
  881. typedef __tree<value_type, value_compare, allocator_type> __base;
  882. typedef allocator_traits<allocator_type> __alloc_traits;
  883. static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
  884. "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
  885. "original allocator");
  886. __base __tree_;
  887. public:
  888. typedef typename __base::pointer pointer;
  889. typedef typename __base::const_pointer const_pointer;
  890. typedef typename __base::size_type size_type;
  891. typedef typename __base::difference_type difference_type;
  892. typedef typename __base::const_iterator iterator;
  893. typedef typename __base::const_iterator const_iterator;
  894. typedef std::reverse_iterator<iterator> reverse_iterator;
  895. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  896. #if _LIBCPP_STD_VER >= 17
  897. typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
  898. #endif
  899. template <class _Key2, class _Compare2, class _Alloc2>
  900. friend class _LIBCPP_TEMPLATE_VIS set;
  901. template <class _Key2, class _Compare2, class _Alloc2>
  902. friend class _LIBCPP_TEMPLATE_VIS multiset;
  903. // construct/copy/destroy:
  904. _LIBCPP_HIDE_FROM_ABI multiset() _NOEXCEPT_(
  905. is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
  906. is_nothrow_copy_constructible<key_compare>::value)
  907. : __tree_(value_compare()) {}
  908. _LIBCPP_HIDE_FROM_ABI explicit multiset(const value_compare& __comp) _NOEXCEPT_(
  909. is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_copy_constructible<key_compare>::value)
  910. : __tree_(__comp) {}
  911. _LIBCPP_HIDE_FROM_ABI explicit multiset(const value_compare& __comp, const allocator_type& __a)
  912. : __tree_(__comp, __a) {}
  913. template <class _InputIterator>
  914. _LIBCPP_HIDE_FROM_ABI multiset(_InputIterator __f, _InputIterator __l, const value_compare& __comp = value_compare())
  915. : __tree_(__comp) {
  916. insert(__f, __l);
  917. }
  918. #if _LIBCPP_STD_VER >= 14
  919. template <class _InputIterator>
  920. _LIBCPP_HIDE_FROM_ABI multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
  921. : multiset(__f, __l, key_compare(), __a) {}
  922. #endif
  923. template <class _InputIterator>
  924. _LIBCPP_HIDE_FROM_ABI
  925. multiset(_InputIterator __f, _InputIterator __l, const value_compare& __comp, const allocator_type& __a)
  926. : __tree_(__comp, __a) {
  927. insert(__f, __l);
  928. }
  929. #if _LIBCPP_STD_VER >= 23
  930. template <_ContainerCompatibleRange<value_type> _Range>
  931. _LIBCPP_HIDE_FROM_ABI
  932. multiset(from_range_t,
  933. _Range&& __range,
  934. const key_compare& __comp = key_compare(),
  935. const allocator_type& __a = allocator_type())
  936. : __tree_(__comp, __a) {
  937. insert_range(std::forward<_Range>(__range));
  938. }
  939. template <_ContainerCompatibleRange<value_type> _Range>
  940. _LIBCPP_HIDE_FROM_ABI multiset(from_range_t, _Range&& __range, const allocator_type& __a)
  941. : multiset(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
  942. #endif
  943. _LIBCPP_HIDE_FROM_ABI multiset(const multiset& __s)
  944. : __tree_(__s.__tree_.value_comp(),
  945. __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc())) {
  946. insert(__s.begin(), __s.end());
  947. }
  948. _LIBCPP_HIDE_FROM_ABI multiset& operator=(const multiset& __s) {
  949. __tree_ = __s.__tree_;
  950. return *this;
  951. }
  952. #ifndef _LIBCPP_CXX03_LANG
  953. _LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
  954. : __tree_(std::move(__s.__tree_)) {}
  955. _LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s, const allocator_type& __a);
  956. #endif // _LIBCPP_CXX03_LANG
  957. _LIBCPP_HIDE_FROM_ABI explicit multiset(const allocator_type& __a) : __tree_(__a) {}
  958. _LIBCPP_HIDE_FROM_ABI multiset(const multiset& __s, const allocator_type& __a)
  959. : __tree_(__s.__tree_.value_comp(), __a) {
  960. insert(__s.begin(), __s.end());
  961. }
  962. #ifndef _LIBCPP_CXX03_LANG
  963. _LIBCPP_HIDE_FROM_ABI multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
  964. : __tree_(__comp) {
  965. insert(__il.begin(), __il.end());
  966. }
  967. _LIBCPP_HIDE_FROM_ABI
  968. multiset(initializer_list<value_type> __il, const value_compare& __comp, const allocator_type& __a)
  969. : __tree_(__comp, __a) {
  970. insert(__il.begin(), __il.end());
  971. }
  972. # if _LIBCPP_STD_VER >= 14
  973. _LIBCPP_HIDE_FROM_ABI multiset(initializer_list<value_type> __il, const allocator_type& __a)
  974. : multiset(__il, key_compare(), __a) {}
  975. # endif
  976. _LIBCPP_HIDE_FROM_ABI multiset& operator=(initializer_list<value_type> __il) {
  977. __tree_.__assign_multi(__il.begin(), __il.end());
  978. return *this;
  979. }
  980. _LIBCPP_HIDE_FROM_ABI multiset& operator=(multiset&& __s) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) {
  981. __tree_ = std::move(__s.__tree_);
  982. return *this;
  983. }
  984. #endif // _LIBCPP_CXX03_LANG
  985. _LIBCPP_HIDE_FROM_ABI ~multiset() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
  986. _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
  987. _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
  988. _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __tree_.end(); }
  989. _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __tree_.end(); }
  990. _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
  991. _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
  992. _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
  993. _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
  994. _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
  995. _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
  996. _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
  997. _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
  998. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
  999. _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
  1000. _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
  1001. // modifiers:
  1002. #ifndef _LIBCPP_CXX03_LANG
  1003. template <class... _Args>
  1004. _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
  1005. return __tree_.__emplace_multi(std::forward<_Args>(__args)...);
  1006. }
  1007. template <class... _Args>
  1008. _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
  1009. return __tree_.__emplace_hint_multi(__p, std::forward<_Args>(__args)...);
  1010. }
  1011. #endif // _LIBCPP_CXX03_LANG
  1012. _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
  1013. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
  1014. return __tree_.__insert_multi(__p, __v);
  1015. }
  1016. template <class _InputIterator>
  1017. _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
  1018. for (const_iterator __e = cend(); __f != __l; ++__f)
  1019. __tree_.__insert_multi(__e, *__f);
  1020. }
  1021. #if _LIBCPP_STD_VER >= 23
  1022. template <_ContainerCompatibleRange<value_type> _Range>
  1023. _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
  1024. const_iterator __end = cend();
  1025. for (auto&& __element : __range) {
  1026. __tree_.__insert_multi(__end, std::forward<decltype(__element)>(__element));
  1027. }
  1028. }
  1029. #endif
  1030. #ifndef _LIBCPP_CXX03_LANG
  1031. _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
  1032. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
  1033. return __tree_.__insert_multi(__p, std::move(__v));
  1034. }
  1035. _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
  1036. #endif // _LIBCPP_CXX03_LANG
  1037. _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p); }
  1038. _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_multi(__k); }
  1039. _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) { return __tree_.erase(__f, __l); }
  1040. _LIBCPP_REINITIALIZES_OBJECT
  1041. _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
  1042. #if _LIBCPP_STD_VER >= 17
  1043. _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
  1044. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1045. "node_type with incompatible allocator passed to multiset::insert()");
  1046. return __tree_.template __node_handle_insert_multi<node_type>(std::move(__nh));
  1047. }
  1048. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
  1049. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1050. "node_type with incompatible allocator passed to multiset::insert()");
  1051. return __tree_.template __node_handle_insert_multi<node_type>(__hint, std::move(__nh));
  1052. }
  1053. _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
  1054. return __tree_.template __node_handle_extract<node_type>(__key);
  1055. }
  1056. _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
  1057. return __tree_.template __node_handle_extract<node_type>(__it);
  1058. }
  1059. template <class _Compare2>
  1060. _LIBCPP_HIDE_FROM_ABI void merge(multiset<key_type, _Compare2, allocator_type>& __source) {
  1061. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1062. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1063. __tree_.__node_handle_merge_multi(__source.__tree_);
  1064. }
  1065. template <class _Compare2>
  1066. _LIBCPP_HIDE_FROM_ABI void merge(multiset<key_type, _Compare2, allocator_type>&& __source) {
  1067. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1068. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1069. __tree_.__node_handle_merge_multi(__source.__tree_);
  1070. }
  1071. template <class _Compare2>
  1072. _LIBCPP_HIDE_FROM_ABI void merge(set<key_type, _Compare2, allocator_type>& __source) {
  1073. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1074. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1075. __tree_.__node_handle_merge_multi(__source.__tree_);
  1076. }
  1077. template <class _Compare2>
  1078. _LIBCPP_HIDE_FROM_ABI void merge(set<key_type, _Compare2, allocator_type>&& __source) {
  1079. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1080. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1081. __tree_.__node_handle_merge_multi(__source.__tree_);
  1082. }
  1083. #endif
  1084. _LIBCPP_HIDE_FROM_ABI void swap(multiset& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {
  1085. __tree_.swap(__s.__tree_);
  1086. }
  1087. _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return __tree_.__alloc(); }
  1088. _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp(); }
  1089. _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return __tree_.value_comp(); }
  1090. // set operations:
  1091. _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
  1092. _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
  1093. #if _LIBCPP_STD_VER >= 14
  1094. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1095. _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
  1096. return __tree_.find(__k);
  1097. }
  1098. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1099. _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
  1100. return __tree_.find(__k);
  1101. }
  1102. #endif
  1103. _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_multi(__k); }
  1104. #if _LIBCPP_STD_VER >= 14
  1105. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1106. _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
  1107. return __tree_.__count_multi(__k);
  1108. }
  1109. #endif
  1110. #if _LIBCPP_STD_VER >= 20
  1111. _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
  1112. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1113. _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
  1114. return find(__k) != end();
  1115. }
  1116. #endif // _LIBCPP_STD_VER >= 20
  1117. _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
  1118. _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
  1119. #if _LIBCPP_STD_VER >= 14
  1120. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1121. _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
  1122. return __tree_.lower_bound(__k);
  1123. }
  1124. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1125. _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
  1126. return __tree_.lower_bound(__k);
  1127. }
  1128. #endif
  1129. _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
  1130. _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
  1131. #if _LIBCPP_STD_VER >= 14
  1132. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1133. _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
  1134. return __tree_.upper_bound(__k);
  1135. }
  1136. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1137. _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
  1138. return __tree_.upper_bound(__k);
  1139. }
  1140. #endif
  1141. _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
  1142. return __tree_.__equal_range_multi(__k);
  1143. }
  1144. _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
  1145. return __tree_.__equal_range_multi(__k);
  1146. }
  1147. #if _LIBCPP_STD_VER >= 14
  1148. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1149. _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
  1150. return __tree_.__equal_range_multi(__k);
  1151. }
  1152. template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
  1153. _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
  1154. return __tree_.__equal_range_multi(__k);
  1155. }
  1156. #endif
  1157. };
  1158. #if _LIBCPP_STD_VER >= 17
  1159. template <class _InputIterator,
  1160. class _Compare = less<__iter_value_type<_InputIterator>>,
  1161. class _Allocator = allocator<__iter_value_type<_InputIterator>>,
  1162. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
  1163. class = enable_if_t<__is_allocator<_Allocator>::value, void>,
  1164. class = enable_if_t<!__is_allocator<_Compare>::value, void>>
  1165. multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
  1166. -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
  1167. # if _LIBCPP_STD_VER >= 23
  1168. template <ranges::input_range _Range,
  1169. class _Compare = less<ranges::range_value_t<_Range>>,
  1170. class _Allocator = allocator<ranges::range_value_t<_Range>>,
  1171. class = enable_if_t<__is_allocator<_Allocator>::value, void>,
  1172. class = enable_if_t<!__is_allocator<_Compare>::value, void>>
  1173. multiset(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
  1174. -> multiset<ranges::range_value_t<_Range>, _Compare, _Allocator>;
  1175. # endif
  1176. template <class _Key,
  1177. class _Compare = less<_Key>,
  1178. class _Allocator = allocator<_Key>,
  1179. class = enable_if_t<__is_allocator<_Allocator>::value, void>,
  1180. class = enable_if_t<!__is_allocator<_Compare>::value, void>>
  1181. multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
  1182. -> multiset<_Key, _Compare, _Allocator>;
  1183. template <class _InputIterator,
  1184. class _Allocator,
  1185. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
  1186. class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  1187. multiset(_InputIterator, _InputIterator, _Allocator)
  1188. -> multiset<__iter_value_type<_InputIterator>, less<__iter_value_type<_InputIterator>>, _Allocator>;
  1189. # if _LIBCPP_STD_VER >= 23
  1190. template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  1191. multiset(from_range_t, _Range&&, _Allocator)
  1192. -> multiset<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
  1193. # endif
  1194. template <class _Key, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  1195. multiset(initializer_list<_Key>, _Allocator) -> multiset<_Key, less<_Key>, _Allocator>;
  1196. #endif
  1197. #ifndef _LIBCPP_CXX03_LANG
  1198. template <class _Key, class _Compare, class _Allocator>
  1199. multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
  1200. : __tree_(std::move(__s.__tree_), __a) {
  1201. if (__a != __s.get_allocator()) {
  1202. const_iterator __e = cend();
  1203. while (!__s.empty())
  1204. insert(__e, std::move(__s.__tree_.remove(__s.begin())->__value_));
  1205. }
  1206. }
  1207. #endif // _LIBCPP_CXX03_LANG
  1208. template <class _Key, class _Compare, class _Allocator>
  1209. inline _LIBCPP_HIDE_FROM_ABI bool
  1210. operator==(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
  1211. return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
  1212. }
  1213. #if _LIBCPP_STD_VER <= 17
  1214. template <class _Key, class _Compare, class _Allocator>
  1215. inline _LIBCPP_HIDE_FROM_ABI bool
  1216. operator<(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
  1217. return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
  1218. }
  1219. template <class _Key, class _Compare, class _Allocator>
  1220. inline _LIBCPP_HIDE_FROM_ABI bool
  1221. operator!=(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
  1222. return !(__x == __y);
  1223. }
  1224. template <class _Key, class _Compare, class _Allocator>
  1225. inline _LIBCPP_HIDE_FROM_ABI bool
  1226. operator>(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
  1227. return __y < __x;
  1228. }
  1229. template <class _Key, class _Compare, class _Allocator>
  1230. inline _LIBCPP_HIDE_FROM_ABI bool
  1231. operator>=(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
  1232. return !(__x < __y);
  1233. }
  1234. template <class _Key, class _Compare, class _Allocator>
  1235. inline _LIBCPP_HIDE_FROM_ABI bool
  1236. operator<=(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
  1237. return !(__y < __x);
  1238. }
  1239. #else // _LIBCPP_STD_VER <= 17
  1240. template <class _Key, class _Allocator>
  1241. _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key>
  1242. operator<=>(const multiset<_Key, _Allocator>& __x, const multiset<_Key, _Allocator>& __y) {
  1243. return std::lexicographical_compare_three_way(
  1244. __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Key, _Key>);
  1245. }
  1246. #endif // _LIBCPP_STD_VER <= 17
  1247. template <class _Key, class _Compare, class _Allocator>
  1248. inline _LIBCPP_HIDE_FROM_ABI void
  1249. swap(multiset<_Key, _Compare, _Allocator>& __x, multiset<_Key, _Compare, _Allocator>& __y)
  1250. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
  1251. __x.swap(__y);
  1252. }
  1253. #if _LIBCPP_STD_VER >= 20
  1254. template <class _Key, class _Compare, class _Allocator, class _Predicate>
  1255. inline _LIBCPP_HIDE_FROM_ABI typename multiset<_Key, _Compare, _Allocator>::size_type
  1256. erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
  1257. return std::__libcpp_erase_if_container(__c, __pred);
  1258. }
  1259. #endif
  1260. _LIBCPP_END_NAMESPACE_STD
  1261. #if _LIBCPP_STD_VER >= 17
  1262. _LIBCPP_BEGIN_NAMESPACE_STD
  1263. namespace pmr {
  1264. template <class _KeyT, class _CompareT = std::less<_KeyT>>
  1265. using set _LIBCPP_AVAILABILITY_PMR = std::set<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>;
  1266. template <class _KeyT, class _CompareT = std::less<_KeyT>>
  1267. using multiset _LIBCPP_AVAILABILITY_PMR = std::multiset<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>;
  1268. } // namespace pmr
  1269. _LIBCPP_END_NAMESPACE_STD
  1270. #endif
  1271. _LIBCPP_POP_MACROS
  1272. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  1273. # include <concepts>
  1274. # include <cstdlib>
  1275. # include <functional>
  1276. # include <iterator>
  1277. # include <stdexcept>
  1278. # include <type_traits>
  1279. #endif
  1280. #endif // _LIBCPP_SET