unordered_set.hpp 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102
  1. // Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard.
  2. // Copyright (C) 2005-2011 Daniel James.
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/unordered for documentation
  6. #ifndef BOOST_UNORDERED_UNORDERED_SET_HPP_INCLUDED
  7. #define BOOST_UNORDERED_UNORDERED_SET_HPP_INCLUDED
  8. #include <boost/config.hpp>
  9. #if defined(BOOST_HAS_PRAGMA_ONCE)
  10. #pragma once
  11. #endif
  12. #include <boost/core/explicit_operator_bool.hpp>
  13. #include <boost/functional/hash.hpp>
  14. #include <boost/move/move.hpp>
  15. #include <boost/unordered/detail/set.hpp>
  16. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  17. #include <initializer_list>
  18. #endif
  19. #if defined(BOOST_MSVC)
  20. #pragma warning(push)
  21. // conditional expression is constant
  22. #pragma warning(disable : 4127)
  23. #if BOOST_MSVC >= 1400
  24. // the inline specifier cannot be used when a friend declaration refers to a
  25. // specialization of a function template
  26. #pragma warning(disable : 4396)
  27. #endif
  28. #endif
  29. namespace boost {
  30. namespace unordered {
  31. template <class T, class H, class P, class A> class unordered_set
  32. {
  33. #if defined(BOOST_UNORDERED_USE_MOVE)
  34. BOOST_COPYABLE_AND_MOVABLE(unordered_set)
  35. #endif
  36. template <typename, typename, typename, typename>
  37. friend class unordered_multiset;
  38. public:
  39. typedef T key_type;
  40. typedef T value_type;
  41. typedef H hasher;
  42. typedef P key_equal;
  43. typedef A allocator_type;
  44. private:
  45. typedef boost::unordered::detail::set<A, T, H, P> types;
  46. typedef typename types::value_allocator_traits value_allocator_traits;
  47. typedef typename types::table table;
  48. typedef typename table::node_pointer node_pointer;
  49. typedef typename table::link_pointer link_pointer;
  50. public:
  51. typedef typename value_allocator_traits::pointer pointer;
  52. typedef typename value_allocator_traits::const_pointer const_pointer;
  53. typedef value_type& reference;
  54. typedef value_type const& const_reference;
  55. typedef std::size_t size_type;
  56. typedef std::ptrdiff_t difference_type;
  57. typedef typename table::iterator iterator;
  58. typedef typename table::c_iterator const_iterator;
  59. typedef typename table::l_iterator local_iterator;
  60. typedef typename table::cl_iterator const_local_iterator;
  61. typedef typename types::node_type node_type;
  62. typedef typename types::insert_return_type insert_return_type;
  63. private:
  64. table table_;
  65. public:
  66. // constructors
  67. unordered_set();
  68. explicit unordered_set(size_type, const hasher& = hasher(),
  69. const key_equal& = key_equal(),
  70. const allocator_type& = allocator_type());
  71. template <class InputIt>
  72. unordered_set(InputIt, InputIt,
  73. size_type = boost::unordered::detail::default_bucket_count,
  74. const hasher& = hasher(), const key_equal& = key_equal(),
  75. const allocator_type& = allocator_type());
  76. unordered_set(unordered_set const&);
  77. #if defined(BOOST_UNORDERED_USE_MOVE) || \
  78. !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  79. unordered_set(BOOST_RV_REF(unordered_set) other)
  80. BOOST_NOEXCEPT_IF(table::nothrow_move_constructible)
  81. : table_(other.table_, boost::unordered::detail::move_tag())
  82. {
  83. // The move is done in table_
  84. }
  85. #endif
  86. explicit unordered_set(allocator_type const&);
  87. unordered_set(unordered_set const&, allocator_type const&);
  88. unordered_set(BOOST_RV_REF(unordered_set), allocator_type const&);
  89. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  90. unordered_set(std::initializer_list<value_type>,
  91. size_type = boost::unordered::detail::default_bucket_count,
  92. const hasher& = hasher(), const key_equal& l = key_equal(),
  93. const allocator_type& = allocator_type());
  94. #endif
  95. explicit unordered_set(size_type, const allocator_type&);
  96. explicit unordered_set(size_type, const hasher&, const allocator_type&);
  97. template <class InputIt>
  98. unordered_set(InputIt, InputIt, size_type, const allocator_type&);
  99. template <class InputIt>
  100. unordered_set(
  101. InputIt, InputIt, size_type, const hasher&, const allocator_type&);
  102. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  103. unordered_set(
  104. std::initializer_list<value_type>, size_type, const allocator_type&);
  105. unordered_set(std::initializer_list<value_type>, size_type, const hasher&,
  106. const allocator_type&);
  107. #endif
  108. // Destructor
  109. ~unordered_set() BOOST_NOEXCEPT;
  110. // Assign
  111. #if defined(BOOST_UNORDERED_USE_MOVE)
  112. unordered_set& operator=(BOOST_COPY_ASSIGN_REF(unordered_set) x)
  113. {
  114. table_.assign(x.table_, boost::unordered::detail::true_type());
  115. return *this;
  116. }
  117. unordered_set& operator=(BOOST_RV_REF(unordered_set) x)
  118. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  119. boost::is_nothrow_move_assignable<H>::value&&
  120. boost::is_nothrow_move_assignable<P>::value)
  121. {
  122. table_.move_assign(x.table_, boost::unordered::detail::true_type());
  123. return *this;
  124. }
  125. #else
  126. unordered_set& operator=(unordered_set const& x)
  127. {
  128. table_.assign(x.table_, boost::unordered::detail::true_type());
  129. return *this;
  130. }
  131. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  132. unordered_set& operator=(unordered_set&& x)
  133. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  134. boost::is_nothrow_move_assignable<H>::value&&
  135. boost::is_nothrow_move_assignable<P>::value)
  136. {
  137. table_.move_assign(x.table_, boost::unordered::detail::true_type());
  138. return *this;
  139. }
  140. #endif
  141. #endif
  142. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  143. unordered_set& operator=(std::initializer_list<value_type>);
  144. #endif
  145. allocator_type get_allocator() const BOOST_NOEXCEPT
  146. {
  147. return table_.node_alloc();
  148. }
  149. // iterators
  150. iterator begin() BOOST_NOEXCEPT { return iterator(table_.begin()); }
  151. const_iterator begin() const BOOST_NOEXCEPT
  152. {
  153. return const_iterator(table_.begin());
  154. }
  155. iterator end() BOOST_NOEXCEPT { return iterator(); }
  156. const_iterator end() const BOOST_NOEXCEPT { return const_iterator(); }
  157. const_iterator cbegin() const BOOST_NOEXCEPT
  158. {
  159. return const_iterator(table_.begin());
  160. }
  161. const_iterator cend() const BOOST_NOEXCEPT { return const_iterator(); }
  162. // size and capacity
  163. bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; }
  164. size_type size() const BOOST_NOEXCEPT { return table_.size_; }
  165. size_type max_size() const BOOST_NOEXCEPT;
  166. // emplace
  167. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  168. template <class... Args>
  169. std::pair<iterator, bool> emplace(BOOST_FWD_REF(Args)... args)
  170. {
  171. return table_.emplace_unique(
  172. table::extractor::extract(boost::forward<Args>(args)...),
  173. boost::forward<Args>(args)...);
  174. }
  175. #else
  176. #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
  177. // 0 argument emplace requires special treatment in case
  178. // the container is instantiated with a value type that
  179. // doesn't have a default constructor.
  180. std::pair<iterator, bool> emplace(
  181. boost::unordered::detail::empty_emplace =
  182. boost::unordered::detail::empty_emplace(),
  183. value_type v = value_type())
  184. {
  185. return this->emplace(boost::move(v));
  186. }
  187. #endif
  188. template <typename A0>
  189. std::pair<iterator, bool> emplace(BOOST_FWD_REF(A0) a0)
  190. {
  191. return table_.emplace_unique(
  192. table::extractor::extract(boost::forward<A0>(a0)),
  193. boost::unordered::detail::create_emplace_args(
  194. boost::forward<A0>(a0)));
  195. }
  196. template <typename A0, typename A1>
  197. std::pair<iterator, bool> emplace(
  198. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  199. {
  200. return table_.emplace_unique(
  201. table::extractor::extract(
  202. boost::forward<A0>(a0), boost::forward<A1>(a1)),
  203. boost::unordered::detail::create_emplace_args(
  204. boost::forward<A0>(a0), boost::forward<A1>(a1)));
  205. }
  206. template <typename A0, typename A1, typename A2>
  207. std::pair<iterator, bool> emplace(
  208. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  209. {
  210. return table_.emplace_unique(
  211. table::extractor::extract(
  212. boost::forward<A0>(a0), boost::forward<A1>(a1)),
  213. boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
  214. boost::forward<A1>(a1), boost::forward<A2>(a2)));
  215. }
  216. #endif
  217. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  218. template <class... Args>
  219. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
  220. {
  221. return table_.emplace_hint_unique(hint,
  222. table::extractor::extract(boost::forward<Args>(args)...),
  223. boost::forward<Args>(args)...);
  224. }
  225. #else
  226. #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
  227. iterator emplace_hint(const_iterator hint,
  228. boost::unordered::detail::empty_emplace =
  229. boost::unordered::detail::empty_emplace(),
  230. value_type v = value_type())
  231. {
  232. return this->emplace_hint(hint, boost::move(v));
  233. }
  234. #endif
  235. template <typename A0>
  236. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0)
  237. {
  238. return table_.emplace_hint_unique(hint,
  239. table::extractor::extract(boost::forward<A0>(a0)),
  240. boost::unordered::detail::create_emplace_args(
  241. boost::forward<A0>(a0)));
  242. }
  243. template <typename A0, typename A1>
  244. iterator emplace_hint(
  245. const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  246. {
  247. return table_.emplace_hint_unique(hint,
  248. table::extractor::extract(
  249. boost::forward<A0>(a0), boost::forward<A1>(a1)),
  250. boost::unordered::detail::create_emplace_args(
  251. boost::forward<A0>(a0), boost::forward<A1>(a1)));
  252. }
  253. template <typename A0, typename A1, typename A2>
  254. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0,
  255. BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  256. {
  257. return table_.emplace_hint_unique(hint,
  258. table::extractor::extract(
  259. boost::forward<A0>(a0), boost::forward<A1>(a1)),
  260. boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
  261. boost::forward<A1>(a1), boost::forward<A2>(a2)));
  262. }
  263. #endif
  264. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  265. #define BOOST_UNORDERED_EMPLACE(z, n, _) \
  266. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  267. std::pair<iterator, bool> emplace( \
  268. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  269. { \
  270. return table_.emplace_unique( \
  271. table::extractor::extract( \
  272. boost::forward<A0>(a0), boost::forward<A1>(a1)), \
  273. boost::unordered::detail::create_emplace_args( \
  274. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
  275. } \
  276. \
  277. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  278. iterator emplace_hint( \
  279. const_iterator hint, BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  280. { \
  281. return table_.emplace_hint_unique(hint, \
  282. table::extractor::extract( \
  283. boost::forward<A0>(a0), boost::forward<A1>(a1)), \
  284. boost::unordered::detail::create_emplace_args( \
  285. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
  286. }
  287. BOOST_UNORDERED_EMPLACE(1, 4, _)
  288. BOOST_UNORDERED_EMPLACE(1, 5, _)
  289. BOOST_UNORDERED_EMPLACE(1, 6, _)
  290. BOOST_UNORDERED_EMPLACE(1, 7, _)
  291. BOOST_UNORDERED_EMPLACE(1, 8, _)
  292. BOOST_UNORDERED_EMPLACE(1, 9, _)
  293. BOOST_PP_REPEAT_FROM_TO(10, BOOST_PP_INC(BOOST_UNORDERED_EMPLACE_LIMIT),
  294. BOOST_UNORDERED_EMPLACE, _)
  295. #undef BOOST_UNORDERED_EMPLACE
  296. #endif
  297. std::pair<iterator, bool> insert(value_type const& x)
  298. {
  299. return this->emplace(x);
  300. }
  301. std::pair<iterator, bool> insert(BOOST_UNORDERED_RV_REF(value_type) x)
  302. {
  303. return this->emplace(boost::move(x));
  304. }
  305. iterator insert(const_iterator hint, value_type const& x)
  306. {
  307. return this->emplace_hint(hint, x);
  308. }
  309. iterator insert(const_iterator hint, BOOST_UNORDERED_RV_REF(value_type) x)
  310. {
  311. return this->emplace_hint(hint, boost::move(x));
  312. }
  313. template <class InputIt> void insert(InputIt, InputIt);
  314. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  315. void insert(std::initializer_list<value_type>);
  316. #endif
  317. // extract
  318. node_type extract(const_iterator position)
  319. {
  320. return node_type(
  321. table_.extract_by_iterator_unique(position), table_.node_alloc());
  322. }
  323. node_type extract(const key_type& k)
  324. {
  325. return node_type(table_.extract_by_key(k), table_.node_alloc());
  326. }
  327. insert_return_type insert(BOOST_RV_REF(node_type) np)
  328. {
  329. insert_return_type result;
  330. table_.move_insert_node_type_unique(np, result);
  331. return boost::move(result);
  332. }
  333. iterator insert(const_iterator hint, BOOST_RV_REF(node_type) np)
  334. {
  335. return table_.move_insert_node_type_with_hint_unique(hint, np);
  336. }
  337. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
  338. (BOOST_COMP_GNUC && BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(4, 6, 0))
  339. private:
  340. // Note: Use r-value node_type to insert.
  341. insert_return_type insert(node_type&);
  342. iterator insert(const_iterator, node_type& np);
  343. public:
  344. #endif
  345. iterator erase(const_iterator);
  346. size_type erase(const key_type&);
  347. iterator erase(const_iterator, const_iterator);
  348. BOOST_UNORDERED_DEPRECATED("Use erase instead")
  349. void quick_erase(const_iterator it) { erase(it); }
  350. BOOST_UNORDERED_DEPRECATED("Use erase instead")
  351. void erase_return_void(const_iterator it) { erase(it); }
  352. void swap(unordered_set&)
  353. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  354. boost::is_nothrow_swappable<H>::value&&
  355. boost::is_nothrow_swappable<P>::value);
  356. void clear() BOOST_NOEXCEPT { table_.clear_impl(); }
  357. template <typename H2, typename P2>
  358. void merge(boost::unordered_set<T, H2, P2, A>& source);
  359. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  360. template <typename H2, typename P2>
  361. void merge(boost::unordered_set<T, H2, P2, A>&& source);
  362. #endif
  363. template <typename H2, typename P2>
  364. void merge(boost::unordered_multiset<T, H2, P2, A>& source);
  365. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  366. template <typename H2, typename P2>
  367. void merge(boost::unordered_multiset<T, H2, P2, A>&& source);
  368. #endif
  369. // observers
  370. hasher hash_function() const;
  371. key_equal key_eq() const;
  372. // lookup
  373. const_iterator find(const key_type&) const;
  374. template <class CompatibleKey, class CompatibleHash,
  375. class CompatiblePredicate>
  376. const_iterator find(CompatibleKey const&, CompatibleHash const&,
  377. CompatiblePredicate const&) const;
  378. size_type count(const key_type&) const;
  379. std::pair<const_iterator, const_iterator> equal_range(
  380. const key_type&) const;
  381. // bucket interface
  382. size_type bucket_count() const BOOST_NOEXCEPT
  383. {
  384. return table_.bucket_count_;
  385. }
  386. size_type max_bucket_count() const BOOST_NOEXCEPT
  387. {
  388. return table_.max_bucket_count();
  389. }
  390. size_type bucket_size(size_type) const;
  391. size_type bucket(const key_type& k) const
  392. {
  393. return table_.hash_to_bucket(table_.hash(k));
  394. }
  395. local_iterator begin(size_type n)
  396. {
  397. return local_iterator(table_.begin(n), n, table_.bucket_count_);
  398. }
  399. const_local_iterator begin(size_type n) const
  400. {
  401. return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
  402. }
  403. local_iterator end(size_type) { return local_iterator(); }
  404. const_local_iterator end(size_type) const
  405. {
  406. return const_local_iterator();
  407. }
  408. const_local_iterator cbegin(size_type n) const
  409. {
  410. return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
  411. }
  412. const_local_iterator cend(size_type) const
  413. {
  414. return const_local_iterator();
  415. }
  416. // hash policy
  417. float load_factor() const BOOST_NOEXCEPT;
  418. float max_load_factor() const BOOST_NOEXCEPT { return table_.mlf_; }
  419. void max_load_factor(float) BOOST_NOEXCEPT;
  420. void rehash(size_type);
  421. void reserve(size_type);
  422. #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582)
  423. friend bool operator==
  424. <T, H, P, A>(unordered_set const&, unordered_set const&);
  425. friend bool operator!=
  426. <T, H, P, A>(unordered_set const&, unordered_set const&);
  427. #endif
  428. }; // class template unordered_set
  429. #if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
  430. template <class InputIterator,
  431. class Hash =
  432. boost::hash<typename std::iterator_traits<InputIterator>::value_type>,
  433. class Pred =
  434. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  435. class Allocator = std::allocator<
  436. typename std::iterator_traits<InputIterator>::value_type> >
  437. unordered_set(InputIterator, InputIterator,
  438. std::size_t = boost::unordered::detail::default_bucket_count,
  439. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  440. ->unordered_set<typename std::iterator_traits<InputIterator>::value_type,
  441. Hash, Pred, Allocator>;
  442. template <class T, class Hash = boost::hash<T>,
  443. class Pred = std::equal_to<T>, class Allocator = std::allocator<T> >
  444. unordered_set(std::initializer_list<T>,
  445. std::size_t = boost::unordered::detail::default_bucket_count,
  446. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  447. ->unordered_set<T, Hash, Pred, Allocator>;
  448. template <class InputIterator, class Allocator>
  449. unordered_set(InputIterator, InputIterator, std::size_t, Allocator)
  450. ->unordered_set<typename std::iterator_traits<InputIterator>::value_type,
  451. boost::hash<typename std::iterator_traits<InputIterator>::value_type>,
  452. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  453. Allocator>;
  454. template <class InputIterator, class Hash, class Allocator>
  455. unordered_set(InputIterator, InputIterator, std::size_t, Hash, Allocator)
  456. ->unordered_set<typename std::iterator_traits<InputIterator>::value_type,
  457. Hash,
  458. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  459. Allocator>;
  460. template <class T, class Allocator>
  461. unordered_set(std::initializer_list<T>, std::size_t, Allocator)
  462. ->unordered_set<T, boost::hash<T>, std::equal_to<T>, Allocator>;
  463. template <class T, class Hash, class Allocator>
  464. unordered_set(std::initializer_list<T>, std::size_t, Hash, Allocator)
  465. ->unordered_set<T, Hash, std::equal_to<T>, Allocator>;
  466. #endif
  467. template <class T, class H, class P, class A> class unordered_multiset
  468. {
  469. #if defined(BOOST_UNORDERED_USE_MOVE)
  470. BOOST_COPYABLE_AND_MOVABLE(unordered_multiset)
  471. #endif
  472. template <typename, typename, typename, typename>
  473. friend class unordered_set;
  474. public:
  475. typedef T key_type;
  476. typedef T value_type;
  477. typedef H hasher;
  478. typedef P key_equal;
  479. typedef A allocator_type;
  480. private:
  481. typedef boost::unordered::detail::set<A, T, H, P> types;
  482. typedef typename types::value_allocator_traits value_allocator_traits;
  483. typedef typename types::table table;
  484. typedef typename table::node_pointer node_pointer;
  485. typedef typename table::link_pointer link_pointer;
  486. public:
  487. typedef typename value_allocator_traits::pointer pointer;
  488. typedef typename value_allocator_traits::const_pointer const_pointer;
  489. typedef value_type& reference;
  490. typedef value_type const& const_reference;
  491. typedef std::size_t size_type;
  492. typedef std::ptrdiff_t difference_type;
  493. typedef typename table::iterator iterator;
  494. typedef typename table::c_iterator const_iterator;
  495. typedef typename table::l_iterator local_iterator;
  496. typedef typename table::cl_iterator const_local_iterator;
  497. typedef typename types::node_type node_type;
  498. private:
  499. table table_;
  500. public:
  501. // constructors
  502. unordered_multiset();
  503. explicit unordered_multiset(size_type, const hasher& = hasher(),
  504. const key_equal& = key_equal(),
  505. const allocator_type& = allocator_type());
  506. template <class InputIt>
  507. unordered_multiset(InputIt, InputIt,
  508. size_type = boost::unordered::detail::default_bucket_count,
  509. const hasher& = hasher(), const key_equal& = key_equal(),
  510. const allocator_type& = allocator_type());
  511. unordered_multiset(unordered_multiset const&);
  512. #if defined(BOOST_UNORDERED_USE_MOVE) || \
  513. !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  514. unordered_multiset(BOOST_RV_REF(unordered_multiset) other)
  515. BOOST_NOEXCEPT_IF(table::nothrow_move_constructible)
  516. : table_(other.table_, boost::unordered::detail::move_tag())
  517. {
  518. // The move is done in table_
  519. }
  520. #endif
  521. explicit unordered_multiset(allocator_type const&);
  522. unordered_multiset(unordered_multiset const&, allocator_type const&);
  523. unordered_multiset(
  524. BOOST_RV_REF(unordered_multiset), allocator_type const&);
  525. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  526. unordered_multiset(std::initializer_list<value_type>,
  527. size_type = boost::unordered::detail::default_bucket_count,
  528. const hasher& = hasher(), const key_equal& l = key_equal(),
  529. const allocator_type& = allocator_type());
  530. #endif
  531. explicit unordered_multiset(size_type, const allocator_type&);
  532. explicit unordered_multiset(
  533. size_type, const hasher&, const allocator_type&);
  534. template <class InputIt>
  535. unordered_multiset(InputIt, InputIt, size_type, const allocator_type&);
  536. template <class InputIt>
  537. unordered_multiset(
  538. InputIt, InputIt, size_type, const hasher&, const allocator_type&);
  539. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  540. unordered_multiset(
  541. std::initializer_list<value_type>, size_type, const allocator_type&);
  542. unordered_multiset(std::initializer_list<value_type>, size_type,
  543. const hasher&, const allocator_type&);
  544. #endif
  545. // Destructor
  546. ~unordered_multiset() BOOST_NOEXCEPT;
  547. // Assign
  548. #if defined(BOOST_UNORDERED_USE_MOVE)
  549. unordered_multiset& operator=(BOOST_COPY_ASSIGN_REF(unordered_multiset) x)
  550. {
  551. table_.assign(x.table_, boost::unordered::detail::false_type());
  552. return *this;
  553. }
  554. unordered_multiset& operator=(BOOST_RV_REF(unordered_multiset) x)
  555. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  556. boost::is_nothrow_move_assignable<H>::value&&
  557. boost::is_nothrow_move_assignable<P>::value)
  558. {
  559. table_.move_assign(x.table_, boost::unordered::detail::false_type());
  560. return *this;
  561. }
  562. #else
  563. unordered_multiset& operator=(unordered_multiset const& x)
  564. {
  565. table_.assign(x.table_, boost::unordered::detail::false_type());
  566. return *this;
  567. }
  568. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  569. unordered_multiset& operator=(unordered_multiset&& x)
  570. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  571. boost::is_nothrow_move_assignable<H>::value&&
  572. boost::is_nothrow_move_assignable<P>::value)
  573. {
  574. table_.move_assign(x.table_, boost::unordered::detail::false_type());
  575. return *this;
  576. }
  577. #endif
  578. #endif
  579. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  580. unordered_multiset& operator=(std::initializer_list<value_type>);
  581. #endif
  582. allocator_type get_allocator() const BOOST_NOEXCEPT
  583. {
  584. return table_.node_alloc();
  585. }
  586. // iterators
  587. iterator begin() BOOST_NOEXCEPT { return iterator(table_.begin()); }
  588. const_iterator begin() const BOOST_NOEXCEPT
  589. {
  590. return const_iterator(table_.begin());
  591. }
  592. iterator end() BOOST_NOEXCEPT { return iterator(); }
  593. const_iterator end() const BOOST_NOEXCEPT { return const_iterator(); }
  594. const_iterator cbegin() const BOOST_NOEXCEPT
  595. {
  596. return const_iterator(table_.begin());
  597. }
  598. const_iterator cend() const BOOST_NOEXCEPT { return const_iterator(); }
  599. // size and capacity
  600. bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; }
  601. size_type size() const BOOST_NOEXCEPT { return table_.size_; }
  602. size_type max_size() const BOOST_NOEXCEPT;
  603. // emplace
  604. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  605. template <class... Args> iterator emplace(BOOST_FWD_REF(Args)... args)
  606. {
  607. return iterator(table_.emplace_equiv(
  608. boost::unordered::detail::func::construct_node_from_args(
  609. table_.node_alloc(), boost::forward<Args>(args)...)));
  610. }
  611. #else
  612. #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
  613. // 0 argument emplace requires special treatment in case
  614. // the container is instantiated with a value type that
  615. // doesn't have a default constructor.
  616. iterator emplace(boost::unordered::detail::empty_emplace =
  617. boost::unordered::detail::empty_emplace(),
  618. value_type v = value_type())
  619. {
  620. return this->emplace(boost::move(v));
  621. }
  622. #endif
  623. template <typename A0> iterator emplace(BOOST_FWD_REF(A0) a0)
  624. {
  625. return iterator(table_.emplace_equiv(
  626. boost::unordered::detail::func::construct_node_from_args(
  627. table_.node_alloc(), boost::unordered::detail::create_emplace_args(
  628. boost::forward<A0>(a0)))));
  629. }
  630. template <typename A0, typename A1>
  631. iterator emplace(BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  632. {
  633. return iterator(table_.emplace_equiv(
  634. boost::unordered::detail::func::construct_node_from_args(
  635. table_.node_alloc(),
  636. boost::unordered::detail::create_emplace_args(
  637. boost::forward<A0>(a0), boost::forward<A1>(a1)))));
  638. }
  639. template <typename A0, typename A1, typename A2>
  640. iterator emplace(
  641. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  642. {
  643. return iterator(table_.emplace_equiv(
  644. boost::unordered::detail::func::construct_node_from_args(
  645. table_.node_alloc(),
  646. boost::unordered::detail::create_emplace_args(
  647. boost::forward<A0>(a0), boost::forward<A1>(a1),
  648. boost::forward<A2>(a2)))));
  649. }
  650. #endif
  651. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  652. template <class... Args>
  653. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
  654. {
  655. return iterator(table_.emplace_hint_equiv(
  656. hint, boost::unordered::detail::func::construct_node_from_args(
  657. table_.node_alloc(), boost::forward<Args>(args)...)));
  658. }
  659. #else
  660. #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
  661. iterator emplace_hint(const_iterator hint,
  662. boost::unordered::detail::empty_emplace =
  663. boost::unordered::detail::empty_emplace(),
  664. value_type v = value_type())
  665. {
  666. return this->emplace_hint(hint, boost::move(v));
  667. }
  668. #endif
  669. template <typename A0>
  670. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0)
  671. {
  672. return iterator(table_.emplace_hint_equiv(hint,
  673. boost::unordered::detail::func::construct_node_from_args(
  674. table_.node_alloc(), boost::unordered::detail::create_emplace_args(
  675. boost::forward<A0>(a0)))));
  676. }
  677. template <typename A0, typename A1>
  678. iterator emplace_hint(
  679. const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  680. {
  681. return iterator(table_.emplace_hint_equiv(
  682. hint, boost::unordered::detail::func::construct_node_from_args(
  683. table_.node_alloc(),
  684. boost::unordered::detail::create_emplace_args(
  685. boost::forward<A0>(a0), boost::forward<A1>(a1)))));
  686. }
  687. template <typename A0, typename A1, typename A2>
  688. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0,
  689. BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  690. {
  691. return iterator(table_.emplace_hint_equiv(
  692. hint, boost::unordered::detail::func::construct_node_from_args(
  693. table_.node_alloc(),
  694. boost::unordered::detail::create_emplace_args(
  695. boost::forward<A0>(a0), boost::forward<A1>(a1),
  696. boost::forward<A2>(a2)))));
  697. }
  698. #endif
  699. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  700. #define BOOST_UNORDERED_EMPLACE(z, n, _) \
  701. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  702. iterator emplace(BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  703. { \
  704. return iterator(table_.emplace_equiv( \
  705. boost::unordered::detail::func::construct_node_from_args( \
  706. table_.node_alloc(), \
  707. boost::unordered::detail::create_emplace_args( \
  708. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))))); \
  709. } \
  710. \
  711. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  712. iterator emplace_hint( \
  713. const_iterator hint, BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  714. { \
  715. return iterator(table_.emplace_hint_equiv( \
  716. hint, boost::unordered::detail::func::construct_node_from_args( \
  717. table_.node_alloc(), \
  718. boost::unordered::detail::create_emplace_args( \
  719. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))))); \
  720. }
  721. BOOST_UNORDERED_EMPLACE(1, 4, _)
  722. BOOST_UNORDERED_EMPLACE(1, 5, _)
  723. BOOST_UNORDERED_EMPLACE(1, 6, _)
  724. BOOST_UNORDERED_EMPLACE(1, 7, _)
  725. BOOST_UNORDERED_EMPLACE(1, 8, _)
  726. BOOST_UNORDERED_EMPLACE(1, 9, _)
  727. BOOST_PP_REPEAT_FROM_TO(10, BOOST_PP_INC(BOOST_UNORDERED_EMPLACE_LIMIT),
  728. BOOST_UNORDERED_EMPLACE, _)
  729. #undef BOOST_UNORDERED_EMPLACE
  730. #endif
  731. iterator insert(value_type const& x) { return this->emplace(x); }
  732. iterator insert(BOOST_UNORDERED_RV_REF(value_type) x)
  733. {
  734. return this->emplace(boost::move(x));
  735. }
  736. iterator insert(const_iterator hint, value_type const& x)
  737. {
  738. return this->emplace_hint(hint, x);
  739. }
  740. iterator insert(const_iterator hint, BOOST_UNORDERED_RV_REF(value_type) x)
  741. {
  742. return this->emplace_hint(hint, boost::move(x));
  743. }
  744. template <class InputIt> void insert(InputIt, InputIt);
  745. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  746. void insert(std::initializer_list<value_type>);
  747. #endif
  748. // extract
  749. node_type extract(const_iterator position)
  750. {
  751. return node_type(
  752. table_.extract_by_iterator_equiv(position), table_.node_alloc());
  753. }
  754. node_type extract(const key_type& k)
  755. {
  756. return node_type(table_.extract_by_key(k), table_.node_alloc());
  757. }
  758. iterator insert(BOOST_RV_REF(node_type) np)
  759. {
  760. return table_.move_insert_node_type_equiv(np);
  761. }
  762. iterator insert(const_iterator hint, BOOST_RV_REF(node_type) np)
  763. {
  764. return table_.move_insert_node_type_with_hint_equiv(hint, np);
  765. }
  766. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
  767. (BOOST_COMP_GNUC && BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(4, 6, 0))
  768. private:
  769. // Note: Use r-value node_type to insert.
  770. iterator insert(node_type&);
  771. iterator insert(const_iterator, node_type& np);
  772. public:
  773. #endif
  774. iterator erase(const_iterator);
  775. size_type erase(const key_type&);
  776. iterator erase(const_iterator, const_iterator);
  777. BOOST_UNORDERED_DEPRECATED("Use erase instead")
  778. void quick_erase(const_iterator it) { erase(it); }
  779. BOOST_UNORDERED_DEPRECATED("Use erase instead")
  780. void erase_return_void(const_iterator it) { erase(it); }
  781. void swap(unordered_multiset&)
  782. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  783. boost::is_nothrow_swappable<H>::value&&
  784. boost::is_nothrow_swappable<P>::value);
  785. void clear() BOOST_NOEXCEPT { table_.clear_impl(); }
  786. template <typename H2, typename P2>
  787. void merge(boost::unordered_multiset<T, H2, P2, A>& source);
  788. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  789. template <typename H2, typename P2>
  790. void merge(boost::unordered_multiset<T, H2, P2, A>&& source);
  791. #endif
  792. template <typename H2, typename P2>
  793. void merge(boost::unordered_set<T, H2, P2, A>& source);
  794. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  795. template <typename H2, typename P2>
  796. void merge(boost::unordered_set<T, H2, P2, A>&& source);
  797. #endif
  798. // observers
  799. hasher hash_function() const;
  800. key_equal key_eq() const;
  801. // lookup
  802. const_iterator find(const key_type&) const;
  803. template <class CompatibleKey, class CompatibleHash,
  804. class CompatiblePredicate>
  805. const_iterator find(CompatibleKey const&, CompatibleHash const&,
  806. CompatiblePredicate const&) const;
  807. size_type count(const key_type&) const;
  808. std::pair<const_iterator, const_iterator> equal_range(
  809. const key_type&) const;
  810. // bucket interface
  811. size_type bucket_count() const BOOST_NOEXCEPT
  812. {
  813. return table_.bucket_count_;
  814. }
  815. size_type max_bucket_count() const BOOST_NOEXCEPT
  816. {
  817. return table_.max_bucket_count();
  818. }
  819. size_type bucket_size(size_type) const;
  820. size_type bucket(const key_type& k) const
  821. {
  822. return table_.hash_to_bucket(table_.hash(k));
  823. }
  824. local_iterator begin(size_type n)
  825. {
  826. return local_iterator(table_.begin(n), n, table_.bucket_count_);
  827. }
  828. const_local_iterator begin(size_type n) const
  829. {
  830. return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
  831. }
  832. local_iterator end(size_type) { return local_iterator(); }
  833. const_local_iterator end(size_type) const
  834. {
  835. return const_local_iterator();
  836. }
  837. const_local_iterator cbegin(size_type n) const
  838. {
  839. return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
  840. }
  841. const_local_iterator cend(size_type) const
  842. {
  843. return const_local_iterator();
  844. }
  845. // hash policy
  846. float load_factor() const BOOST_NOEXCEPT;
  847. float max_load_factor() const BOOST_NOEXCEPT { return table_.mlf_; }
  848. void max_load_factor(float) BOOST_NOEXCEPT;
  849. void rehash(size_type);
  850. void reserve(size_type);
  851. #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582)
  852. friend bool operator==
  853. <T, H, P, A>(unordered_multiset const&, unordered_multiset const&);
  854. friend bool operator!=
  855. <T, H, P, A>(unordered_multiset const&, unordered_multiset const&);
  856. #endif
  857. }; // class template unordered_multiset
  858. #if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
  859. template <class InputIterator,
  860. class Hash =
  861. boost::hash<typename std::iterator_traits<InputIterator>::value_type>,
  862. class Pred =
  863. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  864. class Allocator = std::allocator<
  865. typename std::iterator_traits<InputIterator>::value_type> >
  866. unordered_multiset(InputIterator, InputIterator,
  867. std::size_t = boost::unordered::detail::default_bucket_count,
  868. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  869. ->unordered_multiset<
  870. typename std::iterator_traits<InputIterator>::value_type, Hash, Pred,
  871. Allocator>;
  872. template <class T, class Hash = boost::hash<T>,
  873. class Pred = std::equal_to<T>, class Allocator = std::allocator<T> >
  874. unordered_multiset(std::initializer_list<T>,
  875. std::size_t = boost::unordered::detail::default_bucket_count,
  876. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  877. ->unordered_multiset<T, Hash, Pred, Allocator>;
  878. template <class InputIterator, class Allocator>
  879. unordered_multiset(InputIterator, InputIterator, std::size_t, Allocator)
  880. ->unordered_multiset<
  881. typename std::iterator_traits<InputIterator>::value_type,
  882. boost::hash<typename std::iterator_traits<InputIterator>::value_type>,
  883. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  884. Allocator>;
  885. template <class InputIterator, class Hash, class Allocator>
  886. unordered_multiset(
  887. InputIterator, InputIterator, std::size_t, Hash, Allocator)
  888. ->unordered_multiset<
  889. typename std::iterator_traits<InputIterator>::value_type, Hash,
  890. std::equal_to<typename std::iterator_traits<InputIterator>::value_type>,
  891. Allocator>;
  892. template <class T, class Allocator>
  893. unordered_multiset(std::initializer_list<T>, std::size_t, Allocator)
  894. ->unordered_multiset<T, boost::hash<T>, std::equal_to<T>, Allocator>;
  895. template <class T, class Hash, class Allocator>
  896. unordered_multiset(std::initializer_list<T>, std::size_t, Hash, Allocator)
  897. ->unordered_multiset<T, Hash, std::equal_to<T>, Allocator>;
  898. #endif
  899. ////////////////////////////////////////////////////////////////////////////
  900. template <class T, class H, class P, class A>
  901. unordered_set<T, H, P, A>::unordered_set()
  902. : table_(boost::unordered::detail::default_bucket_count, hasher(),
  903. key_equal(), allocator_type())
  904. {
  905. }
  906. template <class T, class H, class P, class A>
  907. unordered_set<T, H, P, A>::unordered_set(size_type n, const hasher& hf,
  908. const key_equal& eql, const allocator_type& a)
  909. : table_(n, hf, eql, a)
  910. {
  911. }
  912. template <class T, class H, class P, class A>
  913. template <class InputIt>
  914. unordered_set<T, H, P, A>::unordered_set(InputIt f, InputIt l, size_type n,
  915. const hasher& hf, const key_equal& eql, const allocator_type& a)
  916. : table_(boost::unordered::detail::initial_size(f, l, n), hf, eql, a)
  917. {
  918. this->insert(f, l);
  919. }
  920. template <class T, class H, class P, class A>
  921. unordered_set<T, H, P, A>::unordered_set(unordered_set const& other)
  922. : table_(other.table_,
  923. unordered_set::value_allocator_traits::
  924. select_on_container_copy_construction(other.get_allocator()))
  925. {
  926. if (other.table_.size_) {
  927. table_.copy_buckets(
  928. other.table_, boost::unordered::detail::true_type());
  929. }
  930. }
  931. template <class T, class H, class P, class A>
  932. unordered_set<T, H, P, A>::unordered_set(allocator_type const& a)
  933. : table_(boost::unordered::detail::default_bucket_count, hasher(),
  934. key_equal(), a)
  935. {
  936. }
  937. template <class T, class H, class P, class A>
  938. unordered_set<T, H, P, A>::unordered_set(
  939. unordered_set const& other, allocator_type const& a)
  940. : table_(other.table_, a)
  941. {
  942. if (other.table_.size_) {
  943. table_.copy_buckets(
  944. other.table_, boost::unordered::detail::true_type());
  945. }
  946. }
  947. template <class T, class H, class P, class A>
  948. unordered_set<T, H, P, A>::unordered_set(
  949. BOOST_RV_REF(unordered_set) other, allocator_type const& a)
  950. : table_(other.table_, a, boost::unordered::detail::move_tag())
  951. {
  952. table_.move_construct_buckets(other.table_);
  953. }
  954. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  955. template <class T, class H, class P, class A>
  956. unordered_set<T, H, P, A>::unordered_set(
  957. std::initializer_list<value_type> list, size_type n, const hasher& hf,
  958. const key_equal& eql, const allocator_type& a)
  959. : table_(
  960. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  961. hf, eql, a)
  962. {
  963. this->insert(list.begin(), list.end());
  964. }
  965. #endif
  966. template <class T, class H, class P, class A>
  967. unordered_set<T, H, P, A>::unordered_set(
  968. size_type n, const allocator_type& a)
  969. : table_(n, hasher(), key_equal(), a)
  970. {
  971. }
  972. template <class T, class H, class P, class A>
  973. unordered_set<T, H, P, A>::unordered_set(
  974. size_type n, const hasher& hf, const allocator_type& a)
  975. : table_(n, hf, key_equal(), a)
  976. {
  977. }
  978. template <class T, class H, class P, class A>
  979. template <class InputIt>
  980. unordered_set<T, H, P, A>::unordered_set(
  981. InputIt f, InputIt l, size_type n, const allocator_type& a)
  982. : table_(boost::unordered::detail::initial_size(f, l, n), hasher(),
  983. key_equal(), a)
  984. {
  985. this->insert(f, l);
  986. }
  987. template <class T, class H, class P, class A>
  988. template <class InputIt>
  989. unordered_set<T, H, P, A>::unordered_set(InputIt f, InputIt l, size_type n,
  990. const hasher& hf, const allocator_type& a)
  991. : table_(
  992. boost::unordered::detail::initial_size(f, l, n), hf, key_equal(), a)
  993. {
  994. this->insert(f, l);
  995. }
  996. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  997. template <class T, class H, class P, class A>
  998. unordered_set<T, H, P, A>::unordered_set(
  999. std::initializer_list<value_type> list, size_type n,
  1000. const allocator_type& a)
  1001. : table_(
  1002. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1003. hasher(), key_equal(), a)
  1004. {
  1005. this->insert(list.begin(), list.end());
  1006. }
  1007. template <class T, class H, class P, class A>
  1008. unordered_set<T, H, P, A>::unordered_set(
  1009. std::initializer_list<value_type> list, size_type n, const hasher& hf,
  1010. const allocator_type& a)
  1011. : table_(
  1012. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1013. hf, key_equal(), a)
  1014. {
  1015. this->insert(list.begin(), list.end());
  1016. }
  1017. #endif
  1018. template <class T, class H, class P, class A>
  1019. unordered_set<T, H, P, A>::~unordered_set() BOOST_NOEXCEPT
  1020. {
  1021. }
  1022. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1023. template <class T, class H, class P, class A>
  1024. unordered_set<T, H, P, A>& unordered_set<T, H, P, A>::operator=(
  1025. std::initializer_list<value_type> list)
  1026. {
  1027. this->clear();
  1028. this->insert(list.begin(), list.end());
  1029. return *this;
  1030. }
  1031. #endif
  1032. // size and capacity
  1033. template <class T, class H, class P, class A>
  1034. std::size_t unordered_set<T, H, P, A>::max_size() const BOOST_NOEXCEPT
  1035. {
  1036. using namespace std;
  1037. // size < mlf_ * count
  1038. return boost::unordered::detail::double_to_size(
  1039. ceil(static_cast<double>(table_.mlf_) *
  1040. static_cast<double>(table_.max_bucket_count()))) -
  1041. 1;
  1042. }
  1043. // modifiers
  1044. template <class T, class H, class P, class A>
  1045. template <class InputIt>
  1046. void unordered_set<T, H, P, A>::insert(InputIt first, InputIt last)
  1047. {
  1048. if (first != last) {
  1049. table_.insert_range_unique(
  1050. table::extractor::extract(*first), first, last);
  1051. }
  1052. }
  1053. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1054. template <class T, class H, class P, class A>
  1055. void unordered_set<T, H, P, A>::insert(
  1056. std::initializer_list<value_type> list)
  1057. {
  1058. this->insert(list.begin(), list.end());
  1059. }
  1060. #endif
  1061. template <class T, class H, class P, class A>
  1062. typename unordered_set<T, H, P, A>::iterator
  1063. unordered_set<T, H, P, A>::erase(const_iterator position)
  1064. {
  1065. node_pointer node = table::get_node(position);
  1066. BOOST_ASSERT(node);
  1067. node_pointer next = table::next_node(node);
  1068. table_.erase_nodes_unique(node, next);
  1069. return iterator(next);
  1070. }
  1071. template <class T, class H, class P, class A>
  1072. typename unordered_set<T, H, P, A>::size_type
  1073. unordered_set<T, H, P, A>::erase(const key_type& k)
  1074. {
  1075. return table_.erase_key_unique(k);
  1076. }
  1077. template <class T, class H, class P, class A>
  1078. typename unordered_set<T, H, P, A>::iterator
  1079. unordered_set<T, H, P, A>::erase(const_iterator first, const_iterator last)
  1080. {
  1081. node_pointer last_node = table::get_node(last);
  1082. if (first == last)
  1083. return iterator(last_node);
  1084. table_.erase_nodes_unique(table::get_node(first), last_node);
  1085. return iterator(last_node);
  1086. }
  1087. template <class T, class H, class P, class A>
  1088. void unordered_set<T, H, P, A>::swap(unordered_set& other)
  1089. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  1090. boost::is_nothrow_swappable<H>::value&&
  1091. boost::is_nothrow_swappable<P>::value)
  1092. {
  1093. table_.swap(other.table_);
  1094. }
  1095. // observers
  1096. template <class T, class H, class P, class A>
  1097. typename unordered_set<T, H, P, A>::hasher
  1098. unordered_set<T, H, P, A>::hash_function() const
  1099. {
  1100. return table_.hash_function();
  1101. }
  1102. template <class T, class H, class P, class A>
  1103. typename unordered_set<T, H, P, A>::key_equal
  1104. unordered_set<T, H, P, A>::key_eq() const
  1105. {
  1106. return table_.key_eq();
  1107. }
  1108. template <class T, class H, class P, class A>
  1109. template <typename H2, typename P2>
  1110. void unordered_set<T, H, P, A>::merge(
  1111. boost::unordered_set<T, H2, P2, A>& source)
  1112. {
  1113. table_.merge_unique(source.table_);
  1114. }
  1115. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1116. template <class T, class H, class P, class A>
  1117. template <typename H2, typename P2>
  1118. void unordered_set<T, H, P, A>::merge(
  1119. boost::unordered_set<T, H2, P2, A>&& source)
  1120. {
  1121. table_.merge_unique(source.table_);
  1122. }
  1123. #endif
  1124. template <class T, class H, class P, class A>
  1125. template <typename H2, typename P2>
  1126. void unordered_set<T, H, P, A>::merge(
  1127. boost::unordered_multiset<T, H2, P2, A>& source)
  1128. {
  1129. table_.merge_unique(source.table_);
  1130. }
  1131. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1132. template <class T, class H, class P, class A>
  1133. template <typename H2, typename P2>
  1134. void unordered_set<T, H, P, A>::merge(
  1135. boost::unordered_multiset<T, H2, P2, A>&& source)
  1136. {
  1137. table_.merge_unique(source.table_);
  1138. }
  1139. #endif
  1140. // lookup
  1141. template <class T, class H, class P, class A>
  1142. typename unordered_set<T, H, P, A>::const_iterator
  1143. unordered_set<T, H, P, A>::find(const key_type& k) const
  1144. {
  1145. return const_iterator(table_.find_node(k));
  1146. }
  1147. template <class T, class H, class P, class A>
  1148. template <class CompatibleKey, class CompatibleHash,
  1149. class CompatiblePredicate>
  1150. typename unordered_set<T, H, P, A>::const_iterator
  1151. unordered_set<T, H, P, A>::find(CompatibleKey const& k,
  1152. CompatibleHash const& hash, CompatiblePredicate const& eq) const
  1153. {
  1154. return const_iterator(
  1155. table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq));
  1156. }
  1157. template <class T, class H, class P, class A>
  1158. typename unordered_set<T, H, P, A>::size_type
  1159. unordered_set<T, H, P, A>::count(const key_type& k) const
  1160. {
  1161. return table_.find_node(k) ? 1 : 0;
  1162. }
  1163. template <class T, class H, class P, class A>
  1164. std::pair<typename unordered_set<T, H, P, A>::const_iterator,
  1165. typename unordered_set<T, H, P, A>::const_iterator>
  1166. unordered_set<T, H, P, A>::equal_range(const key_type& k) const
  1167. {
  1168. node_pointer n = table_.find_node(k);
  1169. return std::make_pair(
  1170. const_iterator(n), const_iterator(n ? table::next_node(n) : n));
  1171. }
  1172. template <class T, class H, class P, class A>
  1173. typename unordered_set<T, H, P, A>::size_type
  1174. unordered_set<T, H, P, A>::bucket_size(size_type n) const
  1175. {
  1176. return table_.bucket_size(n);
  1177. }
  1178. // hash policy
  1179. template <class T, class H, class P, class A>
  1180. float unordered_set<T, H, P, A>::load_factor() const BOOST_NOEXCEPT
  1181. {
  1182. BOOST_ASSERT(table_.bucket_count_ != 0);
  1183. return static_cast<float>(table_.size_) /
  1184. static_cast<float>(table_.bucket_count_);
  1185. }
  1186. template <class T, class H, class P, class A>
  1187. void unordered_set<T, H, P, A>::max_load_factor(float m) BOOST_NOEXCEPT
  1188. {
  1189. table_.max_load_factor(m);
  1190. }
  1191. template <class T, class H, class P, class A>
  1192. void unordered_set<T, H, P, A>::rehash(size_type n)
  1193. {
  1194. table_.rehash(n);
  1195. }
  1196. template <class T, class H, class P, class A>
  1197. void unordered_set<T, H, P, A>::reserve(size_type n)
  1198. {
  1199. table_.rehash(static_cast<std::size_t>(
  1200. std::ceil(static_cast<double>(n) / table_.mlf_)));
  1201. }
  1202. template <class T, class H, class P, class A>
  1203. inline bool operator==(
  1204. unordered_set<T, H, P, A> const& m1, unordered_set<T, H, P, A> const& m2)
  1205. {
  1206. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1207. struct dummy
  1208. {
  1209. unordered_set<T, H, P, A> x;
  1210. };
  1211. #endif
  1212. return m1.table_.equals_unique(m2.table_);
  1213. }
  1214. template <class T, class H, class P, class A>
  1215. inline bool operator!=(
  1216. unordered_set<T, H, P, A> const& m1, unordered_set<T, H, P, A> const& m2)
  1217. {
  1218. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1219. struct dummy
  1220. {
  1221. unordered_set<T, H, P, A> x;
  1222. };
  1223. #endif
  1224. return !m1.table_.equals_unique(m2.table_);
  1225. }
  1226. template <class T, class H, class P, class A>
  1227. inline void swap(
  1228. unordered_set<T, H, P, A>& m1, unordered_set<T, H, P, A>& m2)
  1229. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(m1.swap(m2)))
  1230. {
  1231. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1232. struct dummy
  1233. {
  1234. unordered_set<T, H, P, A> x;
  1235. };
  1236. #endif
  1237. m1.swap(m2);
  1238. }
  1239. ////////////////////////////////////////////////////////////////////////////
  1240. template <class T, class H, class P, class A>
  1241. unordered_multiset<T, H, P, A>::unordered_multiset()
  1242. : table_(boost::unordered::detail::default_bucket_count, hasher(),
  1243. key_equal(), allocator_type())
  1244. {
  1245. }
  1246. template <class T, class H, class P, class A>
  1247. unordered_multiset<T, H, P, A>::unordered_multiset(size_type n,
  1248. const hasher& hf, const key_equal& eql, const allocator_type& a)
  1249. : table_(n, hf, eql, a)
  1250. {
  1251. }
  1252. template <class T, class H, class P, class A>
  1253. template <class InputIt>
  1254. unordered_multiset<T, H, P, A>::unordered_multiset(InputIt f, InputIt l,
  1255. size_type n, const hasher& hf, const key_equal& eql,
  1256. const allocator_type& a)
  1257. : table_(boost::unordered::detail::initial_size(f, l, n), hf, eql, a)
  1258. {
  1259. this->insert(f, l);
  1260. }
  1261. template <class T, class H, class P, class A>
  1262. unordered_multiset<T, H, P, A>::unordered_multiset(
  1263. unordered_multiset const& other)
  1264. : table_(other.table_,
  1265. unordered_multiset::value_allocator_traits::
  1266. select_on_container_copy_construction(other.get_allocator()))
  1267. {
  1268. if (other.table_.size_) {
  1269. table_.copy_buckets(
  1270. other.table_, boost::unordered::detail::false_type());
  1271. }
  1272. }
  1273. template <class T, class H, class P, class A>
  1274. unordered_multiset<T, H, P, A>::unordered_multiset(allocator_type const& a)
  1275. : table_(boost::unordered::detail::default_bucket_count, hasher(),
  1276. key_equal(), a)
  1277. {
  1278. }
  1279. template <class T, class H, class P, class A>
  1280. unordered_multiset<T, H, P, A>::unordered_multiset(
  1281. unordered_multiset const& other, allocator_type const& a)
  1282. : table_(other.table_, a)
  1283. {
  1284. if (other.table_.size_) {
  1285. table_.copy_buckets(
  1286. other.table_, boost::unordered::detail::false_type());
  1287. }
  1288. }
  1289. template <class T, class H, class P, class A>
  1290. unordered_multiset<T, H, P, A>::unordered_multiset(
  1291. BOOST_RV_REF(unordered_multiset) other, allocator_type const& a)
  1292. : table_(other.table_, a, boost::unordered::detail::move_tag())
  1293. {
  1294. table_.move_construct_buckets(other.table_);
  1295. }
  1296. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1297. template <class T, class H, class P, class A>
  1298. unordered_multiset<T, H, P, A>::unordered_multiset(
  1299. std::initializer_list<value_type> list, size_type n, const hasher& hf,
  1300. const key_equal& eql, const allocator_type& a)
  1301. : table_(
  1302. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1303. hf, eql, a)
  1304. {
  1305. this->insert(list.begin(), list.end());
  1306. }
  1307. #endif
  1308. template <class T, class H, class P, class A>
  1309. unordered_multiset<T, H, P, A>::unordered_multiset(
  1310. size_type n, const allocator_type& a)
  1311. : table_(n, hasher(), key_equal(), a)
  1312. {
  1313. }
  1314. template <class T, class H, class P, class A>
  1315. unordered_multiset<T, H, P, A>::unordered_multiset(
  1316. size_type n, const hasher& hf, const allocator_type& a)
  1317. : table_(n, hf, key_equal(), a)
  1318. {
  1319. }
  1320. template <class T, class H, class P, class A>
  1321. template <class InputIt>
  1322. unordered_multiset<T, H, P, A>::unordered_multiset(
  1323. InputIt f, InputIt l, size_type n, const allocator_type& a)
  1324. : table_(boost::unordered::detail::initial_size(f, l, n), hasher(),
  1325. key_equal(), a)
  1326. {
  1327. this->insert(f, l);
  1328. }
  1329. template <class T, class H, class P, class A>
  1330. template <class InputIt>
  1331. unordered_multiset<T, H, P, A>::unordered_multiset(InputIt f, InputIt l,
  1332. size_type n, const hasher& hf, const allocator_type& a)
  1333. : table_(
  1334. boost::unordered::detail::initial_size(f, l, n), hf, key_equal(), a)
  1335. {
  1336. this->insert(f, l);
  1337. }
  1338. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1339. template <class T, class H, class P, class A>
  1340. unordered_multiset<T, H, P, A>::unordered_multiset(
  1341. std::initializer_list<value_type> list, size_type n,
  1342. const allocator_type& a)
  1343. : table_(
  1344. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1345. hasher(), key_equal(), a)
  1346. {
  1347. this->insert(list.begin(), list.end());
  1348. }
  1349. template <class T, class H, class P, class A>
  1350. unordered_multiset<T, H, P, A>::unordered_multiset(
  1351. std::initializer_list<value_type> list, size_type n, const hasher& hf,
  1352. const allocator_type& a)
  1353. : table_(
  1354. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1355. hf, key_equal(), a)
  1356. {
  1357. this->insert(list.begin(), list.end());
  1358. }
  1359. #endif
  1360. template <class T, class H, class P, class A>
  1361. unordered_multiset<T, H, P, A>::~unordered_multiset() BOOST_NOEXCEPT
  1362. {
  1363. }
  1364. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1365. template <class T, class H, class P, class A>
  1366. unordered_multiset<T, H, P, A>& unordered_multiset<T, H, P, A>::operator=(
  1367. std::initializer_list<value_type> list)
  1368. {
  1369. this->clear();
  1370. this->insert(list.begin(), list.end());
  1371. return *this;
  1372. }
  1373. #endif
  1374. // size and capacity
  1375. template <class T, class H, class P, class A>
  1376. std::size_t unordered_multiset<T, H, P, A>::max_size() const BOOST_NOEXCEPT
  1377. {
  1378. using namespace std;
  1379. // size < mlf_ * count
  1380. return boost::unordered::detail::double_to_size(
  1381. ceil(static_cast<double>(table_.mlf_) *
  1382. static_cast<double>(table_.max_bucket_count()))) -
  1383. 1;
  1384. }
  1385. // modifiers
  1386. template <class T, class H, class P, class A>
  1387. template <class InputIt>
  1388. void unordered_multiset<T, H, P, A>::insert(InputIt first, InputIt last)
  1389. {
  1390. table_.insert_range_equiv(first, last);
  1391. }
  1392. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1393. template <class T, class H, class P, class A>
  1394. void unordered_multiset<T, H, P, A>::insert(
  1395. std::initializer_list<value_type> list)
  1396. {
  1397. this->insert(list.begin(), list.end());
  1398. }
  1399. #endif
  1400. template <class T, class H, class P, class A>
  1401. typename unordered_multiset<T, H, P, A>::iterator
  1402. unordered_multiset<T, H, P, A>::erase(const_iterator position)
  1403. {
  1404. node_pointer node = table::get_node(position);
  1405. BOOST_ASSERT(node);
  1406. node_pointer next = table::next_node(node);
  1407. table_.erase_nodes_equiv(node, next);
  1408. return iterator(next);
  1409. }
  1410. template <class T, class H, class P, class A>
  1411. typename unordered_multiset<T, H, P, A>::size_type
  1412. unordered_multiset<T, H, P, A>::erase(const key_type& k)
  1413. {
  1414. return table_.erase_key_equiv(k);
  1415. }
  1416. template <class T, class H, class P, class A>
  1417. typename unordered_multiset<T, H, P, A>::iterator
  1418. unordered_multiset<T, H, P, A>::erase(
  1419. const_iterator first, const_iterator last)
  1420. {
  1421. node_pointer last_node = table::get_node(last);
  1422. if (first == last)
  1423. return iterator(last_node);
  1424. table_.erase_nodes_equiv(table::get_node(first), last_node);
  1425. return iterator(last_node);
  1426. }
  1427. template <class T, class H, class P, class A>
  1428. void unordered_multiset<T, H, P, A>::swap(unordered_multiset& other)
  1429. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  1430. boost::is_nothrow_swappable<H>::value&&
  1431. boost::is_nothrow_swappable<P>::value)
  1432. {
  1433. table_.swap(other.table_);
  1434. }
  1435. // observers
  1436. template <class T, class H, class P, class A>
  1437. typename unordered_multiset<T, H, P, A>::hasher
  1438. unordered_multiset<T, H, P, A>::hash_function() const
  1439. {
  1440. return table_.hash_function();
  1441. }
  1442. template <class T, class H, class P, class A>
  1443. typename unordered_multiset<T, H, P, A>::key_equal
  1444. unordered_multiset<T, H, P, A>::key_eq() const
  1445. {
  1446. return table_.key_eq();
  1447. }
  1448. template <class T, class H, class P, class A>
  1449. template <typename H2, typename P2>
  1450. void unordered_multiset<T, H, P, A>::merge(
  1451. boost::unordered_multiset<T, H2, P2, A>& source)
  1452. {
  1453. while (!source.empty()) {
  1454. insert(source.extract(source.begin()));
  1455. }
  1456. }
  1457. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1458. template <class T, class H, class P, class A>
  1459. template <typename H2, typename P2>
  1460. void unordered_multiset<T, H, P, A>::merge(
  1461. boost::unordered_multiset<T, H2, P2, A>&& source)
  1462. {
  1463. while (!source.empty()) {
  1464. insert(source.extract(source.begin()));
  1465. }
  1466. }
  1467. #endif
  1468. template <class T, class H, class P, class A>
  1469. template <typename H2, typename P2>
  1470. void unordered_multiset<T, H, P, A>::merge(
  1471. boost::unordered_set<T, H2, P2, A>& source)
  1472. {
  1473. while (!source.empty()) {
  1474. insert(source.extract(source.begin()));
  1475. }
  1476. }
  1477. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1478. template <class T, class H, class P, class A>
  1479. template <typename H2, typename P2>
  1480. void unordered_multiset<T, H, P, A>::merge(
  1481. boost::unordered_set<T, H2, P2, A>&& source)
  1482. {
  1483. while (!source.empty()) {
  1484. insert(source.extract(source.begin()));
  1485. }
  1486. }
  1487. #endif
  1488. // lookup
  1489. template <class T, class H, class P, class A>
  1490. typename unordered_multiset<T, H, P, A>::const_iterator
  1491. unordered_multiset<T, H, P, A>::find(const key_type& k) const
  1492. {
  1493. return const_iterator(table_.find_node(k));
  1494. }
  1495. template <class T, class H, class P, class A>
  1496. template <class CompatibleKey, class CompatibleHash,
  1497. class CompatiblePredicate>
  1498. typename unordered_multiset<T, H, P, A>::const_iterator
  1499. unordered_multiset<T, H, P, A>::find(CompatibleKey const& k,
  1500. CompatibleHash const& hash, CompatiblePredicate const& eq) const
  1501. {
  1502. return const_iterator(
  1503. table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq));
  1504. }
  1505. template <class T, class H, class P, class A>
  1506. typename unordered_multiset<T, H, P, A>::size_type
  1507. unordered_multiset<T, H, P, A>::count(const key_type& k) const
  1508. {
  1509. node_pointer n = table_.find_node(k);
  1510. return n ? table_.group_count(n) : 0;
  1511. }
  1512. template <class T, class H, class P, class A>
  1513. std::pair<typename unordered_multiset<T, H, P, A>::const_iterator,
  1514. typename unordered_multiset<T, H, P, A>::const_iterator>
  1515. unordered_multiset<T, H, P, A>::equal_range(const key_type& k) const
  1516. {
  1517. node_pointer n = table_.find_node(k);
  1518. return std::make_pair(
  1519. const_iterator(n), const_iterator(n ? table_.next_group(n) : n));
  1520. }
  1521. template <class T, class H, class P, class A>
  1522. typename unordered_multiset<T, H, P, A>::size_type
  1523. unordered_multiset<T, H, P, A>::bucket_size(size_type n) const
  1524. {
  1525. return table_.bucket_size(n);
  1526. }
  1527. // hash policy
  1528. template <class T, class H, class P, class A>
  1529. float unordered_multiset<T, H, P, A>::load_factor() const BOOST_NOEXCEPT
  1530. {
  1531. BOOST_ASSERT(table_.bucket_count_ != 0);
  1532. return static_cast<float>(table_.size_) /
  1533. static_cast<float>(table_.bucket_count_);
  1534. }
  1535. template <class T, class H, class P, class A>
  1536. void unordered_multiset<T, H, P, A>::max_load_factor(float m) BOOST_NOEXCEPT
  1537. {
  1538. table_.max_load_factor(m);
  1539. }
  1540. template <class T, class H, class P, class A>
  1541. void unordered_multiset<T, H, P, A>::rehash(size_type n)
  1542. {
  1543. table_.rehash(n);
  1544. }
  1545. template <class T, class H, class P, class A>
  1546. void unordered_multiset<T, H, P, A>::reserve(size_type n)
  1547. {
  1548. table_.rehash(static_cast<std::size_t>(
  1549. std::ceil(static_cast<double>(n) / table_.mlf_)));
  1550. }
  1551. template <class T, class H, class P, class A>
  1552. inline bool operator==(unordered_multiset<T, H, P, A> const& m1,
  1553. unordered_multiset<T, H, P, A> const& m2)
  1554. {
  1555. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1556. struct dummy
  1557. {
  1558. unordered_multiset<T, H, P, A> x;
  1559. };
  1560. #endif
  1561. return m1.table_.equals_equiv(m2.table_);
  1562. }
  1563. template <class T, class H, class P, class A>
  1564. inline bool operator!=(unordered_multiset<T, H, P, A> const& m1,
  1565. unordered_multiset<T, H, P, A> const& m2)
  1566. {
  1567. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1568. struct dummy
  1569. {
  1570. unordered_multiset<T, H, P, A> x;
  1571. };
  1572. #endif
  1573. return !m1.table_.equals_equiv(m2.table_);
  1574. }
  1575. template <class T, class H, class P, class A>
  1576. inline void swap(
  1577. unordered_multiset<T, H, P, A>& m1, unordered_multiset<T, H, P, A>& m2)
  1578. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(m1.swap(m2)))
  1579. {
  1580. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1581. struct dummy
  1582. {
  1583. unordered_multiset<T, H, P, A> x;
  1584. };
  1585. #endif
  1586. m1.swap(m2);
  1587. }
  1588. template <typename N, typename T, typename A> class node_handle_set
  1589. {
  1590. BOOST_MOVABLE_BUT_NOT_COPYABLE(node_handle_set)
  1591. template <typename Types> friend struct ::boost::unordered::detail::table;
  1592. template <class T2, class H2, class P2, class A2>
  1593. friend class unordered_set;
  1594. template <class T2, class H2, class P2, class A2>
  1595. friend class unordered_multiset;
  1596. typedef typename boost::unordered::detail::rebind_wrap<A, T>::type
  1597. value_allocator;
  1598. typedef boost::unordered::detail::allocator_traits<value_allocator>
  1599. value_allocator_traits;
  1600. typedef N node;
  1601. typedef typename boost::unordered::detail::rebind_wrap<A, node>::type
  1602. node_allocator;
  1603. typedef boost::unordered::detail::allocator_traits<node_allocator>
  1604. node_allocator_traits;
  1605. typedef typename node_allocator_traits::pointer node_pointer;
  1606. public:
  1607. typedef T value_type;
  1608. typedef A allocator_type;
  1609. private:
  1610. node_pointer ptr_;
  1611. bool has_alloc_;
  1612. boost::unordered::detail::optional<value_allocator> alloc_;
  1613. node_handle_set(node_pointer ptr, allocator_type const& a)
  1614. : ptr_(ptr), alloc_(a)
  1615. {
  1616. }
  1617. public:
  1618. BOOST_CONSTEXPR node_handle_set() BOOST_NOEXCEPT : ptr_(),
  1619. has_alloc_(false)
  1620. {
  1621. }
  1622. ~node_handle_set()
  1623. {
  1624. if (ptr_) {
  1625. node_allocator node_alloc(*alloc_);
  1626. boost::unordered::detail::node_tmp<node_allocator> tmp(
  1627. ptr_, node_alloc);
  1628. }
  1629. }
  1630. node_handle_set(BOOST_RV_REF(node_handle_set) n) BOOST_NOEXCEPT
  1631. : ptr_(n.ptr_),
  1632. alloc_(boost::move(n.alloc_))
  1633. {
  1634. n.ptr_ = node_pointer();
  1635. }
  1636. node_handle_set& operator=(BOOST_RV_REF(node_handle_set) n)
  1637. {
  1638. BOOST_ASSERT(!alloc_.has_value() ||
  1639. value_allocator_traits::
  1640. propagate_on_container_move_assignment::value ||
  1641. (n.alloc_.has_value() && alloc_ == n.alloc_));
  1642. if (ptr_) {
  1643. node_allocator node_alloc(*alloc_);
  1644. boost::unordered::detail::node_tmp<node_allocator> tmp(
  1645. ptr_, node_alloc);
  1646. ptr_ = node_pointer();
  1647. }
  1648. if (!alloc_.has_value() ||
  1649. value_allocator_traits::propagate_on_container_move_assignment::
  1650. value) {
  1651. alloc_ = boost::move(n.alloc_);
  1652. }
  1653. ptr_ = n.ptr_;
  1654. n.ptr_ = node_pointer();
  1655. return *this;
  1656. }
  1657. value_type& value() const { return ptr_->value(); }
  1658. allocator_type get_allocator() const { return *alloc_; }
  1659. BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
  1660. bool operator!() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; }
  1661. bool empty() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; }
  1662. void swap(node_handle_set& n) BOOST_NOEXCEPT_IF(
  1663. value_allocator_traits::propagate_on_container_swap::value ||
  1664. value_allocator_traits::is_always_equal::value)
  1665. {
  1666. BOOST_ASSERT(
  1667. !alloc_.has_value() || !n.alloc_.has_value() ||
  1668. value_allocator_traits::propagate_on_container_swap::value ||
  1669. alloc_ == n.alloc_);
  1670. if (value_allocator_traits::propagate_on_container_swap::value ||
  1671. !alloc_.has_value() || !n.alloc_.has_value()) {
  1672. boost::swap(alloc_, n.alloc_);
  1673. }
  1674. boost::swap(ptr_, n.ptr_);
  1675. }
  1676. };
  1677. template <typename N, typename T, typename A>
  1678. void swap(node_handle_set<N, T, A>& x, node_handle_set<N, T, A>& y)
  1679. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(x.swap(y)))
  1680. {
  1681. x.swap(y);
  1682. }
  1683. template <typename N, typename T, typename A> struct insert_return_type_set
  1684. {
  1685. private:
  1686. BOOST_MOVABLE_BUT_NOT_COPYABLE(insert_return_type_set)
  1687. typedef typename boost::unordered::detail::rebind_wrap<A, T>::type
  1688. value_allocator;
  1689. typedef N node_;
  1690. public:
  1691. bool inserted;
  1692. boost::unordered::iterator_detail::c_iterator<node_> position;
  1693. boost::unordered::node_handle_set<N, T, A> node;
  1694. insert_return_type_set() : inserted(false), position(), node() {}
  1695. insert_return_type_set(BOOST_RV_REF(insert_return_type_set)
  1696. x) BOOST_NOEXCEPT : inserted(x.inserted),
  1697. position(x.position),
  1698. node(boost::move(x.node))
  1699. {
  1700. }
  1701. insert_return_type_set& operator=(BOOST_RV_REF(insert_return_type_set) x)
  1702. {
  1703. inserted = x.inserted;
  1704. position = x.position;
  1705. node = boost::move(x.node);
  1706. return *this;
  1707. }
  1708. };
  1709. template <typename N, typename T, typename A>
  1710. void swap(
  1711. insert_return_type_set<N, T, A>& x, insert_return_type_set<N, T, A>& y)
  1712. {
  1713. boost::swap(x.node, y.node);
  1714. boost::swap(x.inserted, y.inserted);
  1715. boost::swap(x.position, y.position);
  1716. }
  1717. } // namespace unordered
  1718. } // namespace boost
  1719. #if defined(BOOST_MSVC)
  1720. #pragma warning(pop)
  1721. #endif
  1722. #endif // BOOST_UNORDERED_UNORDERED_SET_HPP_INCLUDED