set 60 KB

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