unordered_set.hpp 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101
  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