set.hpp 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_SET_HPP
  11. #define BOOST_CONTAINER_SET_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #include <boost/container/detail/config_begin.hpp>
  19. #include <boost/container/detail/workaround.hpp>
  20. // container
  21. #include <boost/container/container_fwd.hpp>
  22. // container/detail
  23. #include <boost/container/detail/mpl.hpp>
  24. #include <boost/container/detail/tree.hpp>
  25. #include <boost/container/new_allocator.hpp> //new_allocator
  26. // intrusive/detail
  27. #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
  28. #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal
  29. // move
  30. #include <boost/move/traits.hpp>
  31. #include <boost/move/utility_core.hpp>
  32. // move/detail
  33. #include <boost/move/detail/move_helpers.hpp>
  34. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  35. #include <boost/move/detail/fwd_macros.hpp>
  36. #endif
  37. // std
  38. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  39. #include <initializer_list>
  40. #endif
  41. namespace boost {
  42. namespace container {
  43. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  44. //! A set is a kind of associative container that supports unique keys (contains at
  45. //! most one of each key value) and provides for fast retrieval of the keys themselves.
  46. //! Class set supports bidirectional iterators.
  47. //!
  48. //! A set satisfies all of the requirements of a container and of a reversible container
  49. //! , and of an associative container. A set also provides most operations described in
  50. //! for unique keys.
  51. //!
  52. //! \tparam Key is the type to be inserted in the set, which is also the key_type
  53. //! \tparam Compare is the comparison functor used to order keys
  54. //! \tparam Allocator is the allocator to be used to allocate memory for this container
  55. //! \tparam SetOptions is an packed option type generated using using boost::container::tree_assoc_options.
  56. template <class Key, class Compare = std::less<Key>, class Allocator = new_allocator<Key>, class SetOptions = tree_assoc_defaults >
  57. #else
  58. template <class Key, class Compare, class Allocator, class SetOptions>
  59. #endif
  60. class set
  61. ///@cond
  62. : public container_detail::tree
  63. < Key, Key, container_detail::identity<Key>, Compare, Allocator, SetOptions>
  64. ///@endcond
  65. {
  66. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  67. private:
  68. BOOST_COPYABLE_AND_MOVABLE(set)
  69. typedef container_detail::tree
  70. < Key, Key, container_detail::identity<Key>, Compare, Allocator, SetOptions> base_t;
  71. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  72. public:
  73. //////////////////////////////////////////////
  74. //
  75. // types
  76. //
  77. //////////////////////////////////////////////
  78. typedef Key key_type;
  79. typedef Key value_type;
  80. typedef Compare key_compare;
  81. typedef Compare value_compare;
  82. typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
  83. typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
  84. typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
  85. typedef typename ::boost::container::allocator_traits<Allocator>::reference reference;
  86. typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference;
  87. typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type;
  88. typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type;
  89. typedef Allocator allocator_type;
  90. typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
  91. typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
  92. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
  93. typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
  94. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
  95. //////////////////////////////////////////////
  96. //
  97. // construct/copy/destroy
  98. //
  99. //////////////////////////////////////////////
  100. //! <b>Effects</b>: Default constructs an empty set.
  101. //!
  102. //! <b>Complexity</b>: Constant.
  103. set()
  104. : base_t()
  105. {}
  106. //! <b>Effects</b>: Constructs an empty set using the specified comparison object
  107. //! and allocator.
  108. //!
  109. //! <b>Complexity</b>: Constant.
  110. explicit set(const Compare& comp,
  111. const allocator_type& a = allocator_type())
  112. : base_t(comp, a)
  113. {}
  114. //! <b>Effects</b>: Constructs an empty set using the specified allocator object.
  115. //!
  116. //! <b>Complexity</b>: Constant.
  117. explicit set(const allocator_type& a)
  118. : base_t(a)
  119. {}
  120. //! <b>Effects</b>: Constructs an empty set using the specified comparison object and
  121. //! allocator, and inserts elements from the range [first ,last ).
  122. //!
  123. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  124. //! comp and otherwise N logN, where N is last - first.
  125. template <class InputIterator>
  126. set(InputIterator first, InputIterator last, const Compare& comp = Compare(),
  127. const allocator_type& a = allocator_type())
  128. : base_t(true, first, last, comp, a)
  129. {}
  130. //! <b>Effects</b>: Constructs an empty set using the specified
  131. //! allocator, and inserts elements from the range [first ,last ).
  132. //!
  133. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  134. //! comp and otherwise N logN, where N is last - first.
  135. template <class InputIterator>
  136. set(InputIterator first, InputIterator last, const allocator_type& a)
  137. : base_t(true, first, last, key_compare(), a)
  138. {}
  139. //! <b>Effects</b>: Constructs an empty set using the specified comparison object and
  140. //! allocator, and inserts elements from the ordered unique range [first ,last). This function
  141. //! is more efficient than the normal range creation for ordered ranges.
  142. //!
  143. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
  144. //! unique values.
  145. //!
  146. //! <b>Complexity</b>: Linear in N.
  147. //!
  148. //! <b>Note</b>: Non-standard extension.
  149. template <class InputIterator>
  150. set( ordered_unique_range_t, InputIterator first, InputIterator last
  151. , const Compare& comp = Compare(), const allocator_type& a = allocator_type())
  152. : base_t(ordered_range, first, last, comp, a)
  153. {}
  154. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  155. //! <b>Effects</b>: Constructs an empty set using the specified comparison object and
  156. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  157. //!
  158. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  159. //! comp and otherwise N logN, where N is il.begin() - il.end().
  160. set(std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
  161. : base_t(true, il.begin(), il.end(), comp, a)
  162. {}
  163. //! <b>Effects</b>: Constructs an empty set using the specified
  164. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  165. //!
  166. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  167. //! comp and otherwise N logN, where N is il.begin() - il.end().
  168. set(std::initializer_list<value_type> il, const allocator_type& a)
  169. : base_t(true, il.begin(), il.end(), Compare(), a)
  170. {}
  171. //! <b>Effects</b>: Constructs an empty set using the specified comparison object and
  172. //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
  173. //! is more efficient than the normal range creation for ordered ranges.
  174. //!
  175. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  176. //! unique values.
  177. //!
  178. //! <b>Complexity</b>: Linear in N.
  179. //!
  180. //! <b>Note</b>: Non-standard extension.
  181. set( ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare()
  182. , const allocator_type& a = allocator_type())
  183. : base_t(ordered_range, il.begin(), il.end(), comp, a)
  184. {}
  185. #endif
  186. //! <b>Effects</b>: Copy constructs a set.
  187. //!
  188. //! <b>Complexity</b>: Linear in x.size().
  189. set(const set& x)
  190. : base_t(static_cast<const base_t&>(x))
  191. {}
  192. //! <b>Effects</b>: Move constructs a set. Constructs *this using x's resources.
  193. //!
  194. //! <b>Complexity</b>: Constant.
  195. //!
  196. //! <b>Postcondition</b>: x is emptied.
  197. set(BOOST_RV_REF(set) x)
  198. : base_t(BOOST_MOVE_BASE(base_t, x))
  199. {}
  200. //! <b>Effects</b>: Copy constructs a set using the specified allocator.
  201. //!
  202. //! <b>Complexity</b>: Linear in x.size().
  203. set(const set& x, const allocator_type &a)
  204. : base_t(static_cast<const base_t&>(x), a)
  205. {}
  206. //! <b>Effects</b>: Move constructs a set using the specified allocator.
  207. //! Constructs *this using x's resources.
  208. //!
  209. //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
  210. set(BOOST_RV_REF(set) x, const allocator_type &a)
  211. : base_t(BOOST_MOVE_BASE(base_t, x), a)
  212. {}
  213. //! <b>Effects</b>: Makes *this a copy of x.
  214. //!
  215. //! <b>Complexity</b>: Linear in x.size().
  216. set& operator=(BOOST_COPY_ASSIGN_REF(set) x)
  217. { return static_cast<set&>(this->base_t::operator=(static_cast<const base_t&>(x))); }
  218. //! <b>Effects</b>: this->swap(x.get()).
  219. //!
  220. //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
  221. //! is false and (allocation throws or value_type's move constructor throws)
  222. //!
  223. //! <b>Complexity</b>: Constant if allocator_traits_type::
  224. //! propagate_on_container_move_assignment is true or
  225. //! this->get>allocator() == x.get_allocator(). Linear otherwise.
  226. set& operator=(BOOST_RV_REF(set) x)
  227. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  228. && boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
  229. { return static_cast<set&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
  230. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  231. //! <b>Effects</b>: Copy all elements from il to *this.
  232. //!
  233. //! <b>Complexity</b>: Linear in il.size().
  234. set& operator=(std::initializer_list<value_type> il)
  235. {
  236. this->clear();
  237. insert(il.begin(), il.end());
  238. return *this;
  239. }
  240. #endif
  241. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  242. //! <b>Effects</b>: Returns a copy of the allocator that
  243. //! was passed to the object's constructor.
  244. //!
  245. //! <b>Complexity</b>: Constant.
  246. allocator_type get_allocator() const;
  247. //! <b>Effects</b>: Returns a reference to the internal allocator.
  248. //!
  249. //! <b>Throws</b>: Nothing
  250. //!
  251. //! <b>Complexity</b>: Constant.
  252. //!
  253. //! <b>Note</b>: Non-standard extension.
  254. stored_allocator_type &get_stored_allocator();
  255. //! <b>Effects</b>: Returns a reference to the internal allocator.
  256. //!
  257. //! <b>Throws</b>: Nothing
  258. //!
  259. //! <b>Complexity</b>: Constant.
  260. //!
  261. //! <b>Note</b>: Non-standard extension.
  262. const stored_allocator_type &get_stored_allocator() const;
  263. //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
  264. //!
  265. //! <b>Throws</b>: Nothing.
  266. //!
  267. //! <b>Complexity</b>: Constant
  268. iterator begin();
  269. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  270. //!
  271. //! <b>Throws</b>: Nothing.
  272. //!
  273. //! <b>Complexity</b>: Constant.
  274. const_iterator begin() const;
  275. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  276. //!
  277. //! <b>Throws</b>: Nothing.
  278. //!
  279. //! <b>Complexity</b>: Constant.
  280. const_iterator cbegin() const;
  281. //! <b>Effects</b>: Returns an iterator to the end of the container.
  282. //!
  283. //! <b>Throws</b>: Nothing.
  284. //!
  285. //! <b>Complexity</b>: Constant.
  286. iterator end();
  287. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  288. //!
  289. //! <b>Throws</b>: Nothing.
  290. //!
  291. //! <b>Complexity</b>: Constant.
  292. const_iterator end() const;
  293. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  294. //!
  295. //! <b>Throws</b>: Nothing.
  296. //!
  297. //! <b>Complexity</b>: Constant.
  298. const_iterator cend() const;
  299. //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
  300. //! of the reversed container.
  301. //!
  302. //! <b>Throws</b>: Nothing.
  303. //!
  304. //! <b>Complexity</b>: Constant.
  305. reverse_iterator rbegin();
  306. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  307. //! of the reversed container.
  308. //!
  309. //! <b>Throws</b>: Nothing.
  310. //!
  311. //! <b>Complexity</b>: Constant.
  312. const_reverse_iterator rbegin() const;
  313. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  314. //! of the reversed container.
  315. //!
  316. //! <b>Throws</b>: Nothing.
  317. //!
  318. //! <b>Complexity</b>: Constant.
  319. const_reverse_iterator crbegin() const;
  320. //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
  321. //! of the reversed container.
  322. //!
  323. //! <b>Throws</b>: Nothing.
  324. //!
  325. //! <b>Complexity</b>: Constant.
  326. reverse_iterator rend();
  327. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  328. //! of the reversed container.
  329. //!
  330. //! <b>Throws</b>: Nothing.
  331. //!
  332. //! <b>Complexity</b>: Constant.
  333. const_reverse_iterator rend() const;
  334. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  335. //! of the reversed container.
  336. //!
  337. //! <b>Throws</b>: Nothing.
  338. //!
  339. //! <b>Complexity</b>: Constant.
  340. const_reverse_iterator crend() const;
  341. //! <b>Effects</b>: Returns true if the container contains no elements.
  342. //!
  343. //! <b>Throws</b>: Nothing.
  344. //!
  345. //! <b>Complexity</b>: Constant.
  346. bool empty() const;
  347. //! <b>Effects</b>: Returns the number of the elements contained in the container.
  348. //!
  349. //! <b>Throws</b>: Nothing.
  350. //!
  351. //! <b>Complexity</b>: Constant.
  352. size_type size() const;
  353. //! <b>Effects</b>: Returns the largest possible size of the container.
  354. //!
  355. //! <b>Throws</b>: Nothing.
  356. //!
  357. //! <b>Complexity</b>: Constant.
  358. size_type max_size() const;
  359. #endif // #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  360. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  361. //! <b>Effects</b>: Inserts an object x of type Key constructed with
  362. //! std::forward<Args>(args)... if and only if there is
  363. //! no element in the container with equivalent value.
  364. //! and returns the iterator pointing to the
  365. //! newly inserted element.
  366. //!
  367. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  368. //! if the insertion takes place, and the iterator component of the pair
  369. //! points to the element with key equivalent to the key of x.
  370. //!
  371. //! <b>Throws</b>: If memory allocation throws or
  372. //! Key's in-place constructor throws.
  373. //!
  374. //! <b>Complexity</b>: Logarithmic.
  375. template <class... Args>
  376. std::pair<iterator,bool> emplace(BOOST_FWD_REF(Args)... args)
  377. { return this->base_t::emplace_unique(boost::forward<Args>(args)...); }
  378. //! <b>Effects</b>: Inserts an object of type Key constructed with
  379. //! std::forward<Args>(args)... if and only if there is
  380. //! no element in the container with equivalent value.
  381. //! p is a hint pointing to where the insert
  382. //! should start to search.
  383. //!
  384. //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
  385. //!
  386. //! <b>Complexity</b>: Logarithmic.
  387. template <class... Args>
  388. iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
  389. { return this->base_t::emplace_hint_unique(p, boost::forward<Args>(args)...); }
  390. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  391. #define BOOST_CONTAINER_SET_EMPLACE_CODE(N) \
  392. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  393. std::pair<iterator,bool> emplace(BOOST_MOVE_UREF##N)\
  394. { return this->base_t::emplace_unique(BOOST_MOVE_FWD##N); }\
  395. \
  396. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  397. iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  398. { return this->base_t::emplace_hint_unique(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
  399. //
  400. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SET_EMPLACE_CODE)
  401. #undef BOOST_CONTAINER_SET_EMPLACE_CODE
  402. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  403. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  404. //! <b>Effects</b>: Inserts x if and only if there is no element in the container
  405. //! with key equivalent to the key of x.
  406. //!
  407. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  408. //! if the insertion takes place, and the iterator component of the pair
  409. //! points to the element with key equivalent to the key of x.
  410. //!
  411. //! <b>Complexity</b>: Logarithmic.
  412. std::pair<iterator, bool> insert(const value_type &x);
  413. //! <b>Effects</b>: Move constructs a new value from x if and only if there is
  414. //! no element in the container with key equivalent to the key of x.
  415. //!
  416. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  417. //! if the insertion takes place, and the iterator component of the pair
  418. //! points to the element with key equivalent to the key of x.
  419. //!
  420. //! <b>Complexity</b>: Logarithmic.
  421. std::pair<iterator, bool> insert(value_type &&x);
  422. #else
  423. private:
  424. typedef std::pair<iterator, bool> insert_return_pair;
  425. public:
  426. BOOST_MOVE_CONVERSION_AWARE_CATCH(insert, value_type, insert_return_pair, this->priv_insert)
  427. #endif
  428. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  429. //! <b>Effects</b>: Inserts a copy of x in the container if and only if there is
  430. //! no element in the container with key equivalent to the key of x.
  431. //! p is a hint pointing to where the insert should start to search.
  432. //!
  433. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  434. //! to the key of x.
  435. //!
  436. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  437. //! is inserted right before p.
  438. iterator insert(const_iterator p, const value_type &x);
  439. //! <b>Effects</b>: Inserts an element move constructed from x in the container.
  440. //! p is a hint pointing to where the insert should start to search.
  441. //!
  442. //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
  443. //!
  444. //! <b>Complexity</b>: Logarithmic.
  445. iterator insert(const_iterator p, value_type &&x);
  446. #else
  447. BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, value_type, iterator, this->priv_insert, const_iterator, const_iterator)
  448. #endif
  449. //! <b>Requires</b>: first, last are not iterators into *this.
  450. //!
  451. //! <b>Effects</b>: inserts each element from the range [first,last) if and only
  452. //! if there is no element with key equivalent to the key of that element.
  453. //!
  454. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  455. template <class InputIterator>
  456. void insert(InputIterator first, InputIterator last)
  457. { this->base_t::insert_unique(first, last); }
  458. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  459. //! <b>Effects</b>: inserts each element from the range [il.begin(),il.end()) if and only
  460. //! if there is no element with key equivalent to the key of that element.
  461. //!
  462. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
  463. void insert(std::initializer_list<value_type> il)
  464. { this->base_t::insert_unique(il.begin(), il.end()); }
  465. #endif
  466. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  467. //! <b>Effects</b>: Erases the element pointed to by p.
  468. //!
  469. //! <b>Returns</b>: Returns an iterator pointing to the element immediately
  470. //! following q prior to the element being erased. If no such element exists,
  471. //! returns end().
  472. //!
  473. //! <b>Complexity</b>: Amortized constant time
  474. iterator erase(const_iterator p);
  475. //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
  476. //!
  477. //! <b>Returns</b>: Returns the number of erased elements.
  478. //!
  479. //! <b>Complexity</b>: log(size()) + count(k)
  480. size_type erase(const key_type& x);
  481. //! <b>Effects</b>: Erases all the elements in the range [first, last).
  482. //!
  483. //! <b>Returns</b>: Returns last.
  484. //!
  485. //! <b>Complexity</b>: log(size())+N where N is the distance from first to last.
  486. iterator erase(const_iterator first, const_iterator last);
  487. //! <b>Effects</b>: Swaps the contents of *this and x.
  488. //!
  489. //! <b>Throws</b>: Nothing.
  490. //!
  491. //! <b>Complexity</b>: Constant.
  492. void swap(set& x)
  493. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  494. && boost::container::container_detail::is_nothrow_swappable<Compare>::value );
  495. //! <b>Effects</b>: erase(a.begin(),a.end()).
  496. //!
  497. //! <b>Postcondition</b>: size() == 0.
  498. //!
  499. //! <b>Complexity</b>: linear in size().
  500. void clear();
  501. //! <b>Effects</b>: Returns the comparison object out
  502. //! of which a was constructed.
  503. //!
  504. //! <b>Complexity</b>: Constant.
  505. key_compare key_comp() const;
  506. //! <b>Effects</b>: Returns an object of value_compare constructed out
  507. //! of the comparison object.
  508. //!
  509. //! <b>Complexity</b>: Constant.
  510. value_compare value_comp() const;
  511. //! <b>Returns</b>: An iterator pointing to an element with the key
  512. //! equivalent to x, or end() if such an element is not found.
  513. //!
  514. //! <b>Complexity</b>: Logarithmic.
  515. iterator find(const key_type& x);
  516. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  517. //! equivalent to x, or end() if such an element is not found.
  518. //!
  519. //! <b>Complexity</b>: Logarithmic.
  520. const_iterator find(const key_type& x) const;
  521. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  522. //! <b>Returns</b>: The number of elements with key equivalent to x.
  523. //!
  524. //! <b>Complexity</b>: log(size())+count(k)
  525. size_type count(const key_type& x) const
  526. { return static_cast<size_type>(this->base_t::find(x) != this->base_t::cend()); }
  527. //! <b>Returns</b>: The number of elements with key equivalent to x.
  528. //!
  529. //! <b>Complexity</b>: log(size())+count(k)
  530. size_type count(const key_type& x)
  531. { return static_cast<size_type>(this->base_t::find(x) != this->base_t::end()); }
  532. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  533. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  534. //! than k, or a.end() if such an element is not found.
  535. //!
  536. //! <b>Complexity</b>: Logarithmic
  537. iterator lower_bound(const key_type& x);
  538. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  539. //! less than k, or a.end() if such an element is not found.
  540. //!
  541. //! <b>Complexity</b>: Logarithmic
  542. const_iterator lower_bound(const key_type& x) const;
  543. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  544. //! than x, or end() if such an element is not found.
  545. //!
  546. //! <b>Complexity</b>: Logarithmic
  547. iterator upper_bound(const key_type& x);
  548. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  549. //! less than x, or end() if such an element is not found.
  550. //!
  551. //! <b>Complexity</b>: Logarithmic
  552. const_iterator upper_bound(const key_type& x) const;
  553. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  554. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  555. //!
  556. //! <b>Complexity</b>: Logarithmic
  557. std::pair<iterator,iterator> equal_range(const key_type& x)
  558. { return this->base_t::lower_bound_range(x); }
  559. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  560. //!
  561. //! <b>Complexity</b>: Logarithmic
  562. std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const
  563. { return this->base_t::lower_bound_range(x); }
  564. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  565. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  566. //!
  567. //! <b>Complexity</b>: Logarithmic
  568. std::pair<iterator,iterator> equal_range(const key_type& x);
  569. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  570. //!
  571. //! <b>Complexity</b>: Logarithmic
  572. std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const;
  573. //! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees.
  574. //!
  575. //! <b>Complexity</b>: Linear
  576. void rebalance();
  577. //! <b>Effects</b>: Returns true if x and y are equal
  578. //!
  579. //! <b>Complexity</b>: Linear to the number of elements in the container.
  580. friend bool operator==(const set& x, const set& y);
  581. //! <b>Effects</b>: Returns true if x and y are unequal
  582. //!
  583. //! <b>Complexity</b>: Linear to the number of elements in the container.
  584. friend bool operator!=(const set& x, const set& y);
  585. //! <b>Effects</b>: Returns true if x is less than y
  586. //!
  587. //! <b>Complexity</b>: Linear to the number of elements in the container.
  588. friend bool operator<(const set& x, const set& y);
  589. //! <b>Effects</b>: Returns true if x is greater than y
  590. //!
  591. //! <b>Complexity</b>: Linear to the number of elements in the container.
  592. friend bool operator>(const set& x, const set& y);
  593. //! <b>Effects</b>: Returns true if x is equal or less than y
  594. //!
  595. //! <b>Complexity</b>: Linear to the number of elements in the container.
  596. friend bool operator<=(const set& x, const set& y);
  597. //! <b>Effects</b>: Returns true if x is equal or greater than y
  598. //!
  599. //! <b>Complexity</b>: Linear to the number of elements in the container.
  600. friend bool operator>=(const set& x, const set& y);
  601. //! <b>Effects</b>: x.swap(y)
  602. //!
  603. //! <b>Complexity</b>: Constant.
  604. friend void swap(set& x, set& y);
  605. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  606. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  607. private:
  608. template <class KeyType>
  609. std::pair<iterator, bool> priv_insert(BOOST_FWD_REF(KeyType) x)
  610. { return this->base_t::insert_unique(::boost::forward<KeyType>(x)); }
  611. template <class KeyType>
  612. iterator priv_insert(const_iterator p, BOOST_FWD_REF(KeyType) x)
  613. { return this->base_t::insert_unique(p, ::boost::forward<KeyType>(x)); }
  614. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  615. };
  616. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  617. } //namespace container {
  618. //!has_trivial_destructor_after_move<> == true_type
  619. //!specialization for optimizations
  620. template <class Key, class Compare, class SetOptions, class Allocator>
  621. struct has_trivial_destructor_after_move<boost::container::set<Key, Compare, Allocator, SetOptions> >
  622. {
  623. typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
  624. static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
  625. ::boost::has_trivial_destructor_after_move<pointer>::value &&
  626. ::boost::has_trivial_destructor_after_move<Compare>::value;
  627. };
  628. namespace container {
  629. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  630. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  631. //! A multiset is a kind of associative container that supports equivalent keys
  632. //! (possibly contains multiple copies of the same key value) and provides for
  633. //! fast retrieval of the keys themselves. Class multiset supports bidirectional iterators.
  634. //!
  635. //! A multiset satisfies all of the requirements of a container and of a reversible
  636. //! container, and of an associative container). multiset also provides most operations
  637. //! described for duplicate keys.
  638. //!
  639. //! \tparam Key is the type to be inserted in the set, which is also the key_type
  640. //! \tparam Compare is the comparison functor used to order keys
  641. //! \tparam Allocator is the allocator to be used to allocate memory for this container
  642. //! \tparam MultiSetOptions is an packed option type generated using using boost::container::tree_assoc_options.
  643. template <class Key, class Compare = std::less<Key>, class Allocator = new_allocator<Key>, class MultiSetOptions = tree_assoc_defaults >
  644. #else
  645. template <class Key, class Compare, class Allocator, class MultiSetOptions>
  646. #endif
  647. class multiset
  648. /// @cond
  649. : public container_detail::tree
  650. <Key, Key,container_detail::identity<Key>, Compare, Allocator, MultiSetOptions>
  651. /// @endcond
  652. {
  653. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  654. private:
  655. BOOST_COPYABLE_AND_MOVABLE(multiset)
  656. typedef container_detail::tree
  657. <Key, Key,container_detail::identity<Key>, Compare, Allocator, MultiSetOptions> base_t;
  658. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  659. public:
  660. //////////////////////////////////////////////
  661. //
  662. // types
  663. //
  664. //////////////////////////////////////////////
  665. typedef Key key_type;
  666. typedef Key value_type;
  667. typedef Compare key_compare;
  668. typedef Compare value_compare;
  669. typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
  670. typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
  671. typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
  672. typedef typename ::boost::container::allocator_traits<Allocator>::reference reference;
  673. typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference;
  674. typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type;
  675. typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type;
  676. typedef Allocator allocator_type;
  677. typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
  678. typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
  679. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
  680. typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
  681. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
  682. //////////////////////////////////////////////
  683. //
  684. // construct/copy/destroy
  685. //
  686. //////////////////////////////////////////////
  687. //! @copydoc ::boost::container::set::set()
  688. multiset()
  689. : base_t()
  690. {}
  691. //! @copydoc ::boost::container::set::set(const Compare&, const allocator_type&)
  692. explicit multiset(const Compare& comp,
  693. const allocator_type& a = allocator_type())
  694. : base_t(comp, a)
  695. {}
  696. //! @copydoc ::boost::container::set::set(const allocator_type&)
  697. explicit multiset(const allocator_type& a)
  698. : base_t(a)
  699. {}
  700. //! @copydoc ::boost::container::set::set(InputIterator, InputIterator, const Compare& comp, const allocator_type&)
  701. template <class InputIterator>
  702. multiset(InputIterator first, InputIterator last,
  703. const Compare& comp = Compare(),
  704. const allocator_type& a = allocator_type())
  705. : base_t(false, first, last, comp, a)
  706. {}
  707. //! @copydoc ::boost::container::set::set(InputIterator, InputIterator, const allocator_type&)
  708. template <class InputIterator>
  709. multiset(InputIterator first, InputIterator last, const allocator_type& a)
  710. : base_t(false, first, last, key_compare(), a)
  711. {}
  712. //! <b>Effects</b>: Constructs an empty multiset using the specified comparison object and
  713. //! allocator, and inserts elements from the ordered range [first ,last ). This function
  714. //! is more efficient than the normal range creation for ordered ranges.
  715. //!
  716. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  717. //!
  718. //! <b>Complexity</b>: Linear in N.
  719. //!
  720. //! <b>Note</b>: Non-standard extension.
  721. template <class InputIterator>
  722. multiset( ordered_range_t, InputIterator first, InputIterator last
  723. , const Compare& comp = Compare()
  724. , const allocator_type& a = allocator_type())
  725. : base_t(ordered_range, first, last, comp, a)
  726. {}
  727. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  728. //! @copydoc ::boost::container::set::set(std::initializer_list<value_type>, const Compare& comp, const allocator_type&)
  729. multiset(std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
  730. : base_t(false, il.begin(), il.end(), comp, a)
  731. {}
  732. //! @copydoc ::boost::container::set::set(std::initializer_list<value_type>, const allocator_type&)
  733. multiset(std::initializer_list<value_type> il, const allocator_type& a)
  734. : base_t(false, il.begin(), il.end(), Compare(), a)
  735. {}
  736. //! @copydoc ::boost::container::set::set(ordered_unique_range_t, std::initializer_list<value_type>, const Compare& comp, const allocator_type&)
  737. multiset(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
  738. : base_t(ordered_range, il.begin(), il.end(), comp, a)
  739. {}
  740. #endif
  741. //! @copydoc ::boost::container::set::set(const set &)
  742. multiset(const multiset& x)
  743. : base_t(static_cast<const base_t&>(x))
  744. {}
  745. //! @copydoc ::boost::container::set::set(set &&)
  746. multiset(BOOST_RV_REF(multiset) x)
  747. : base_t(BOOST_MOVE_BASE(base_t, x))
  748. {}
  749. //! @copydoc ::boost::container::set::set(const set &, const allocator_type &)
  750. multiset(const multiset& x, const allocator_type &a)
  751. : base_t(static_cast<const base_t&>(x), a)
  752. {}
  753. //! @copydoc ::boost::container::set::set(set &&, const allocator_type &)
  754. multiset(BOOST_RV_REF(multiset) x, const allocator_type &a)
  755. : base_t(BOOST_MOVE_BASE(base_t, x), a)
  756. {}
  757. //! @copydoc ::boost::container::set::operator=(const set &)
  758. multiset& operator=(BOOST_COPY_ASSIGN_REF(multiset) x)
  759. { return static_cast<multiset&>(this->base_t::operator=(static_cast<const base_t&>(x))); }
  760. //! @copydoc ::boost::container::set::operator=(set &&)
  761. multiset& operator=(BOOST_RV_REF(multiset) x)
  762. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  763. && boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
  764. { return static_cast<multiset&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
  765. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  766. //! @copydoc ::boost::container::set::operator=(std::initializer_list<value_type>)
  767. multiset& operator=(std::initializer_list<value_type> il)
  768. {
  769. this->clear();
  770. insert(il.begin(), il.end());
  771. return *this;
  772. }
  773. #endif
  774. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  775. //! @copydoc ::boost::container::set::get_allocator()
  776. allocator_type get_allocator() const;
  777. //! @copydoc ::boost::container::set::get_stored_allocator()
  778. stored_allocator_type &get_stored_allocator();
  779. //! @copydoc ::boost::container::set::get_stored_allocator() const
  780. const stored_allocator_type &get_stored_allocator() const;
  781. //! @copydoc ::boost::container::set::begin()
  782. iterator begin();
  783. //! @copydoc ::boost::container::set::begin() const
  784. const_iterator begin() const;
  785. //! @copydoc ::boost::container::set::cbegin() const
  786. const_iterator cbegin() const;
  787. //! @copydoc ::boost::container::set::end()
  788. iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
  789. //! @copydoc ::boost::container::set::end() const
  790. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
  791. //! @copydoc ::boost::container::set::cend() const
  792. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
  793. //! @copydoc ::boost::container::set::rbegin()
  794. reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
  795. //! @copydoc ::boost::container::set::rbegin() const
  796. const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  797. //! @copydoc ::boost::container::set::crbegin() const
  798. const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  799. //! @copydoc ::boost::container::set::rend()
  800. reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
  801. //! @copydoc ::boost::container::set::rend() const
  802. const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
  803. //! @copydoc ::boost::container::set::crend() const
  804. const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
  805. //! @copydoc ::boost::container::set::empty() const
  806. bool empty() const;
  807. //! @copydoc ::boost::container::set::size() const
  808. size_type size() const;
  809. //! @copydoc ::boost::container::set::max_size() const
  810. size_type max_size() const;
  811. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  812. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  813. //! <b>Effects</b>: Inserts an object of type Key constructed with
  814. //! std::forward<Args>(args)... and returns the iterator pointing to the
  815. //! newly inserted element.
  816. //!
  817. //! <b>Complexity</b>: Logarithmic.
  818. template <class... Args>
  819. iterator emplace(BOOST_FWD_REF(Args)... args)
  820. { return this->base_t::emplace_equal(boost::forward<Args>(args)...); }
  821. //! <b>Effects</b>: Inserts an object of type Key constructed with
  822. //! std::forward<Args>(args)...
  823. //!
  824. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  825. //! to the key of x.
  826. //!
  827. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  828. //! is inserted right before p.
  829. template <class... Args>
  830. iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
  831. { return this->base_t::emplace_hint_equal(p, boost::forward<Args>(args)...); }
  832. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  833. #define BOOST_CONTAINER_MULTISET_EMPLACE_CODE(N) \
  834. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  835. iterator emplace(BOOST_MOVE_UREF##N)\
  836. { return this->base_t::emplace_equal(BOOST_MOVE_FWD##N); }\
  837. \
  838. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  839. iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  840. { return this->base_t::emplace_hint_equal(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
  841. //
  842. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_MULTISET_EMPLACE_CODE)
  843. #undef BOOST_CONTAINER_MULTISET_EMPLACE_CODE
  844. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  845. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  846. //! <b>Effects</b>: Inserts x and returns the iterator pointing to the
  847. //! newly inserted element.
  848. //!
  849. //! <b>Complexity</b>: Logarithmic.
  850. iterator insert(const value_type &x);
  851. //! <b>Effects</b>: Inserts a copy of x in the container.
  852. //!
  853. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  854. //! to the key of x.
  855. //!
  856. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  857. //! is inserted right before p.
  858. iterator insert(value_type &&x);
  859. #else
  860. BOOST_MOVE_CONVERSION_AWARE_CATCH(insert, value_type, iterator, this->priv_insert)
  861. #endif
  862. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  863. //! <b>Effects</b>: Inserts a copy of x in the container.
  864. //! p is a hint pointing to where the insert should start to search.
  865. //!
  866. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  867. //! to the key of x.
  868. //!
  869. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  870. //! is inserted right before p.
  871. iterator insert(const_iterator p, const value_type &x);
  872. //! <b>Effects</b>: Inserts a value move constructed from x in the container.
  873. //! p is a hint pointing to where the insert should start to search.
  874. //!
  875. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  876. //! to the key of x.
  877. //!
  878. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  879. //! is inserted right before p.
  880. iterator insert(const_iterator p, value_type &&x);
  881. #else
  882. BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, value_type, iterator, this->priv_insert, const_iterator, const_iterator)
  883. #endif
  884. //! <b>Requires</b>: first, last are not iterators into *this.
  885. //!
  886. //! <b>Effects</b>: inserts each element from the range [first,last) .
  887. //!
  888. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  889. template <class InputIterator>
  890. void insert(InputIterator first, InputIterator last)
  891. { this->base_t::insert_equal(first, last); }
  892. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  893. //! @copydoc ::boost::container::set::insert(std::initializer_list<value_type>)
  894. void insert(std::initializer_list<value_type> il)
  895. { this->base_t::insert_equal(il.begin(), il.end()); }
  896. #endif
  897. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  898. //! @copydoc ::boost::container::set::erase(const_iterator)
  899. iterator erase(const_iterator p);
  900. //! @copydoc ::boost::container::set::erase(const key_type&)
  901. size_type erase(const key_type& x);
  902. //! @copydoc ::boost::container::set::erase(const_iterator,const_iterator)
  903. iterator erase(const_iterator first, const_iterator last);
  904. //! @copydoc ::boost::container::set::swap
  905. void swap(multiset& x)
  906. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  907. && boost::container::container_detail::is_nothrow_swappable<Compare>::value );
  908. //! @copydoc ::boost::container::set::clear
  909. void clear() BOOST_NOEXCEPT_OR_NOTHROW;
  910. //! @copydoc ::boost::container::set::key_comp
  911. key_compare key_comp() const;
  912. //! @copydoc ::boost::container::set::value_comp
  913. value_compare value_comp() const;
  914. //! @copydoc ::boost::container::set::find(const key_type& )
  915. iterator find(const key_type& x);
  916. //! @copydoc ::boost::container::set::find(const key_type& ) const
  917. const_iterator find(const key_type& x) const;
  918. //! @copydoc ::boost::container::set::count(const key_type& ) const
  919. size_type count(const key_type& x) const;
  920. //! @copydoc ::boost::container::set::lower_bound(const key_type& )
  921. iterator lower_bound(const key_type& x);
  922. //! @copydoc ::boost::container::set::lower_bound(const key_type& ) const
  923. const_iterator lower_bound(const key_type& x) const;
  924. //! @copydoc ::boost::container::set::upper_bound(const key_type& )
  925. iterator upper_bound(const key_type& x);
  926. //! @copydoc ::boost::container::set::upper_bound(const key_type& ) const
  927. const_iterator upper_bound(const key_type& x) const;
  928. //! @copydoc ::boost::container::set::equal_range(const key_type& ) const
  929. std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const;
  930. //! @copydoc ::boost::container::set::equal_range(const key_type& )
  931. std::pair<iterator,iterator> equal_range(const key_type& x);
  932. //! @copydoc ::boost::container::set::rebalance()
  933. void rebalance();
  934. //! <b>Effects</b>: Returns true if x and y are equal
  935. //!
  936. //! <b>Complexity</b>: Linear to the number of elements in the container.
  937. friend bool operator==(const multiset& x, const multiset& y);
  938. //! <b>Effects</b>: Returns true if x and y are unequal
  939. //!
  940. //! <b>Complexity</b>: Linear to the number of elements in the container.
  941. friend bool operator!=(const multiset& x, const multiset& y);
  942. //! <b>Effects</b>: Returns true if x is less than y
  943. //!
  944. //! <b>Complexity</b>: Linear to the number of elements in the container.
  945. friend bool operator<(const multiset& x, const multiset& y);
  946. //! <b>Effects</b>: Returns true if x is greater than y
  947. //!
  948. //! <b>Complexity</b>: Linear to the number of elements in the container.
  949. friend bool operator>(const multiset& x, const multiset& y);
  950. //! <b>Effects</b>: Returns true if x is equal or less than y
  951. //!
  952. //! <b>Complexity</b>: Linear to the number of elements in the container.
  953. friend bool operator<=(const multiset& x, const multiset& y);
  954. //! <b>Effects</b>: Returns true if x is equal or greater than y
  955. //!
  956. //! <b>Complexity</b>: Linear to the number of elements in the container.
  957. friend bool operator>=(const multiset& x, const multiset& y);
  958. //! <b>Effects</b>: x.swap(y)
  959. //!
  960. //! <b>Complexity</b>: Constant.
  961. friend void swap(multiset& x, multiset& y);
  962. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  963. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  964. private:
  965. template <class KeyType>
  966. iterator priv_insert(BOOST_FWD_REF(KeyType) x)
  967. { return this->base_t::insert_equal(::boost::forward<KeyType>(x)); }
  968. template <class KeyType>
  969. iterator priv_insert(const_iterator p, BOOST_FWD_REF(KeyType) x)
  970. { return this->base_t::insert_equal(p, ::boost::forward<KeyType>(x)); }
  971. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  972. };
  973. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  974. } //namespace container {
  975. //!has_trivial_destructor_after_move<> == true_type
  976. //!specialization for optimizations
  977. template <class Key, class Compare, class Allocator, class MultiSetOptions>
  978. struct has_trivial_destructor_after_move<boost::container::multiset<Key, Compare, Allocator, MultiSetOptions> >
  979. {
  980. typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
  981. static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
  982. ::boost::has_trivial_destructor_after_move<pointer>::value &&
  983. ::boost::has_trivial_destructor_after_move<Compare>::value;
  984. };
  985. namespace container {
  986. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  987. }}
  988. #include <boost/container/detail/config_end.hpp>
  989. #endif // BOOST_CONTAINER_SET_HPP