set 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. // -*- C++ -*-
  2. //===---------------------------- set -------------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_SET
  11. #define _LIBCPP_SET
  12. /*
  13. set synopsis
  14. namespace std
  15. {
  16. template <class Key, class Compare = less<Key>,
  17. class Allocator = allocator<Key>>
  18. class set
  19. {
  20. public:
  21. // types:
  22. typedef Key key_type;
  23. typedef key_type value_type;
  24. typedef Compare key_compare;
  25. typedef key_compare value_compare;
  26. typedef Allocator allocator_type;
  27. typedef typename allocator_type::reference reference;
  28. typedef typename allocator_type::const_reference const_reference;
  29. typedef typename allocator_type::size_type size_type;
  30. typedef typename allocator_type::difference_type difference_type;
  31. typedef typename allocator_type::pointer pointer;
  32. typedef typename allocator_type::const_pointer const_pointer;
  33. typedef implementation-defined iterator;
  34. typedef implementation-defined const_iterator;
  35. typedef std::reverse_iterator<iterator> reverse_iterator;
  36. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  37. // construct/copy/destroy:
  38. set()
  39. noexcept(
  40. is_nothrow_default_constructible<allocator_type>::value &&
  41. is_nothrow_default_constructible<key_compare>::value &&
  42. is_nothrow_copy_constructible<key_compare>::value);
  43. explicit set(const value_compare& comp);
  44. set(const value_compare& comp, const allocator_type& a);
  45. template <class InputIterator>
  46. set(InputIterator first, InputIterator last,
  47. const value_compare& comp = value_compare());
  48. template <class InputIterator>
  49. set(InputIterator first, InputIterator last, const value_compare& comp,
  50. const allocator_type& a);
  51. set(const set& s);
  52. set(set&& s)
  53. noexcept(
  54. is_nothrow_move_constructible<allocator_type>::value &&
  55. is_nothrow_move_constructible<key_compare>::value);
  56. explicit set(const allocator_type& a);
  57. set(const set& s, const allocator_type& a);
  58. set(set&& s, const allocator_type& a);
  59. set(initializer_list<value_type> il, const value_compare& comp = value_compare());
  60. set(initializer_list<value_type> il, const value_compare& comp,
  61. const allocator_type& a);
  62. template <class InputIterator>
  63. set(InputIterator first, InputIterator last, const allocator_type& a)
  64. : set(first, last, Compare(), a) {} // C++14
  65. set(initializer_list<value_type> il, const allocator_type& a)
  66. : set(il, Compare(), a) {} // C++14
  67. ~set();
  68. set& operator=(const set& s);
  69. set& operator=(set&& s)
  70. noexcept(
  71. allocator_type::propagate_on_container_move_assignment::value &&
  72. is_nothrow_move_assignable<allocator_type>::value &&
  73. is_nothrow_move_assignable<key_compare>::value);
  74. set& operator=(initializer_list<value_type> il);
  75. // iterators:
  76. iterator begin() noexcept;
  77. const_iterator begin() const noexcept;
  78. iterator end() noexcept;
  79. const_iterator end() const noexcept;
  80. reverse_iterator rbegin() noexcept;
  81. const_reverse_iterator rbegin() const noexcept;
  82. reverse_iterator rend() noexcept;
  83. const_reverse_iterator rend() const noexcept;
  84. const_iterator cbegin() const noexcept;
  85. const_iterator cend() const noexcept;
  86. const_reverse_iterator crbegin() const noexcept;
  87. const_reverse_iterator crend() const noexcept;
  88. // capacity:
  89. bool empty() const noexcept;
  90. size_type size() const noexcept;
  91. size_type max_size() const noexcept;
  92. // modifiers:
  93. template <class... Args>
  94. pair<iterator, bool> emplace(Args&&... args);
  95. template <class... Args>
  96. iterator emplace_hint(const_iterator position, Args&&... args);
  97. pair<iterator,bool> insert(const value_type& v);
  98. pair<iterator,bool> insert(value_type&& v);
  99. iterator insert(const_iterator position, const value_type& v);
  100. iterator insert(const_iterator position, value_type&& v);
  101. template <class InputIterator>
  102. void insert(InputIterator first, InputIterator last);
  103. void insert(initializer_list<value_type> il);
  104. iterator erase(const_iterator position);
  105. iterator erase(iterator position); // C++14
  106. size_type erase(const key_type& k);
  107. iterator erase(const_iterator first, const_iterator last);
  108. void clear() noexcept;
  109. void swap(set& s)
  110. noexcept(
  111. __is_nothrow_swappable<key_compare>::value &&
  112. (!allocator_type::propagate_on_container_swap::value ||
  113. __is_nothrow_swappable<allocator_type>::value));
  114. // observers:
  115. allocator_type get_allocator() const noexcept;
  116. key_compare key_comp() const;
  117. value_compare value_comp() const;
  118. // set operations:
  119. iterator find(const key_type& k);
  120. const_iterator find(const key_type& k) const;
  121. template<typename K>
  122. iterator find(const K& x);
  123. template<typename K>
  124. const_iterator find(const K& x) const; // C++14
  125. template<typename K>
  126. size_type count(const K& x) const; // C++14
  127. size_type count(const key_type& k) const;
  128. iterator lower_bound(const key_type& k);
  129. const_iterator lower_bound(const key_type& k) const;
  130. template<typename K>
  131. iterator lower_bound(const K& x); // C++14
  132. template<typename K>
  133. const_iterator lower_bound(const K& x) const; // C++14
  134. iterator upper_bound(const key_type& k);
  135. const_iterator upper_bound(const key_type& k) const;
  136. template<typename K>
  137. iterator upper_bound(const K& x); // C++14
  138. template<typename K>
  139. const_iterator upper_bound(const K& x) const; // C++14
  140. pair<iterator,iterator> equal_range(const key_type& k);
  141. pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
  142. template<typename K>
  143. pair<iterator,iterator> equal_range(const K& x); // C++14
  144. template<typename K>
  145. pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
  146. };
  147. template <class Key, class Compare, class Allocator>
  148. bool
  149. operator==(const set<Key, Compare, Allocator>& x,
  150. const set<Key, Compare, Allocator>& y);
  151. template <class Key, class Compare, class Allocator>
  152. bool
  153. operator< (const set<Key, Compare, Allocator>& x,
  154. const set<Key, Compare, Allocator>& y);
  155. template <class Key, class Compare, class Allocator>
  156. bool
  157. operator!=(const set<Key, Compare, Allocator>& x,
  158. const set<Key, Compare, Allocator>& y);
  159. template <class Key, class Compare, class Allocator>
  160. bool
  161. operator> (const set<Key, Compare, Allocator>& x,
  162. const set<Key, Compare, Allocator>& y);
  163. template <class Key, class Compare, class Allocator>
  164. bool
  165. operator>=(const set<Key, Compare, Allocator>& x,
  166. const set<Key, Compare, Allocator>& y);
  167. template <class Key, class Compare, class Allocator>
  168. bool
  169. operator<=(const set<Key, Compare, Allocator>& x,
  170. const set<Key, Compare, Allocator>& y);
  171. // specialized algorithms:
  172. template <class Key, class Compare, class Allocator>
  173. void
  174. swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
  175. noexcept(noexcept(x.swap(y)));
  176. template <class Key, class Compare = less<Key>,
  177. class Allocator = allocator<Key>>
  178. class multiset
  179. {
  180. public:
  181. // types:
  182. typedef Key key_type;
  183. typedef key_type value_type;
  184. typedef Compare key_compare;
  185. typedef key_compare value_compare;
  186. typedef Allocator allocator_type;
  187. typedef typename allocator_type::reference reference;
  188. typedef typename allocator_type::const_reference const_reference;
  189. typedef typename allocator_type::size_type size_type;
  190. typedef typename allocator_type::difference_type difference_type;
  191. typedef typename allocator_type::pointer pointer;
  192. typedef typename allocator_type::const_pointer const_pointer;
  193. typedef implementation-defined iterator;
  194. typedef implementation-defined const_iterator;
  195. typedef std::reverse_iterator<iterator> reverse_iterator;
  196. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  197. // construct/copy/destroy:
  198. multiset()
  199. noexcept(
  200. is_nothrow_default_constructible<allocator_type>::value &&
  201. is_nothrow_default_constructible<key_compare>::value &&
  202. is_nothrow_copy_constructible<key_compare>::value);
  203. explicit multiset(const value_compare& comp);
  204. multiset(const value_compare& comp, const allocator_type& a);
  205. template <class InputIterator>
  206. multiset(InputIterator first, InputIterator last,
  207. const value_compare& comp = value_compare());
  208. template <class InputIterator>
  209. multiset(InputIterator first, InputIterator last,
  210. const value_compare& comp, const allocator_type& a);
  211. multiset(const multiset& s);
  212. multiset(multiset&& s)
  213. noexcept(
  214. is_nothrow_move_constructible<allocator_type>::value &&
  215. is_nothrow_move_constructible<key_compare>::value);
  216. explicit multiset(const allocator_type& a);
  217. multiset(const multiset& s, const allocator_type& a);
  218. multiset(multiset&& s, const allocator_type& a);
  219. multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
  220. multiset(initializer_list<value_type> il, const value_compare& comp,
  221. const allocator_type& a);
  222. template <class InputIterator>
  223. multiset(InputIterator first, InputIterator last, const allocator_type& a)
  224. : set(first, last, Compare(), a) {} // C++14
  225. multiset(initializer_list<value_type> il, const allocator_type& a)
  226. : set(il, Compare(), a) {} // C++14
  227. ~multiset();
  228. multiset& operator=(const multiset& s);
  229. multiset& operator=(multiset&& s)
  230. noexcept(
  231. allocator_type::propagate_on_container_move_assignment::value &&
  232. is_nothrow_move_assignable<allocator_type>::value &&
  233. is_nothrow_move_assignable<key_compare>::value);
  234. multiset& operator=(initializer_list<value_type> il);
  235. // iterators:
  236. iterator begin() noexcept;
  237. const_iterator begin() const noexcept;
  238. iterator end() noexcept;
  239. const_iterator end() const noexcept;
  240. reverse_iterator rbegin() noexcept;
  241. const_reverse_iterator rbegin() const noexcept;
  242. reverse_iterator rend() noexcept;
  243. const_reverse_iterator rend() const noexcept;
  244. const_iterator cbegin() const noexcept;
  245. const_iterator cend() const noexcept;
  246. const_reverse_iterator crbegin() const noexcept;
  247. const_reverse_iterator crend() const noexcept;
  248. // capacity:
  249. bool empty() const noexcept;
  250. size_type size() const noexcept;
  251. size_type max_size() const noexcept;
  252. // modifiers:
  253. template <class... Args>
  254. iterator emplace(Args&&... args);
  255. template <class... Args>
  256. iterator emplace_hint(const_iterator position, Args&&... args);
  257. iterator insert(const value_type& v);
  258. iterator insert(value_type&& v);
  259. iterator insert(const_iterator position, const value_type& v);
  260. iterator insert(const_iterator position, value_type&& v);
  261. template <class InputIterator>
  262. void insert(InputIterator first, InputIterator last);
  263. void insert(initializer_list<value_type> il);
  264. iterator erase(const_iterator position);
  265. iterator erase(iterator position); // C++14
  266. size_type erase(const key_type& k);
  267. iterator erase(const_iterator first, const_iterator last);
  268. void clear() noexcept;
  269. void swap(multiset& s)
  270. noexcept(
  271. __is_nothrow_swappable<key_compare>::value &&
  272. (!allocator_type::propagate_on_container_swap::value ||
  273. __is_nothrow_swappable<allocator_type>::value));
  274. // observers:
  275. allocator_type get_allocator() const noexcept;
  276. key_compare key_comp() const;
  277. value_compare value_comp() const;
  278. // set operations:
  279. iterator find(const key_type& k);
  280. const_iterator find(const key_type& k) const;
  281. template<typename K>
  282. iterator find(const K& x);
  283. template<typename K>
  284. const_iterator find(const K& x) const; // C++14
  285. size_type count(const key_type& k) const;
  286. iterator lower_bound(const key_type& k);
  287. const_iterator lower_bound(const key_type& k) const;
  288. template<typename K>
  289. iterator lower_bound(const K& x); // C++14
  290. template<typename K>
  291. const_iterator lower_bound(const K& x) const; // C++14
  292. iterator upper_bound(const key_type& k);
  293. const_iterator upper_bound(const key_type& k) const;
  294. template<typename K>
  295. iterator upper_bound(const K& x); // C++14
  296. template<typename K>
  297. const_iterator upper_bound(const K& x) const; // C++14
  298. pair<iterator,iterator> equal_range(const key_type& k);
  299. pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
  300. template<typename K>
  301. pair<iterator,iterator> equal_range(const K& x); // C++14
  302. template<typename K>
  303. pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
  304. };
  305. template <class Key, class Compare, class Allocator>
  306. bool
  307. operator==(const multiset<Key, Compare, Allocator>& x,
  308. const multiset<Key, Compare, Allocator>& y);
  309. template <class Key, class Compare, class Allocator>
  310. bool
  311. operator< (const multiset<Key, Compare, Allocator>& x,
  312. const multiset<Key, Compare, Allocator>& y);
  313. template <class Key, class Compare, class Allocator>
  314. bool
  315. operator!=(const multiset<Key, Compare, Allocator>& x,
  316. const multiset<Key, Compare, Allocator>& y);
  317. template <class Key, class Compare, class Allocator>
  318. bool
  319. operator> (const multiset<Key, Compare, Allocator>& x,
  320. const multiset<Key, Compare, Allocator>& y);
  321. template <class Key, class Compare, class Allocator>
  322. bool
  323. operator>=(const multiset<Key, Compare, Allocator>& x,
  324. const multiset<Key, Compare, Allocator>& y);
  325. template <class Key, class Compare, class Allocator>
  326. bool
  327. operator<=(const multiset<Key, Compare, Allocator>& x,
  328. const multiset<Key, Compare, Allocator>& y);
  329. // specialized algorithms:
  330. template <class Key, class Compare, class Allocator>
  331. void
  332. swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
  333. noexcept(noexcept(x.swap(y)));
  334. } // std
  335. */
  336. #include <__config>
  337. #include <__tree>
  338. #include <functional>
  339. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  340. #pragma GCC system_header
  341. #endif
  342. _LIBCPP_BEGIN_NAMESPACE_STD
  343. template <class _Key, class _Compare = less<_Key>,
  344. class _Allocator = allocator<_Key> >
  345. class _LIBCPP_TYPE_VIS_ONLY set
  346. {
  347. public:
  348. // types:
  349. typedef _Key key_type;
  350. typedef key_type value_type;
  351. typedef _Compare key_compare;
  352. typedef key_compare value_compare;
  353. typedef _Allocator allocator_type;
  354. typedef value_type& reference;
  355. typedef const value_type& const_reference;
  356. static_assert((is_same<typename allocator_type::value_type, value_type>::value),
  357. "Allocator::value_type must be same type as value_type");
  358. private:
  359. typedef __tree<value_type, value_compare, allocator_type> __base;
  360. typedef allocator_traits<allocator_type> __alloc_traits;
  361. typedef typename __base::__node_holder __node_holder;
  362. __base __tree_;
  363. public:
  364. typedef typename __base::pointer pointer;
  365. typedef typename __base::const_pointer const_pointer;
  366. typedef typename __base::size_type size_type;
  367. typedef typename __base::difference_type difference_type;
  368. typedef typename __base::const_iterator iterator;
  369. typedef typename __base::const_iterator const_iterator;
  370. typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
  371. typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
  372. _LIBCPP_INLINE_VISIBILITY
  373. set()
  374. _NOEXCEPT_(
  375. is_nothrow_default_constructible<allocator_type>::value &&
  376. is_nothrow_default_constructible<key_compare>::value &&
  377. is_nothrow_copy_constructible<key_compare>::value)
  378. : __tree_(value_compare()) {}
  379. _LIBCPP_INLINE_VISIBILITY
  380. explicit set(const value_compare& __comp)
  381. _NOEXCEPT_(
  382. is_nothrow_default_constructible<allocator_type>::value &&
  383. is_nothrow_copy_constructible<key_compare>::value)
  384. : __tree_(__comp) {}
  385. _LIBCPP_INLINE_VISIBILITY
  386. explicit set(const value_compare& __comp, const allocator_type& __a)
  387. : __tree_(__comp, __a) {}
  388. template <class _InputIterator>
  389. _LIBCPP_INLINE_VISIBILITY
  390. set(_InputIterator __f, _InputIterator __l,
  391. const value_compare& __comp = value_compare())
  392. : __tree_(__comp)
  393. {
  394. insert(__f, __l);
  395. }
  396. template <class _InputIterator>
  397. _LIBCPP_INLINE_VISIBILITY
  398. set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
  399. const allocator_type& __a)
  400. : __tree_(__comp, __a)
  401. {
  402. insert(__f, __l);
  403. }
  404. #if _LIBCPP_STD_VER > 11
  405. template <class _InputIterator>
  406. _LIBCPP_INLINE_VISIBILITY
  407. set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
  408. : set(__f, __l, key_compare(), __a) {}
  409. #endif
  410. _LIBCPP_INLINE_VISIBILITY
  411. set(const set& __s)
  412. : __tree_(__s.__tree_)
  413. {
  414. insert(__s.begin(), __s.end());
  415. }
  416. _LIBCPP_INLINE_VISIBILITY
  417. set& operator=(const set& __s)
  418. {
  419. __tree_ = __s.__tree_;
  420. return *this;
  421. }
  422. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  423. _LIBCPP_INLINE_VISIBILITY
  424. set(set&& __s)
  425. _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
  426. : __tree_(_VSTD::move(__s.__tree_)) {}
  427. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  428. _LIBCPP_INLINE_VISIBILITY
  429. explicit set(const allocator_type& __a)
  430. : __tree_(__a) {}
  431. _LIBCPP_INLINE_VISIBILITY
  432. set(const set& __s, const allocator_type& __a)
  433. : __tree_(__s.__tree_.value_comp(), __a)
  434. {
  435. insert(__s.begin(), __s.end());
  436. }
  437. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  438. set(set&& __s, const allocator_type& __a);
  439. #endif
  440. #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  441. _LIBCPP_INLINE_VISIBILITY
  442. set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
  443. : __tree_(__comp)
  444. {
  445. insert(__il.begin(), __il.end());
  446. }
  447. _LIBCPP_INLINE_VISIBILITY
  448. set(initializer_list<value_type> __il, const value_compare& __comp,
  449. const allocator_type& __a)
  450. : __tree_(__comp, __a)
  451. {
  452. insert(__il.begin(), __il.end());
  453. }
  454. #if _LIBCPP_STD_VER > 11
  455. _LIBCPP_INLINE_VISIBILITY
  456. set(initializer_list<value_type> __il, const allocator_type& __a)
  457. : set(__il, key_compare(), __a) {}
  458. #endif
  459. _LIBCPP_INLINE_VISIBILITY
  460. set& operator=(initializer_list<value_type> __il)
  461. {
  462. __tree_.__assign_unique(__il.begin(), __il.end());
  463. return *this;
  464. }
  465. #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  466. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  467. _LIBCPP_INLINE_VISIBILITY
  468. set& operator=(set&& __s)
  469. _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
  470. {
  471. __tree_ = _VSTD::move(__s.__tree_);
  472. return *this;
  473. }
  474. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  475. _LIBCPP_INLINE_VISIBILITY
  476. iterator begin() _NOEXCEPT {return __tree_.begin();}
  477. _LIBCPP_INLINE_VISIBILITY
  478. const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
  479. _LIBCPP_INLINE_VISIBILITY
  480. iterator end() _NOEXCEPT {return __tree_.end();}
  481. _LIBCPP_INLINE_VISIBILITY
  482. const_iterator end() const _NOEXCEPT {return __tree_.end();}
  483. _LIBCPP_INLINE_VISIBILITY
  484. reverse_iterator rbegin() _NOEXCEPT
  485. {return reverse_iterator(end());}
  486. _LIBCPP_INLINE_VISIBILITY
  487. const_reverse_iterator rbegin() const _NOEXCEPT
  488. {return const_reverse_iterator(end());}
  489. _LIBCPP_INLINE_VISIBILITY
  490. reverse_iterator rend() _NOEXCEPT
  491. {return reverse_iterator(begin());}
  492. _LIBCPP_INLINE_VISIBILITY
  493. const_reverse_iterator rend() const _NOEXCEPT
  494. {return const_reverse_iterator(begin());}
  495. _LIBCPP_INLINE_VISIBILITY
  496. const_iterator cbegin() const _NOEXCEPT {return begin();}
  497. _LIBCPP_INLINE_VISIBILITY
  498. const_iterator cend() const _NOEXCEPT {return end();}
  499. _LIBCPP_INLINE_VISIBILITY
  500. const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
  501. _LIBCPP_INLINE_VISIBILITY
  502. const_reverse_iterator crend() const _NOEXCEPT {return rend();}
  503. _LIBCPP_INLINE_VISIBILITY
  504. bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
  505. _LIBCPP_INLINE_VISIBILITY
  506. size_type size() const _NOEXCEPT {return __tree_.size();}
  507. _LIBCPP_INLINE_VISIBILITY
  508. size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
  509. // modifiers:
  510. #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  511. template <class... _Args>
  512. _LIBCPP_INLINE_VISIBILITY
  513. pair<iterator, bool> emplace(_Args&&... __args)
  514. {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
  515. template <class... _Args>
  516. _LIBCPP_INLINE_VISIBILITY
  517. iterator emplace_hint(const_iterator __p, _Args&&... __args)
  518. {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
  519. #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  520. _LIBCPP_INLINE_VISIBILITY
  521. pair<iterator,bool> insert(const value_type& __v)
  522. {return __tree_.__insert_unique(__v);}
  523. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  524. _LIBCPP_INLINE_VISIBILITY
  525. pair<iterator,bool> insert(value_type&& __v)
  526. {return __tree_.__insert_unique(_VSTD::move(__v));}
  527. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  528. _LIBCPP_INLINE_VISIBILITY
  529. iterator insert(const_iterator __p, const value_type& __v)
  530. {return __tree_.__insert_unique(__p, __v);}
  531. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  532. _LIBCPP_INLINE_VISIBILITY
  533. iterator insert(const_iterator __p, value_type&& __v)
  534. {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
  535. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  536. template <class _InputIterator>
  537. _LIBCPP_INLINE_VISIBILITY
  538. void insert(_InputIterator __f, _InputIterator __l)
  539. {
  540. for (const_iterator __e = cend(); __f != __l; ++__f)
  541. __tree_.__insert_unique(__e, *__f);
  542. }
  543. #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  544. _LIBCPP_INLINE_VISIBILITY
  545. void insert(initializer_list<value_type> __il)
  546. {insert(__il.begin(), __il.end());}
  547. #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  548. _LIBCPP_INLINE_VISIBILITY
  549. iterator erase(const_iterator __p) {return __tree_.erase(__p);}
  550. _LIBCPP_INLINE_VISIBILITY
  551. size_type erase(const key_type& __k)
  552. {return __tree_.__erase_unique(__k);}
  553. _LIBCPP_INLINE_VISIBILITY
  554. iterator erase(const_iterator __f, const_iterator __l)
  555. {return __tree_.erase(__f, __l);}
  556. _LIBCPP_INLINE_VISIBILITY
  557. void clear() _NOEXCEPT {__tree_.clear();}
  558. _LIBCPP_INLINE_VISIBILITY
  559. void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
  560. {__tree_.swap(__s.__tree_);}
  561. _LIBCPP_INLINE_VISIBILITY
  562. allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
  563. _LIBCPP_INLINE_VISIBILITY
  564. key_compare key_comp() const {return __tree_.value_comp();}
  565. _LIBCPP_INLINE_VISIBILITY
  566. value_compare value_comp() const {return __tree_.value_comp();}
  567. // set operations:
  568. _LIBCPP_INLINE_VISIBILITY
  569. iterator find(const key_type& __k) {return __tree_.find(__k);}
  570. _LIBCPP_INLINE_VISIBILITY
  571. const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
  572. #if _LIBCPP_STD_VER > 11
  573. template <typename _K2>
  574. _LIBCPP_INLINE_VISIBILITY
  575. typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
  576. find(const _K2& __k) {return __tree_.find(__k);}
  577. template <typename _K2>
  578. _LIBCPP_INLINE_VISIBILITY
  579. typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
  580. find(const _K2& __k) const {return __tree_.find(__k);}
  581. #endif
  582. _LIBCPP_INLINE_VISIBILITY
  583. size_type count(const key_type& __k) const
  584. {return __tree_.__count_unique(__k);}
  585. #if _LIBCPP_STD_VER > 11
  586. template <typename _K2>
  587. _LIBCPP_INLINE_VISIBILITY
  588. typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
  589. count(const _K2& __k) {return __tree_.__count_unique(__k);}
  590. #endif
  591. _LIBCPP_INLINE_VISIBILITY
  592. iterator lower_bound(const key_type& __k)
  593. {return __tree_.lower_bound(__k);}
  594. _LIBCPP_INLINE_VISIBILITY
  595. const_iterator lower_bound(const key_type& __k) const
  596. {return __tree_.lower_bound(__k);}
  597. #if _LIBCPP_STD_VER > 11
  598. template <typename _K2>
  599. _LIBCPP_INLINE_VISIBILITY
  600. typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
  601. lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
  602. template <typename _K2>
  603. _LIBCPP_INLINE_VISIBILITY
  604. typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
  605. lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
  606. #endif
  607. _LIBCPP_INLINE_VISIBILITY
  608. iterator upper_bound(const key_type& __k)
  609. {return __tree_.upper_bound(__k);}
  610. _LIBCPP_INLINE_VISIBILITY
  611. const_iterator upper_bound(const key_type& __k) const
  612. {return __tree_.upper_bound(__k);}
  613. #if _LIBCPP_STD_VER > 11
  614. template <typename _K2>
  615. _LIBCPP_INLINE_VISIBILITY
  616. typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
  617. upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
  618. template <typename _K2>
  619. _LIBCPP_INLINE_VISIBILITY
  620. typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
  621. upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
  622. #endif
  623. _LIBCPP_INLINE_VISIBILITY
  624. pair<iterator,iterator> equal_range(const key_type& __k)
  625. {return __tree_.__equal_range_unique(__k);}
  626. _LIBCPP_INLINE_VISIBILITY
  627. pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
  628. {return __tree_.__equal_range_unique(__k);}
  629. #if _LIBCPP_STD_VER > 11
  630. template <typename _K2>
  631. _LIBCPP_INLINE_VISIBILITY
  632. typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
  633. equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
  634. template <typename _K2>
  635. _LIBCPP_INLINE_VISIBILITY
  636. typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
  637. equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
  638. #endif
  639. };
  640. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  641. template <class _Key, class _Compare, class _Allocator>
  642. set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
  643. : __tree_(_VSTD::move(__s.__tree_), __a)
  644. {
  645. if (__a != __s.get_allocator())
  646. {
  647. const_iterator __e = cend();
  648. while (!__s.empty())
  649. insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
  650. }
  651. }
  652. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  653. template <class _Key, class _Compare, class _Allocator>
  654. inline _LIBCPP_INLINE_VISIBILITY
  655. bool
  656. operator==(const set<_Key, _Compare, _Allocator>& __x,
  657. const set<_Key, _Compare, _Allocator>& __y)
  658. {
  659. return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
  660. }
  661. template <class _Key, class _Compare, class _Allocator>
  662. inline _LIBCPP_INLINE_VISIBILITY
  663. bool
  664. operator< (const set<_Key, _Compare, _Allocator>& __x,
  665. const set<_Key, _Compare, _Allocator>& __y)
  666. {
  667. return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
  668. }
  669. template <class _Key, class _Compare, class _Allocator>
  670. inline _LIBCPP_INLINE_VISIBILITY
  671. bool
  672. operator!=(const set<_Key, _Compare, _Allocator>& __x,
  673. const set<_Key, _Compare, _Allocator>& __y)
  674. {
  675. return !(__x == __y);
  676. }
  677. template <class _Key, class _Compare, class _Allocator>
  678. inline _LIBCPP_INLINE_VISIBILITY
  679. bool
  680. operator> (const set<_Key, _Compare, _Allocator>& __x,
  681. const set<_Key, _Compare, _Allocator>& __y)
  682. {
  683. return __y < __x;
  684. }
  685. template <class _Key, class _Compare, class _Allocator>
  686. inline _LIBCPP_INLINE_VISIBILITY
  687. bool
  688. operator>=(const set<_Key, _Compare, _Allocator>& __x,
  689. const set<_Key, _Compare, _Allocator>& __y)
  690. {
  691. return !(__x < __y);
  692. }
  693. template <class _Key, class _Compare, class _Allocator>
  694. inline _LIBCPP_INLINE_VISIBILITY
  695. bool
  696. operator<=(const set<_Key, _Compare, _Allocator>& __x,
  697. const set<_Key, _Compare, _Allocator>& __y)
  698. {
  699. return !(__y < __x);
  700. }
  701. // specialized algorithms:
  702. template <class _Key, class _Compare, class _Allocator>
  703. inline _LIBCPP_INLINE_VISIBILITY
  704. void
  705. swap(set<_Key, _Compare, _Allocator>& __x,
  706. set<_Key, _Compare, _Allocator>& __y)
  707. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  708. {
  709. __x.swap(__y);
  710. }
  711. template <class _Key, class _Compare = less<_Key>,
  712. class _Allocator = allocator<_Key> >
  713. class _LIBCPP_TYPE_VIS_ONLY multiset
  714. {
  715. public:
  716. // types:
  717. typedef _Key key_type;
  718. typedef key_type value_type;
  719. typedef _Compare key_compare;
  720. typedef key_compare value_compare;
  721. typedef _Allocator allocator_type;
  722. typedef value_type& reference;
  723. typedef const value_type& const_reference;
  724. static_assert((is_same<typename allocator_type::value_type, value_type>::value),
  725. "Allocator::value_type must be same type as value_type");
  726. private:
  727. typedef __tree<value_type, value_compare, allocator_type> __base;
  728. typedef allocator_traits<allocator_type> __alloc_traits;
  729. typedef typename __base::__node_holder __node_holder;
  730. __base __tree_;
  731. public:
  732. typedef typename __base::pointer pointer;
  733. typedef typename __base::const_pointer const_pointer;
  734. typedef typename __base::size_type size_type;
  735. typedef typename __base::difference_type difference_type;
  736. typedef typename __base::const_iterator iterator;
  737. typedef typename __base::const_iterator const_iterator;
  738. typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
  739. typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
  740. // construct/copy/destroy:
  741. _LIBCPP_INLINE_VISIBILITY
  742. multiset()
  743. _NOEXCEPT_(
  744. is_nothrow_default_constructible<allocator_type>::value &&
  745. is_nothrow_default_constructible<key_compare>::value &&
  746. is_nothrow_copy_constructible<key_compare>::value)
  747. : __tree_(value_compare()) {}
  748. _LIBCPP_INLINE_VISIBILITY
  749. explicit multiset(const value_compare& __comp)
  750. _NOEXCEPT_(
  751. is_nothrow_default_constructible<allocator_type>::value &&
  752. is_nothrow_copy_constructible<key_compare>::value)
  753. : __tree_(__comp) {}
  754. _LIBCPP_INLINE_VISIBILITY
  755. explicit multiset(const value_compare& __comp, const allocator_type& __a)
  756. : __tree_(__comp, __a) {}
  757. template <class _InputIterator>
  758. _LIBCPP_INLINE_VISIBILITY
  759. multiset(_InputIterator __f, _InputIterator __l,
  760. const value_compare& __comp = value_compare())
  761. : __tree_(__comp)
  762. {
  763. insert(__f, __l);
  764. }
  765. #if _LIBCPP_STD_VER > 11
  766. template <class _InputIterator>
  767. _LIBCPP_INLINE_VISIBILITY
  768. multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
  769. : multiset(__f, __l, key_compare(), __a) {}
  770. #endif
  771. template <class _InputIterator>
  772. _LIBCPP_INLINE_VISIBILITY
  773. multiset(_InputIterator __f, _InputIterator __l,
  774. const value_compare& __comp, const allocator_type& __a)
  775. : __tree_(__comp, __a)
  776. {
  777. insert(__f, __l);
  778. }
  779. _LIBCPP_INLINE_VISIBILITY
  780. multiset(const multiset& __s)
  781. : __tree_(__s.__tree_.value_comp(),
  782. __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
  783. {
  784. insert(__s.begin(), __s.end());
  785. }
  786. _LIBCPP_INLINE_VISIBILITY
  787. multiset& operator=(const multiset& __s)
  788. {
  789. __tree_ = __s.__tree_;
  790. return *this;
  791. }
  792. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  793. _LIBCPP_INLINE_VISIBILITY
  794. multiset(multiset&& __s)
  795. _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
  796. : __tree_(_VSTD::move(__s.__tree_)) {}
  797. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  798. _LIBCPP_INLINE_VISIBILITY
  799. explicit multiset(const allocator_type& __a)
  800. : __tree_(__a) {}
  801. _LIBCPP_INLINE_VISIBILITY
  802. multiset(const multiset& __s, const allocator_type& __a)
  803. : __tree_(__s.__tree_.value_comp(), __a)
  804. {
  805. insert(__s.begin(), __s.end());
  806. }
  807. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  808. multiset(multiset&& __s, const allocator_type& __a);
  809. #endif
  810. #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  811. _LIBCPP_INLINE_VISIBILITY
  812. multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
  813. : __tree_(__comp)
  814. {
  815. insert(__il.begin(), __il.end());
  816. }
  817. _LIBCPP_INLINE_VISIBILITY
  818. multiset(initializer_list<value_type> __il, const value_compare& __comp,
  819. const allocator_type& __a)
  820. : __tree_(__comp, __a)
  821. {
  822. insert(__il.begin(), __il.end());
  823. }
  824. #if _LIBCPP_STD_VER > 11
  825. _LIBCPP_INLINE_VISIBILITY
  826. multiset(initializer_list<value_type> __il, const allocator_type& __a)
  827. : multiset(__il, key_compare(), __a) {}
  828. #endif
  829. _LIBCPP_INLINE_VISIBILITY
  830. multiset& operator=(initializer_list<value_type> __il)
  831. {
  832. __tree_.__assign_multi(__il.begin(), __il.end());
  833. return *this;
  834. }
  835. #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  836. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  837. _LIBCPP_INLINE_VISIBILITY
  838. multiset& operator=(multiset&& __s)
  839. _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
  840. {
  841. __tree_ = _VSTD::move(__s.__tree_);
  842. return *this;
  843. }
  844. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  845. _LIBCPP_INLINE_VISIBILITY
  846. iterator begin() _NOEXCEPT {return __tree_.begin();}
  847. _LIBCPP_INLINE_VISIBILITY
  848. const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
  849. _LIBCPP_INLINE_VISIBILITY
  850. iterator end() _NOEXCEPT {return __tree_.end();}
  851. _LIBCPP_INLINE_VISIBILITY
  852. const_iterator end() const _NOEXCEPT {return __tree_.end();}
  853. _LIBCPP_INLINE_VISIBILITY
  854. reverse_iterator rbegin() _NOEXCEPT
  855. {return reverse_iterator(end());}
  856. _LIBCPP_INLINE_VISIBILITY
  857. const_reverse_iterator rbegin() const _NOEXCEPT
  858. {return const_reverse_iterator(end());}
  859. _LIBCPP_INLINE_VISIBILITY
  860. reverse_iterator rend() _NOEXCEPT
  861. {return reverse_iterator(begin());}
  862. _LIBCPP_INLINE_VISIBILITY
  863. const_reverse_iterator rend() const _NOEXCEPT
  864. {return const_reverse_iterator(begin());}
  865. _LIBCPP_INLINE_VISIBILITY
  866. const_iterator cbegin() const _NOEXCEPT {return begin();}
  867. _LIBCPP_INLINE_VISIBILITY
  868. const_iterator cend() const _NOEXCEPT {return end();}
  869. _LIBCPP_INLINE_VISIBILITY
  870. const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
  871. _LIBCPP_INLINE_VISIBILITY
  872. const_reverse_iterator crend() const _NOEXCEPT {return rend();}
  873. _LIBCPP_INLINE_VISIBILITY
  874. bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
  875. _LIBCPP_INLINE_VISIBILITY
  876. size_type size() const _NOEXCEPT {return __tree_.size();}
  877. _LIBCPP_INLINE_VISIBILITY
  878. size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
  879. // modifiers:
  880. #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  881. template <class... _Args>
  882. _LIBCPP_INLINE_VISIBILITY
  883. iterator emplace(_Args&&... __args)
  884. {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
  885. template <class... _Args>
  886. _LIBCPP_INLINE_VISIBILITY
  887. iterator emplace_hint(const_iterator __p, _Args&&... __args)
  888. {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
  889. #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  890. _LIBCPP_INLINE_VISIBILITY
  891. iterator insert(const value_type& __v)
  892. {return __tree_.__insert_multi(__v);}
  893. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  894. _LIBCPP_INLINE_VISIBILITY
  895. iterator insert(value_type&& __v)
  896. {return __tree_.__insert_multi(_VSTD::move(__v));}
  897. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  898. _LIBCPP_INLINE_VISIBILITY
  899. iterator insert(const_iterator __p, const value_type& __v)
  900. {return __tree_.__insert_multi(__p, __v);}
  901. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  902. _LIBCPP_INLINE_VISIBILITY
  903. iterator insert(const_iterator __p, value_type&& __v)
  904. {return __tree_.__insert_multi(_VSTD::move(__v));}
  905. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  906. template <class _InputIterator>
  907. _LIBCPP_INLINE_VISIBILITY
  908. void insert(_InputIterator __f, _InputIterator __l)
  909. {
  910. for (const_iterator __e = cend(); __f != __l; ++__f)
  911. __tree_.__insert_multi(__e, *__f);
  912. }
  913. #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  914. _LIBCPP_INLINE_VISIBILITY
  915. void insert(initializer_list<value_type> __il)
  916. {insert(__il.begin(), __il.end());}
  917. #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  918. _LIBCPP_INLINE_VISIBILITY
  919. iterator erase(const_iterator __p) {return __tree_.erase(__p);}
  920. _LIBCPP_INLINE_VISIBILITY
  921. size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
  922. _LIBCPP_INLINE_VISIBILITY
  923. iterator erase(const_iterator __f, const_iterator __l)
  924. {return __tree_.erase(__f, __l);}
  925. _LIBCPP_INLINE_VISIBILITY
  926. void clear() _NOEXCEPT {__tree_.clear();}
  927. _LIBCPP_INLINE_VISIBILITY
  928. void swap(multiset& __s)
  929. _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
  930. {__tree_.swap(__s.__tree_);}
  931. _LIBCPP_INLINE_VISIBILITY
  932. allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
  933. _LIBCPP_INLINE_VISIBILITY
  934. key_compare key_comp() const {return __tree_.value_comp();}
  935. _LIBCPP_INLINE_VISIBILITY
  936. value_compare value_comp() const {return __tree_.value_comp();}
  937. // set operations:
  938. _LIBCPP_INLINE_VISIBILITY
  939. iterator find(const key_type& __k) {return __tree_.find(__k);}
  940. _LIBCPP_INLINE_VISIBILITY
  941. const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
  942. #if _LIBCPP_STD_VER > 11
  943. template <typename _K2>
  944. _LIBCPP_INLINE_VISIBILITY
  945. typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
  946. find(const _K2& __k) {return __tree_.find(__k);}
  947. template <typename _K2>
  948. _LIBCPP_INLINE_VISIBILITY
  949. typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
  950. find(const _K2& __k) const {return __tree_.find(__k);}
  951. #endif
  952. _LIBCPP_INLINE_VISIBILITY
  953. size_type count(const key_type& __k) const
  954. {return __tree_.__count_multi(__k);}
  955. #if _LIBCPP_STD_VER > 11
  956. template <typename _K2>
  957. _LIBCPP_INLINE_VISIBILITY
  958. typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
  959. count(const _K2& __k) {return __tree_.__count_multi(__k);}
  960. #endif
  961. _LIBCPP_INLINE_VISIBILITY
  962. iterator lower_bound(const key_type& __k)
  963. {return __tree_.lower_bound(__k);}
  964. _LIBCPP_INLINE_VISIBILITY
  965. const_iterator lower_bound(const key_type& __k) const
  966. {return __tree_.lower_bound(__k);}
  967. #if _LIBCPP_STD_VER > 11
  968. template <typename _K2>
  969. _LIBCPP_INLINE_VISIBILITY
  970. typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
  971. lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
  972. template <typename _K2>
  973. _LIBCPP_INLINE_VISIBILITY
  974. typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
  975. lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
  976. #endif
  977. _LIBCPP_INLINE_VISIBILITY
  978. iterator upper_bound(const key_type& __k)
  979. {return __tree_.upper_bound(__k);}
  980. _LIBCPP_INLINE_VISIBILITY
  981. const_iterator upper_bound(const key_type& __k) const
  982. {return __tree_.upper_bound(__k);}
  983. #if _LIBCPP_STD_VER > 11
  984. template <typename _K2>
  985. _LIBCPP_INLINE_VISIBILITY
  986. typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
  987. upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
  988. template <typename _K2>
  989. _LIBCPP_INLINE_VISIBILITY
  990. typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
  991. upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
  992. #endif
  993. _LIBCPP_INLINE_VISIBILITY
  994. pair<iterator,iterator> equal_range(const key_type& __k)
  995. {return __tree_.__equal_range_multi(__k);}
  996. _LIBCPP_INLINE_VISIBILITY
  997. pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
  998. {return __tree_.__equal_range_multi(__k);}
  999. #if _LIBCPP_STD_VER > 11
  1000. template <typename _K2>
  1001. _LIBCPP_INLINE_VISIBILITY
  1002. typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
  1003. equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
  1004. template <typename _K2>
  1005. _LIBCPP_INLINE_VISIBILITY
  1006. typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
  1007. equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
  1008. #endif
  1009. };
  1010. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  1011. template <class _Key, class _Compare, class _Allocator>
  1012. multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
  1013. : __tree_(_VSTD::move(__s.__tree_), __a)
  1014. {
  1015. if (__a != __s.get_allocator())
  1016. {
  1017. const_iterator __e = cend();
  1018. while (!__s.empty())
  1019. insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
  1020. }
  1021. }
  1022. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  1023. template <class _Key, class _Compare, class _Allocator>
  1024. inline _LIBCPP_INLINE_VISIBILITY
  1025. bool
  1026. operator==(const multiset<_Key, _Compare, _Allocator>& __x,
  1027. const multiset<_Key, _Compare, _Allocator>& __y)
  1028. {
  1029. return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
  1030. }
  1031. template <class _Key, class _Compare, class _Allocator>
  1032. inline _LIBCPP_INLINE_VISIBILITY
  1033. bool
  1034. operator< (const multiset<_Key, _Compare, _Allocator>& __x,
  1035. const multiset<_Key, _Compare, _Allocator>& __y)
  1036. {
  1037. return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
  1038. }
  1039. template <class _Key, class _Compare, class _Allocator>
  1040. inline _LIBCPP_INLINE_VISIBILITY
  1041. bool
  1042. operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
  1043. const multiset<_Key, _Compare, _Allocator>& __y)
  1044. {
  1045. return !(__x == __y);
  1046. }
  1047. template <class _Key, class _Compare, class _Allocator>
  1048. inline _LIBCPP_INLINE_VISIBILITY
  1049. bool
  1050. operator> (const multiset<_Key, _Compare, _Allocator>& __x,
  1051. const multiset<_Key, _Compare, _Allocator>& __y)
  1052. {
  1053. return __y < __x;
  1054. }
  1055. template <class _Key, class _Compare, class _Allocator>
  1056. inline _LIBCPP_INLINE_VISIBILITY
  1057. bool
  1058. operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
  1059. const multiset<_Key, _Compare, _Allocator>& __y)
  1060. {
  1061. return !(__x < __y);
  1062. }
  1063. template <class _Key, class _Compare, class _Allocator>
  1064. inline _LIBCPP_INLINE_VISIBILITY
  1065. bool
  1066. operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
  1067. const multiset<_Key, _Compare, _Allocator>& __y)
  1068. {
  1069. return !(__y < __x);
  1070. }
  1071. template <class _Key, class _Compare, class _Allocator>
  1072. inline _LIBCPP_INLINE_VISIBILITY
  1073. void
  1074. swap(multiset<_Key, _Compare, _Allocator>& __x,
  1075. multiset<_Key, _Compare, _Allocator>& __y)
  1076. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  1077. {
  1078. __x.swap(__y);
  1079. }
  1080. _LIBCPP_END_NAMESPACE_STD
  1081. #endif // _LIBCPP_SET