set.hpp 47 KB

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