set 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  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 <__node_handle>
  414. #include <__tree>
  415. #include <__utility/forward.h>
  416. #include <version>
  417. #ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
  418. # include <functional>
  419. # include <iterator>
  420. #endif
  421. // standard-mandated includes
  422. // [iterator.range]
  423. #include <__iterator/access.h>
  424. #include <__iterator/data.h>
  425. #include <__iterator/empty.h>
  426. #include <__iterator/reverse_access.h>
  427. #include <__iterator/size.h>
  428. // [associative.set.syn]
  429. #include <compare>
  430. #include <initializer_list>
  431. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  432. # pragma GCC system_header
  433. #endif
  434. _LIBCPP_BEGIN_NAMESPACE_STD
  435. template <class _Key, class _Compare, class _Allocator>
  436. class multiset;
  437. template <class _Key, class _Compare = less<_Key>,
  438. class _Allocator = allocator<_Key> >
  439. class _LIBCPP_TEMPLATE_VIS set
  440. {
  441. public:
  442. // types:
  443. typedef _Key key_type;
  444. typedef key_type value_type;
  445. typedef __type_identity_t<_Compare> key_compare;
  446. typedef key_compare value_compare;
  447. typedef __type_identity_t<_Allocator> allocator_type;
  448. typedef value_type& reference;
  449. typedef const value_type& const_reference;
  450. static_assert((is_same<typename allocator_type::value_type, value_type>::value),
  451. "Allocator::value_type must be same type as value_type");
  452. private:
  453. typedef __tree<value_type, value_compare, allocator_type> __base;
  454. typedef allocator_traits<allocator_type> __alloc_traits;
  455. __base __tree_;
  456. public:
  457. typedef typename __base::pointer pointer;
  458. typedef typename __base::const_pointer const_pointer;
  459. typedef typename __base::size_type size_type;
  460. typedef typename __base::difference_type difference_type;
  461. typedef typename __base::const_iterator iterator;
  462. typedef typename __base::const_iterator const_iterator;
  463. typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
  464. typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
  465. #if _LIBCPP_STD_VER > 14
  466. typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
  467. typedef __insert_return_type<iterator, node_type> insert_return_type;
  468. #endif
  469. template <class _Key2, class _Compare2, class _Alloc2>
  470. friend class _LIBCPP_TEMPLATE_VIS set;
  471. template <class _Key2, class _Compare2, class _Alloc2>
  472. friend class _LIBCPP_TEMPLATE_VIS multiset;
  473. _LIBCPP_INLINE_VISIBILITY
  474. set()
  475. _NOEXCEPT_(
  476. is_nothrow_default_constructible<allocator_type>::value &&
  477. is_nothrow_default_constructible<key_compare>::value &&
  478. is_nothrow_copy_constructible<key_compare>::value)
  479. : __tree_(value_compare()) {}
  480. _LIBCPP_INLINE_VISIBILITY
  481. explicit set(const value_compare& __comp)
  482. _NOEXCEPT_(
  483. is_nothrow_default_constructible<allocator_type>::value &&
  484. is_nothrow_copy_constructible<key_compare>::value)
  485. : __tree_(__comp) {}
  486. _LIBCPP_INLINE_VISIBILITY
  487. explicit set(const value_compare& __comp, const allocator_type& __a)
  488. : __tree_(__comp, __a) {}
  489. template <class _InputIterator>
  490. _LIBCPP_INLINE_VISIBILITY
  491. set(_InputIterator __f, _InputIterator __l,
  492. const value_compare& __comp = value_compare())
  493. : __tree_(__comp)
  494. {
  495. insert(__f, __l);
  496. }
  497. template <class _InputIterator>
  498. _LIBCPP_INLINE_VISIBILITY
  499. set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
  500. const allocator_type& __a)
  501. : __tree_(__comp, __a)
  502. {
  503. insert(__f, __l);
  504. }
  505. #if _LIBCPP_STD_VER > 11
  506. template <class _InputIterator>
  507. _LIBCPP_INLINE_VISIBILITY
  508. set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
  509. : set(__f, __l, key_compare(), __a) {}
  510. #endif
  511. _LIBCPP_INLINE_VISIBILITY
  512. set(const set& __s)
  513. : __tree_(__s.__tree_)
  514. {
  515. insert(__s.begin(), __s.end());
  516. }
  517. _LIBCPP_INLINE_VISIBILITY
  518. set& operator=(const set& __s)
  519. {
  520. __tree_ = __s.__tree_;
  521. return *this;
  522. }
  523. #ifndef _LIBCPP_CXX03_LANG
  524. _LIBCPP_INLINE_VISIBILITY
  525. set(set&& __s)
  526. _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
  527. : __tree_(_VSTD::move(__s.__tree_)) {}
  528. #endif // _LIBCPP_CXX03_LANG
  529. _LIBCPP_INLINE_VISIBILITY
  530. explicit set(const allocator_type& __a)
  531. : __tree_(__a) {}
  532. _LIBCPP_INLINE_VISIBILITY
  533. set(const set& __s, const allocator_type& __a)
  534. : __tree_(__s.__tree_.value_comp(), __a)
  535. {
  536. insert(__s.begin(), __s.end());
  537. }
  538. #ifndef _LIBCPP_CXX03_LANG
  539. set(set&& __s, const allocator_type& __a);
  540. _LIBCPP_INLINE_VISIBILITY
  541. set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
  542. : __tree_(__comp)
  543. {
  544. insert(__il.begin(), __il.end());
  545. }
  546. _LIBCPP_INLINE_VISIBILITY
  547. set(initializer_list<value_type> __il, const value_compare& __comp,
  548. const allocator_type& __a)
  549. : __tree_(__comp, __a)
  550. {
  551. insert(__il.begin(), __il.end());
  552. }
  553. #if _LIBCPP_STD_VER > 11
  554. _LIBCPP_INLINE_VISIBILITY
  555. set(initializer_list<value_type> __il, const allocator_type& __a)
  556. : set(__il, key_compare(), __a) {}
  557. #endif
  558. _LIBCPP_INLINE_VISIBILITY
  559. set& operator=(initializer_list<value_type> __il)
  560. {
  561. __tree_.__assign_unique(__il.begin(), __il.end());
  562. return *this;
  563. }
  564. _LIBCPP_INLINE_VISIBILITY
  565. set& operator=(set&& __s)
  566. _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
  567. {
  568. __tree_ = _VSTD::move(__s.__tree_);
  569. return *this;
  570. }
  571. #endif // _LIBCPP_CXX03_LANG
  572. _LIBCPP_INLINE_VISIBILITY
  573. ~set() {
  574. static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
  575. }
  576. _LIBCPP_INLINE_VISIBILITY
  577. iterator begin() _NOEXCEPT {return __tree_.begin();}
  578. _LIBCPP_INLINE_VISIBILITY
  579. const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
  580. _LIBCPP_INLINE_VISIBILITY
  581. iterator end() _NOEXCEPT {return __tree_.end();}
  582. _LIBCPP_INLINE_VISIBILITY
  583. const_iterator end() const _NOEXCEPT {return __tree_.end();}
  584. _LIBCPP_INLINE_VISIBILITY
  585. reverse_iterator rbegin() _NOEXCEPT
  586. {return reverse_iterator(end());}
  587. _LIBCPP_INLINE_VISIBILITY
  588. const_reverse_iterator rbegin() const _NOEXCEPT
  589. {return const_reverse_iterator(end());}
  590. _LIBCPP_INLINE_VISIBILITY
  591. reverse_iterator rend() _NOEXCEPT
  592. {return reverse_iterator(begin());}
  593. _LIBCPP_INLINE_VISIBILITY
  594. const_reverse_iterator rend() const _NOEXCEPT
  595. {return const_reverse_iterator(begin());}
  596. _LIBCPP_INLINE_VISIBILITY
  597. const_iterator cbegin() const _NOEXCEPT {return begin();}
  598. _LIBCPP_INLINE_VISIBILITY
  599. const_iterator cend() const _NOEXCEPT {return end();}
  600. _LIBCPP_INLINE_VISIBILITY
  601. const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
  602. _LIBCPP_INLINE_VISIBILITY
  603. const_reverse_iterator crend() const _NOEXCEPT {return rend();}
  604. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  605. bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
  606. _LIBCPP_INLINE_VISIBILITY
  607. size_type size() const _NOEXCEPT {return __tree_.size();}
  608. _LIBCPP_INLINE_VISIBILITY
  609. size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
  610. // modifiers:
  611. #ifndef _LIBCPP_CXX03_LANG
  612. template <class... _Args>
  613. _LIBCPP_INLINE_VISIBILITY
  614. pair<iterator, bool> emplace(_Args&&... __args)
  615. {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
  616. template <class... _Args>
  617. _LIBCPP_INLINE_VISIBILITY
  618. iterator emplace_hint(const_iterator __p, _Args&&... __args)
  619. {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
  620. #endif // _LIBCPP_CXX03_LANG
  621. _LIBCPP_INLINE_VISIBILITY
  622. pair<iterator,bool> insert(const value_type& __v)
  623. {return __tree_.__insert_unique(__v);}
  624. _LIBCPP_INLINE_VISIBILITY
  625. iterator insert(const_iterator __p, const value_type& __v)
  626. {return __tree_.__insert_unique(__p, __v);}
  627. template <class _InputIterator>
  628. _LIBCPP_INLINE_VISIBILITY
  629. void insert(_InputIterator __f, _InputIterator __l)
  630. {
  631. for (const_iterator __e = cend(); __f != __l; ++__f)
  632. __tree_.__insert_unique(__e, *__f);
  633. }
  634. #ifndef _LIBCPP_CXX03_LANG
  635. _LIBCPP_INLINE_VISIBILITY
  636. pair<iterator,bool> insert(value_type&& __v)
  637. {return __tree_.__insert_unique(_VSTD::move(__v));}
  638. _LIBCPP_INLINE_VISIBILITY
  639. iterator insert(const_iterator __p, value_type&& __v)
  640. {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
  641. _LIBCPP_INLINE_VISIBILITY
  642. void insert(initializer_list<value_type> __il)
  643. {insert(__il.begin(), __il.end());}
  644. #endif // _LIBCPP_CXX03_LANG
  645. _LIBCPP_INLINE_VISIBILITY
  646. iterator erase(const_iterator __p) {return __tree_.erase(__p);}
  647. _LIBCPP_INLINE_VISIBILITY
  648. size_type erase(const key_type& __k)
  649. {return __tree_.__erase_unique(__k);}
  650. _LIBCPP_INLINE_VISIBILITY
  651. iterator erase(const_iterator __f, const_iterator __l)
  652. {return __tree_.erase(__f, __l);}
  653. _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_INLINE_VISIBILITY
  654. void clear() _NOEXCEPT {__tree_.clear();}
  655. #if _LIBCPP_STD_VER > 14
  656. _LIBCPP_INLINE_VISIBILITY
  657. insert_return_type insert(node_type&& __nh)
  658. {
  659. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  660. "node_type with incompatible allocator passed to set::insert()");
  661. return __tree_.template __node_handle_insert_unique<
  662. node_type, insert_return_type>(_VSTD::move(__nh));
  663. }
  664. _LIBCPP_INLINE_VISIBILITY
  665. iterator insert(const_iterator __hint, node_type&& __nh)
  666. {
  667. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  668. "node_type with incompatible allocator passed to set::insert()");
  669. return __tree_.template __node_handle_insert_unique<node_type>(
  670. __hint, _VSTD::move(__nh));
  671. }
  672. _LIBCPP_INLINE_VISIBILITY
  673. node_type extract(key_type const& __key)
  674. {
  675. return __tree_.template __node_handle_extract<node_type>(__key);
  676. }
  677. _LIBCPP_INLINE_VISIBILITY
  678. node_type extract(const_iterator __it)
  679. {
  680. return __tree_.template __node_handle_extract<node_type>(__it);
  681. }
  682. template <class _Compare2>
  683. _LIBCPP_INLINE_VISIBILITY
  684. void merge(set<key_type, _Compare2, allocator_type>& __source)
  685. {
  686. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  687. "merging container with incompatible allocator");
  688. __tree_.__node_handle_merge_unique(__source.__tree_);
  689. }
  690. template <class _Compare2>
  691. _LIBCPP_INLINE_VISIBILITY
  692. void merge(set<key_type, _Compare2, allocator_type>&& __source)
  693. {
  694. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  695. "merging container with incompatible allocator");
  696. __tree_.__node_handle_merge_unique(__source.__tree_);
  697. }
  698. template <class _Compare2>
  699. _LIBCPP_INLINE_VISIBILITY
  700. void merge(multiset<key_type, _Compare2, allocator_type>& __source)
  701. {
  702. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  703. "merging container with incompatible allocator");
  704. __tree_.__node_handle_merge_unique(__source.__tree_);
  705. }
  706. template <class _Compare2>
  707. _LIBCPP_INLINE_VISIBILITY
  708. void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
  709. {
  710. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  711. "merging container with incompatible allocator");
  712. __tree_.__node_handle_merge_unique(__source.__tree_);
  713. }
  714. #endif
  715. _LIBCPP_INLINE_VISIBILITY
  716. void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
  717. {__tree_.swap(__s.__tree_);}
  718. _LIBCPP_INLINE_VISIBILITY
  719. allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
  720. _LIBCPP_INLINE_VISIBILITY
  721. key_compare key_comp() const {return __tree_.value_comp();}
  722. _LIBCPP_INLINE_VISIBILITY
  723. value_compare value_comp() const {return __tree_.value_comp();}
  724. // set operations:
  725. _LIBCPP_INLINE_VISIBILITY
  726. iterator find(const key_type& __k) {return __tree_.find(__k);}
  727. _LIBCPP_INLINE_VISIBILITY
  728. const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
  729. #if _LIBCPP_STD_VER > 11
  730. template <typename _K2>
  731. _LIBCPP_INLINE_VISIBILITY
  732. typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
  733. find(const _K2& __k) {return __tree_.find(__k);}
  734. template <typename _K2>
  735. _LIBCPP_INLINE_VISIBILITY
  736. typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
  737. find(const _K2& __k) const {return __tree_.find(__k);}
  738. #endif
  739. _LIBCPP_INLINE_VISIBILITY
  740. size_type count(const key_type& __k) const
  741. {return __tree_.__count_unique(__k);}
  742. #if _LIBCPP_STD_VER > 11
  743. template <typename _K2>
  744. _LIBCPP_INLINE_VISIBILITY
  745. typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
  746. count(const _K2& __k) const {return __tree_.__count_multi(__k);}
  747. #endif
  748. #if _LIBCPP_STD_VER > 17
  749. _LIBCPP_INLINE_VISIBILITY
  750. bool contains(const key_type& __k) const {return find(__k) != end();}
  751. template <typename _K2>
  752. _LIBCPP_INLINE_VISIBILITY
  753. typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
  754. contains(const _K2& __k) const { return find(__k) != end(); }
  755. #endif // _LIBCPP_STD_VER > 17
  756. _LIBCPP_INLINE_VISIBILITY
  757. iterator lower_bound(const key_type& __k)
  758. {return __tree_.lower_bound(__k);}
  759. _LIBCPP_INLINE_VISIBILITY
  760. const_iterator lower_bound(const key_type& __k) const
  761. {return __tree_.lower_bound(__k);}
  762. #if _LIBCPP_STD_VER > 11
  763. template <typename _K2>
  764. _LIBCPP_INLINE_VISIBILITY
  765. typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
  766. lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
  767. template <typename _K2>
  768. _LIBCPP_INLINE_VISIBILITY
  769. typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
  770. lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
  771. #endif
  772. _LIBCPP_INLINE_VISIBILITY
  773. iterator upper_bound(const key_type& __k)
  774. {return __tree_.upper_bound(__k);}
  775. _LIBCPP_INLINE_VISIBILITY
  776. const_iterator upper_bound(const key_type& __k) const
  777. {return __tree_.upper_bound(__k);}
  778. #if _LIBCPP_STD_VER > 11
  779. template <typename _K2>
  780. _LIBCPP_INLINE_VISIBILITY
  781. typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
  782. upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
  783. template <typename _K2>
  784. _LIBCPP_INLINE_VISIBILITY
  785. typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
  786. upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
  787. #endif
  788. _LIBCPP_INLINE_VISIBILITY
  789. pair<iterator,iterator> equal_range(const key_type& __k)
  790. {return __tree_.__equal_range_unique(__k);}
  791. _LIBCPP_INLINE_VISIBILITY
  792. pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
  793. {return __tree_.__equal_range_unique(__k);}
  794. #if _LIBCPP_STD_VER > 11
  795. template <typename _K2>
  796. _LIBCPP_INLINE_VISIBILITY
  797. typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
  798. equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
  799. template <typename _K2>
  800. _LIBCPP_INLINE_VISIBILITY
  801. typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
  802. equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
  803. #endif
  804. };
  805. #if _LIBCPP_STD_VER >= 17
  806. template<class _InputIterator,
  807. class _Compare = less<__iter_value_type<_InputIterator>>,
  808. class _Allocator = allocator<__iter_value_type<_InputIterator>>,
  809. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
  810. class = enable_if_t<__is_allocator<_Allocator>::value, void>,
  811. class = enable_if_t<!__is_allocator<_Compare>::value, void>>
  812. set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
  813. -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
  814. template<class _Key, class _Compare = less<_Key>,
  815. class _Allocator = allocator<_Key>,
  816. class = enable_if_t<!__is_allocator<_Compare>::value, void>,
  817. class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  818. set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
  819. -> set<_Key, _Compare, _Allocator>;
  820. template<class _InputIterator, class _Allocator,
  821. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
  822. class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  823. set(_InputIterator, _InputIterator, _Allocator)
  824. -> set<__iter_value_type<_InputIterator>,
  825. less<__iter_value_type<_InputIterator>>, _Allocator>;
  826. template<class _Key, class _Allocator,
  827. class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  828. set(initializer_list<_Key>, _Allocator)
  829. -> set<_Key, less<_Key>, _Allocator>;
  830. #endif
  831. #ifndef _LIBCPP_CXX03_LANG
  832. template <class _Key, class _Compare, class _Allocator>
  833. set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
  834. : __tree_(_VSTD::move(__s.__tree_), __a)
  835. {
  836. if (__a != __s.get_allocator())
  837. {
  838. const_iterator __e = cend();
  839. while (!__s.empty())
  840. insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
  841. }
  842. }
  843. #endif // _LIBCPP_CXX03_LANG
  844. template <class _Key, class _Compare, class _Allocator>
  845. inline _LIBCPP_INLINE_VISIBILITY
  846. bool
  847. operator==(const set<_Key, _Compare, _Allocator>& __x,
  848. const set<_Key, _Compare, _Allocator>& __y)
  849. {
  850. return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
  851. }
  852. template <class _Key, class _Compare, class _Allocator>
  853. inline _LIBCPP_INLINE_VISIBILITY
  854. bool
  855. operator< (const set<_Key, _Compare, _Allocator>& __x,
  856. const set<_Key, _Compare, _Allocator>& __y)
  857. {
  858. return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
  859. }
  860. template <class _Key, class _Compare, class _Allocator>
  861. inline _LIBCPP_INLINE_VISIBILITY
  862. bool
  863. operator!=(const set<_Key, _Compare, _Allocator>& __x,
  864. const set<_Key, _Compare, _Allocator>& __y)
  865. {
  866. return !(__x == __y);
  867. }
  868. template <class _Key, class _Compare, class _Allocator>
  869. inline _LIBCPP_INLINE_VISIBILITY
  870. bool
  871. operator> (const set<_Key, _Compare, _Allocator>& __x,
  872. const set<_Key, _Compare, _Allocator>& __y)
  873. {
  874. return __y < __x;
  875. }
  876. template <class _Key, class _Compare, class _Allocator>
  877. inline _LIBCPP_INLINE_VISIBILITY
  878. bool
  879. operator>=(const set<_Key, _Compare, _Allocator>& __x,
  880. const set<_Key, _Compare, _Allocator>& __y)
  881. {
  882. return !(__x < __y);
  883. }
  884. template <class _Key, class _Compare, class _Allocator>
  885. inline _LIBCPP_INLINE_VISIBILITY
  886. bool
  887. operator<=(const set<_Key, _Compare, _Allocator>& __x,
  888. const set<_Key, _Compare, _Allocator>& __y)
  889. {
  890. return !(__y < __x);
  891. }
  892. // specialized algorithms:
  893. template <class _Key, class _Compare, class _Allocator>
  894. inline _LIBCPP_INLINE_VISIBILITY
  895. void
  896. swap(set<_Key, _Compare, _Allocator>& __x,
  897. set<_Key, _Compare, _Allocator>& __y)
  898. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  899. {
  900. __x.swap(__y);
  901. }
  902. #if _LIBCPP_STD_VER > 17
  903. template <class _Key, class _Compare, class _Allocator, class _Predicate>
  904. inline _LIBCPP_INLINE_VISIBILITY
  905. typename set<_Key, _Compare, _Allocator>::size_type
  906. erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
  907. return _VSTD::__libcpp_erase_if_container(__c, __pred);
  908. }
  909. #endif
  910. template <class _Key, class _Compare = less<_Key>,
  911. class _Allocator = allocator<_Key> >
  912. class _LIBCPP_TEMPLATE_VIS multiset
  913. {
  914. public:
  915. // types:
  916. typedef _Key key_type;
  917. typedef key_type value_type;
  918. typedef __type_identity_t<_Compare> key_compare;
  919. typedef key_compare value_compare;
  920. typedef __type_identity_t<_Allocator> allocator_type;
  921. typedef value_type& reference;
  922. typedef const value_type& const_reference;
  923. static_assert((is_same<typename allocator_type::value_type, value_type>::value),
  924. "Allocator::value_type must be same type as value_type");
  925. private:
  926. typedef __tree<value_type, value_compare, allocator_type> __base;
  927. typedef allocator_traits<allocator_type> __alloc_traits;
  928. __base __tree_;
  929. public:
  930. typedef typename __base::pointer pointer;
  931. typedef typename __base::const_pointer const_pointer;
  932. typedef typename __base::size_type size_type;
  933. typedef typename __base::difference_type difference_type;
  934. typedef typename __base::const_iterator iterator;
  935. typedef typename __base::const_iterator const_iterator;
  936. typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
  937. typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
  938. #if _LIBCPP_STD_VER > 14
  939. typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
  940. #endif
  941. template <class _Key2, class _Compare2, class _Alloc2>
  942. friend class _LIBCPP_TEMPLATE_VIS set;
  943. template <class _Key2, class _Compare2, class _Alloc2>
  944. friend class _LIBCPP_TEMPLATE_VIS multiset;
  945. // construct/copy/destroy:
  946. _LIBCPP_INLINE_VISIBILITY
  947. multiset()
  948. _NOEXCEPT_(
  949. is_nothrow_default_constructible<allocator_type>::value &&
  950. is_nothrow_default_constructible<key_compare>::value &&
  951. is_nothrow_copy_constructible<key_compare>::value)
  952. : __tree_(value_compare()) {}
  953. _LIBCPP_INLINE_VISIBILITY
  954. explicit multiset(const value_compare& __comp)
  955. _NOEXCEPT_(
  956. is_nothrow_default_constructible<allocator_type>::value &&
  957. is_nothrow_copy_constructible<key_compare>::value)
  958. : __tree_(__comp) {}
  959. _LIBCPP_INLINE_VISIBILITY
  960. explicit multiset(const value_compare& __comp, const allocator_type& __a)
  961. : __tree_(__comp, __a) {}
  962. template <class _InputIterator>
  963. _LIBCPP_INLINE_VISIBILITY
  964. multiset(_InputIterator __f, _InputIterator __l,
  965. const value_compare& __comp = value_compare())
  966. : __tree_(__comp)
  967. {
  968. insert(__f, __l);
  969. }
  970. #if _LIBCPP_STD_VER > 11
  971. template <class _InputIterator>
  972. _LIBCPP_INLINE_VISIBILITY
  973. multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
  974. : multiset(__f, __l, key_compare(), __a) {}
  975. #endif
  976. template <class _InputIterator>
  977. _LIBCPP_INLINE_VISIBILITY
  978. multiset(_InputIterator __f, _InputIterator __l,
  979. const value_compare& __comp, const allocator_type& __a)
  980. : __tree_(__comp, __a)
  981. {
  982. insert(__f, __l);
  983. }
  984. _LIBCPP_INLINE_VISIBILITY
  985. multiset(const multiset& __s)
  986. : __tree_(__s.__tree_.value_comp(),
  987. __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
  988. {
  989. insert(__s.begin(), __s.end());
  990. }
  991. _LIBCPP_INLINE_VISIBILITY
  992. multiset& operator=(const multiset& __s)
  993. {
  994. __tree_ = __s.__tree_;
  995. return *this;
  996. }
  997. #ifndef _LIBCPP_CXX03_LANG
  998. _LIBCPP_INLINE_VISIBILITY
  999. multiset(multiset&& __s)
  1000. _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
  1001. : __tree_(_VSTD::move(__s.__tree_)) {}
  1002. multiset(multiset&& __s, const allocator_type& __a);
  1003. #endif // _LIBCPP_CXX03_LANG
  1004. _LIBCPP_INLINE_VISIBILITY
  1005. explicit multiset(const allocator_type& __a)
  1006. : __tree_(__a) {}
  1007. _LIBCPP_INLINE_VISIBILITY
  1008. multiset(const multiset& __s, const allocator_type& __a)
  1009. : __tree_(__s.__tree_.value_comp(), __a)
  1010. {
  1011. insert(__s.begin(), __s.end());
  1012. }
  1013. #ifndef _LIBCPP_CXX03_LANG
  1014. _LIBCPP_INLINE_VISIBILITY
  1015. multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
  1016. : __tree_(__comp)
  1017. {
  1018. insert(__il.begin(), __il.end());
  1019. }
  1020. _LIBCPP_INLINE_VISIBILITY
  1021. multiset(initializer_list<value_type> __il, const value_compare& __comp,
  1022. const allocator_type& __a)
  1023. : __tree_(__comp, __a)
  1024. {
  1025. insert(__il.begin(), __il.end());
  1026. }
  1027. #if _LIBCPP_STD_VER > 11
  1028. _LIBCPP_INLINE_VISIBILITY
  1029. multiset(initializer_list<value_type> __il, const allocator_type& __a)
  1030. : multiset(__il, key_compare(), __a) {}
  1031. #endif
  1032. _LIBCPP_INLINE_VISIBILITY
  1033. multiset& operator=(initializer_list<value_type> __il)
  1034. {
  1035. __tree_.__assign_multi(__il.begin(), __il.end());
  1036. return *this;
  1037. }
  1038. _LIBCPP_INLINE_VISIBILITY
  1039. multiset& operator=(multiset&& __s)
  1040. _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
  1041. {
  1042. __tree_ = _VSTD::move(__s.__tree_);
  1043. return *this;
  1044. }
  1045. #endif // _LIBCPP_CXX03_LANG
  1046. _LIBCPP_INLINE_VISIBILITY
  1047. ~multiset() {
  1048. static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
  1049. }
  1050. _LIBCPP_INLINE_VISIBILITY
  1051. iterator begin() _NOEXCEPT {return __tree_.begin();}
  1052. _LIBCPP_INLINE_VISIBILITY
  1053. const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
  1054. _LIBCPP_INLINE_VISIBILITY
  1055. iterator end() _NOEXCEPT {return __tree_.end();}
  1056. _LIBCPP_INLINE_VISIBILITY
  1057. const_iterator end() const _NOEXCEPT {return __tree_.end();}
  1058. _LIBCPP_INLINE_VISIBILITY
  1059. reverse_iterator rbegin() _NOEXCEPT
  1060. {return reverse_iterator(end());}
  1061. _LIBCPP_INLINE_VISIBILITY
  1062. const_reverse_iterator rbegin() const _NOEXCEPT
  1063. {return const_reverse_iterator(end());}
  1064. _LIBCPP_INLINE_VISIBILITY
  1065. reverse_iterator rend() _NOEXCEPT
  1066. {return reverse_iterator(begin());}
  1067. _LIBCPP_INLINE_VISIBILITY
  1068. const_reverse_iterator rend() const _NOEXCEPT
  1069. {return const_reverse_iterator(begin());}
  1070. _LIBCPP_INLINE_VISIBILITY
  1071. const_iterator cbegin() const _NOEXCEPT {return begin();}
  1072. _LIBCPP_INLINE_VISIBILITY
  1073. const_iterator cend() const _NOEXCEPT {return end();}
  1074. _LIBCPP_INLINE_VISIBILITY
  1075. const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
  1076. _LIBCPP_INLINE_VISIBILITY
  1077. const_reverse_iterator crend() const _NOEXCEPT {return rend();}
  1078. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  1079. bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
  1080. _LIBCPP_INLINE_VISIBILITY
  1081. size_type size() const _NOEXCEPT {return __tree_.size();}
  1082. _LIBCPP_INLINE_VISIBILITY
  1083. size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
  1084. // modifiers:
  1085. #ifndef _LIBCPP_CXX03_LANG
  1086. template <class... _Args>
  1087. _LIBCPP_INLINE_VISIBILITY
  1088. iterator emplace(_Args&&... __args)
  1089. {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
  1090. template <class... _Args>
  1091. _LIBCPP_INLINE_VISIBILITY
  1092. iterator emplace_hint(const_iterator __p, _Args&&... __args)
  1093. {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
  1094. #endif // _LIBCPP_CXX03_LANG
  1095. _LIBCPP_INLINE_VISIBILITY
  1096. iterator insert(const value_type& __v)
  1097. {return __tree_.__insert_multi(__v);}
  1098. _LIBCPP_INLINE_VISIBILITY
  1099. iterator insert(const_iterator __p, const value_type& __v)
  1100. {return __tree_.__insert_multi(__p, __v);}
  1101. template <class _InputIterator>
  1102. _LIBCPP_INLINE_VISIBILITY
  1103. void insert(_InputIterator __f, _InputIterator __l)
  1104. {
  1105. for (const_iterator __e = cend(); __f != __l; ++__f)
  1106. __tree_.__insert_multi(__e, *__f);
  1107. }
  1108. #ifndef _LIBCPP_CXX03_LANG
  1109. _LIBCPP_INLINE_VISIBILITY
  1110. iterator insert(value_type&& __v)
  1111. {return __tree_.__insert_multi(_VSTD::move(__v));}
  1112. _LIBCPP_INLINE_VISIBILITY
  1113. iterator insert(const_iterator __p, value_type&& __v)
  1114. {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
  1115. _LIBCPP_INLINE_VISIBILITY
  1116. void insert(initializer_list<value_type> __il)
  1117. {insert(__il.begin(), __il.end());}
  1118. #endif // _LIBCPP_CXX03_LANG
  1119. _LIBCPP_INLINE_VISIBILITY
  1120. iterator erase(const_iterator __p) {return __tree_.erase(__p);}
  1121. _LIBCPP_INLINE_VISIBILITY
  1122. size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
  1123. _LIBCPP_INLINE_VISIBILITY
  1124. iterator erase(const_iterator __f, const_iterator __l)
  1125. {return __tree_.erase(__f, __l);}
  1126. _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_INLINE_VISIBILITY
  1127. void clear() _NOEXCEPT {__tree_.clear();}
  1128. #if _LIBCPP_STD_VER > 14
  1129. _LIBCPP_INLINE_VISIBILITY
  1130. iterator insert(node_type&& __nh)
  1131. {
  1132. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1133. "node_type with incompatible allocator passed to multiset::insert()");
  1134. return __tree_.template __node_handle_insert_multi<node_type>(
  1135. _VSTD::move(__nh));
  1136. }
  1137. _LIBCPP_INLINE_VISIBILITY
  1138. iterator insert(const_iterator __hint, node_type&& __nh)
  1139. {
  1140. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1141. "node_type with incompatible allocator passed to multiset::insert()");
  1142. return __tree_.template __node_handle_insert_multi<node_type>(
  1143. __hint, _VSTD::move(__nh));
  1144. }
  1145. _LIBCPP_INLINE_VISIBILITY
  1146. node_type extract(key_type const& __key)
  1147. {
  1148. return __tree_.template __node_handle_extract<node_type>(__key);
  1149. }
  1150. _LIBCPP_INLINE_VISIBILITY
  1151. node_type extract(const_iterator __it)
  1152. {
  1153. return __tree_.template __node_handle_extract<node_type>(__it);
  1154. }
  1155. template <class _Compare2>
  1156. _LIBCPP_INLINE_VISIBILITY
  1157. void merge(multiset<key_type, _Compare2, allocator_type>& __source)
  1158. {
  1159. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1160. "merging container with incompatible allocator");
  1161. __tree_.__node_handle_merge_multi(__source.__tree_);
  1162. }
  1163. template <class _Compare2>
  1164. _LIBCPP_INLINE_VISIBILITY
  1165. void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
  1166. {
  1167. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1168. "merging container with incompatible allocator");
  1169. __tree_.__node_handle_merge_multi(__source.__tree_);
  1170. }
  1171. template <class _Compare2>
  1172. _LIBCPP_INLINE_VISIBILITY
  1173. void merge(set<key_type, _Compare2, allocator_type>& __source)
  1174. {
  1175. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1176. "merging container with incompatible allocator");
  1177. __tree_.__node_handle_merge_multi(__source.__tree_);
  1178. }
  1179. template <class _Compare2>
  1180. _LIBCPP_INLINE_VISIBILITY
  1181. void merge(set<key_type, _Compare2, allocator_type>&& __source)
  1182. {
  1183. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1184. "merging container with incompatible allocator");
  1185. __tree_.__node_handle_merge_multi(__source.__tree_);
  1186. }
  1187. #endif
  1188. _LIBCPP_INLINE_VISIBILITY
  1189. void swap(multiset& __s)
  1190. _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
  1191. {__tree_.swap(__s.__tree_);}
  1192. _LIBCPP_INLINE_VISIBILITY
  1193. allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
  1194. _LIBCPP_INLINE_VISIBILITY
  1195. key_compare key_comp() const {return __tree_.value_comp();}
  1196. _LIBCPP_INLINE_VISIBILITY
  1197. value_compare value_comp() const {return __tree_.value_comp();}
  1198. // set operations:
  1199. _LIBCPP_INLINE_VISIBILITY
  1200. iterator find(const key_type& __k) {return __tree_.find(__k);}
  1201. _LIBCPP_INLINE_VISIBILITY
  1202. const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
  1203. #if _LIBCPP_STD_VER > 11
  1204. template <typename _K2>
  1205. _LIBCPP_INLINE_VISIBILITY
  1206. typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
  1207. find(const _K2& __k) {return __tree_.find(__k);}
  1208. template <typename _K2>
  1209. _LIBCPP_INLINE_VISIBILITY
  1210. typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
  1211. find(const _K2& __k) const {return __tree_.find(__k);}
  1212. #endif
  1213. _LIBCPP_INLINE_VISIBILITY
  1214. size_type count(const key_type& __k) const
  1215. {return __tree_.__count_multi(__k);}
  1216. #if _LIBCPP_STD_VER > 11
  1217. template <typename _K2>
  1218. _LIBCPP_INLINE_VISIBILITY
  1219. typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
  1220. count(const _K2& __k) const {return __tree_.__count_multi(__k);}
  1221. #endif
  1222. #if _LIBCPP_STD_VER > 17
  1223. _LIBCPP_INLINE_VISIBILITY
  1224. bool contains(const key_type& __k) const {return find(__k) != end();}
  1225. template <typename _K2>
  1226. _LIBCPP_INLINE_VISIBILITY
  1227. typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
  1228. contains(const _K2& __k) const { return find(__k) != end(); }
  1229. #endif // _LIBCPP_STD_VER > 17
  1230. _LIBCPP_INLINE_VISIBILITY
  1231. iterator lower_bound(const key_type& __k)
  1232. {return __tree_.lower_bound(__k);}
  1233. _LIBCPP_INLINE_VISIBILITY
  1234. const_iterator lower_bound(const key_type& __k) const
  1235. {return __tree_.lower_bound(__k);}
  1236. #if _LIBCPP_STD_VER > 11
  1237. template <typename _K2>
  1238. _LIBCPP_INLINE_VISIBILITY
  1239. typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
  1240. lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
  1241. template <typename _K2>
  1242. _LIBCPP_INLINE_VISIBILITY
  1243. typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
  1244. lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
  1245. #endif
  1246. _LIBCPP_INLINE_VISIBILITY
  1247. iterator upper_bound(const key_type& __k)
  1248. {return __tree_.upper_bound(__k);}
  1249. _LIBCPP_INLINE_VISIBILITY
  1250. const_iterator upper_bound(const key_type& __k) const
  1251. {return __tree_.upper_bound(__k);}
  1252. #if _LIBCPP_STD_VER > 11
  1253. template <typename _K2>
  1254. _LIBCPP_INLINE_VISIBILITY
  1255. typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
  1256. upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
  1257. template <typename _K2>
  1258. _LIBCPP_INLINE_VISIBILITY
  1259. typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
  1260. upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
  1261. #endif
  1262. _LIBCPP_INLINE_VISIBILITY
  1263. pair<iterator,iterator> equal_range(const key_type& __k)
  1264. {return __tree_.__equal_range_multi(__k);}
  1265. _LIBCPP_INLINE_VISIBILITY
  1266. pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
  1267. {return __tree_.__equal_range_multi(__k);}
  1268. #if _LIBCPP_STD_VER > 11
  1269. template <typename _K2>
  1270. _LIBCPP_INLINE_VISIBILITY
  1271. typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
  1272. equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
  1273. template <typename _K2>
  1274. _LIBCPP_INLINE_VISIBILITY
  1275. typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
  1276. equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
  1277. #endif
  1278. };
  1279. #if _LIBCPP_STD_VER >= 17
  1280. template<class _InputIterator,
  1281. class _Compare = less<__iter_value_type<_InputIterator>>,
  1282. class _Allocator = allocator<__iter_value_type<_InputIterator>>,
  1283. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
  1284. class = enable_if_t<__is_allocator<_Allocator>::value, void>,
  1285. class = enable_if_t<!__is_allocator<_Compare>::value, void>>
  1286. multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
  1287. -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
  1288. template<class _Key, class _Compare = less<_Key>,
  1289. class _Allocator = allocator<_Key>,
  1290. class = enable_if_t<__is_allocator<_Allocator>::value, void>,
  1291. class = enable_if_t<!__is_allocator<_Compare>::value, void>>
  1292. multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
  1293. -> multiset<_Key, _Compare, _Allocator>;
  1294. template<class _InputIterator, class _Allocator,
  1295. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
  1296. class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  1297. multiset(_InputIterator, _InputIterator, _Allocator)
  1298. -> multiset<__iter_value_type<_InputIterator>,
  1299. less<__iter_value_type<_InputIterator>>, _Allocator>;
  1300. template<class _Key, class _Allocator,
  1301. class = enable_if_t<__is_allocator<_Allocator>::value, void>>
  1302. multiset(initializer_list<_Key>, _Allocator)
  1303. -> multiset<_Key, less<_Key>, _Allocator>;
  1304. #endif
  1305. #ifndef _LIBCPP_CXX03_LANG
  1306. template <class _Key, class _Compare, class _Allocator>
  1307. multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
  1308. : __tree_(_VSTD::move(__s.__tree_), __a)
  1309. {
  1310. if (__a != __s.get_allocator())
  1311. {
  1312. const_iterator __e = cend();
  1313. while (!__s.empty())
  1314. insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
  1315. }
  1316. }
  1317. #endif // _LIBCPP_CXX03_LANG
  1318. template <class _Key, class _Compare, class _Allocator>
  1319. inline _LIBCPP_INLINE_VISIBILITY
  1320. bool
  1321. operator==(const multiset<_Key, _Compare, _Allocator>& __x,
  1322. const multiset<_Key, _Compare, _Allocator>& __y)
  1323. {
  1324. return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
  1325. }
  1326. template <class _Key, class _Compare, class _Allocator>
  1327. inline _LIBCPP_INLINE_VISIBILITY
  1328. bool
  1329. operator< (const multiset<_Key, _Compare, _Allocator>& __x,
  1330. const multiset<_Key, _Compare, _Allocator>& __y)
  1331. {
  1332. return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
  1333. }
  1334. template <class _Key, class _Compare, class _Allocator>
  1335. inline _LIBCPP_INLINE_VISIBILITY
  1336. bool
  1337. operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
  1338. const multiset<_Key, _Compare, _Allocator>& __y)
  1339. {
  1340. return !(__x == __y);
  1341. }
  1342. template <class _Key, class _Compare, class _Allocator>
  1343. inline _LIBCPP_INLINE_VISIBILITY
  1344. bool
  1345. operator> (const multiset<_Key, _Compare, _Allocator>& __x,
  1346. const multiset<_Key, _Compare, _Allocator>& __y)
  1347. {
  1348. return __y < __x;
  1349. }
  1350. template <class _Key, class _Compare, class _Allocator>
  1351. inline _LIBCPP_INLINE_VISIBILITY
  1352. bool
  1353. operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
  1354. const multiset<_Key, _Compare, _Allocator>& __y)
  1355. {
  1356. return !(__x < __y);
  1357. }
  1358. template <class _Key, class _Compare, class _Allocator>
  1359. inline _LIBCPP_INLINE_VISIBILITY
  1360. bool
  1361. operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
  1362. const multiset<_Key, _Compare, _Allocator>& __y)
  1363. {
  1364. return !(__y < __x);
  1365. }
  1366. template <class _Key, class _Compare, class _Allocator>
  1367. inline _LIBCPP_INLINE_VISIBILITY
  1368. void
  1369. swap(multiset<_Key, _Compare, _Allocator>& __x,
  1370. multiset<_Key, _Compare, _Allocator>& __y)
  1371. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  1372. {
  1373. __x.swap(__y);
  1374. }
  1375. #if _LIBCPP_STD_VER > 17
  1376. template <class _Key, class _Compare, class _Allocator, class _Predicate>
  1377. inline _LIBCPP_INLINE_VISIBILITY
  1378. typename multiset<_Key, _Compare, _Allocator>::size_type
  1379. erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
  1380. return _VSTD::__libcpp_erase_if_container(__c, __pred);
  1381. }
  1382. #endif
  1383. _LIBCPP_END_NAMESPACE_STD
  1384. #endif // _LIBCPP_SET