unordered_map.hpp 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590
  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_MAP_HPP_INCLUDED
  7. #define BOOST_UNORDERED_UNORDERED_MAP_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/type_traits/is_constructible.hpp>
  16. #include <boost/unordered/detail/map.hpp>
  17. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  18. #include <initializer_list>
  19. #endif
  20. #if defined(BOOST_MSVC)
  21. #pragma warning(push)
  22. // conditional expression is constant
  23. #pragma warning(disable : 4127)
  24. #if BOOST_MSVC >= 1400
  25. // the inline specifier cannot be used when a friend declaration refers to a
  26. // specialization of a function template
  27. #pragma warning(disable : 4396)
  28. #endif
  29. #endif
  30. namespace boost {
  31. namespace unordered {
  32. template <class K, class T, class H, class P, class A> class unordered_map
  33. {
  34. #if defined(BOOST_UNORDERED_USE_MOVE)
  35. BOOST_COPYABLE_AND_MOVABLE(unordered_map)
  36. #endif
  37. template <typename, typename, typename, typename, typename>
  38. friend class unordered_multimap;
  39. public:
  40. typedef K key_type;
  41. typedef T mapped_type;
  42. typedef std::pair<const K, T> value_type;
  43. typedef H hasher;
  44. typedef P key_equal;
  45. typedef A allocator_type;
  46. private:
  47. typedef boost::unordered::detail::map<A, K, T, H, P> types;
  48. typedef typename types::value_allocator_traits value_allocator_traits;
  49. typedef typename types::table table;
  50. typedef typename table::node_pointer node_pointer;
  51. typedef typename table::link_pointer link_pointer;
  52. public:
  53. typedef typename value_allocator_traits::pointer pointer;
  54. typedef typename value_allocator_traits::const_pointer const_pointer;
  55. typedef value_type& reference;
  56. typedef value_type const& const_reference;
  57. typedef std::size_t size_type;
  58. typedef std::ptrdiff_t difference_type;
  59. typedef typename table::iterator iterator;
  60. typedef typename table::c_iterator const_iterator;
  61. typedef typename table::l_iterator local_iterator;
  62. typedef typename table::cl_iterator const_local_iterator;
  63. typedef typename types::node_type node_type;
  64. typedef typename types::insert_return_type insert_return_type;
  65. private:
  66. table table_;
  67. public:
  68. // constructors
  69. unordered_map();
  70. explicit unordered_map(size_type, const hasher& = hasher(),
  71. const key_equal& = key_equal(),
  72. const allocator_type& = allocator_type());
  73. template <class InputIt>
  74. unordered_map(InputIt, InputIt,
  75. size_type = boost::unordered::detail::default_bucket_count,
  76. const hasher& = hasher(), const key_equal& = key_equal(),
  77. const allocator_type& = allocator_type());
  78. unordered_map(unordered_map const&);
  79. #if defined(BOOST_UNORDERED_USE_MOVE) || \
  80. !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  81. unordered_map(BOOST_RV_REF(unordered_map) other)
  82. BOOST_NOEXCEPT_IF(table::nothrow_move_constructible)
  83. : table_(other.table_, boost::unordered::detail::move_tag())
  84. {
  85. // The move is done in table_
  86. }
  87. #endif
  88. explicit unordered_map(allocator_type const&);
  89. unordered_map(unordered_map const&, allocator_type const&);
  90. unordered_map(BOOST_RV_REF(unordered_map), allocator_type const&);
  91. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  92. unordered_map(std::initializer_list<value_type>,
  93. size_type = boost::unordered::detail::default_bucket_count,
  94. const hasher& = hasher(), const key_equal& l = key_equal(),
  95. const allocator_type& = allocator_type());
  96. #endif
  97. explicit unordered_map(size_type, const allocator_type&);
  98. explicit unordered_map(size_type, const hasher&, const allocator_type&);
  99. template <class InputIt>
  100. unordered_map(InputIt, InputIt, size_type, const allocator_type&);
  101. template <class InputIt>
  102. unordered_map(
  103. InputIt, InputIt, size_type, const hasher&, const allocator_type&);
  104. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  105. unordered_map(
  106. std::initializer_list<value_type>, size_type, const allocator_type&);
  107. unordered_map(std::initializer_list<value_type>, size_type, const hasher&,
  108. const allocator_type&);
  109. #endif
  110. // Destructor
  111. ~unordered_map() BOOST_NOEXCEPT;
  112. // Assign
  113. #if defined(BOOST_UNORDERED_USE_MOVE)
  114. unordered_map& operator=(BOOST_COPY_ASSIGN_REF(unordered_map) x)
  115. {
  116. table_.assign(x.table_, boost::unordered::detail::true_type());
  117. return *this;
  118. }
  119. unordered_map& operator=(BOOST_RV_REF(unordered_map) x)
  120. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  121. boost::is_nothrow_move_assignable<H>::value&&
  122. boost::is_nothrow_move_assignable<P>::value)
  123. {
  124. table_.move_assign(x.table_, boost::unordered::detail::true_type());
  125. return *this;
  126. }
  127. #else
  128. unordered_map& operator=(unordered_map const& x)
  129. {
  130. table_.assign(x.table_, boost::unordered::detail::true_type());
  131. return *this;
  132. }
  133. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  134. unordered_map& operator=(unordered_map&& x)
  135. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  136. boost::is_nothrow_move_assignable<H>::value&&
  137. boost::is_nothrow_move_assignable<P>::value)
  138. {
  139. table_.move_assign(x.table_, boost::unordered::detail::true_type());
  140. return *this;
  141. }
  142. #endif
  143. #endif
  144. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  145. unordered_map& operator=(std::initializer_list<value_type>);
  146. #endif
  147. allocator_type get_allocator() const BOOST_NOEXCEPT
  148. {
  149. return table_.node_alloc();
  150. }
  151. // iterators
  152. iterator begin() BOOST_NOEXCEPT { return iterator(table_.begin()); }
  153. const_iterator begin() const BOOST_NOEXCEPT
  154. {
  155. return const_iterator(table_.begin());
  156. }
  157. iterator end() BOOST_NOEXCEPT { return iterator(); }
  158. const_iterator end() const BOOST_NOEXCEPT { return const_iterator(); }
  159. const_iterator cbegin() const BOOST_NOEXCEPT
  160. {
  161. return const_iterator(table_.begin());
  162. }
  163. const_iterator cend() const BOOST_NOEXCEPT { return const_iterator(); }
  164. // size and capacity
  165. bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; }
  166. size_type size() const BOOST_NOEXCEPT { return table_.size_; }
  167. size_type max_size() const BOOST_NOEXCEPT;
  168. // emplace
  169. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  170. template <class... Args>
  171. std::pair<iterator, bool> emplace(BOOST_FWD_REF(Args)... args)
  172. {
  173. return table_.emplace_unique(
  174. table::extractor::extract(boost::forward<Args>(args)...),
  175. boost::forward<Args>(args)...);
  176. }
  177. #else
  178. #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
  179. // 0 argument emplace requires special treatment in case
  180. // the container is instantiated with a value type that
  181. // doesn't have a default constructor.
  182. std::pair<iterator, bool> emplace(
  183. boost::unordered::detail::empty_emplace =
  184. boost::unordered::detail::empty_emplace(),
  185. value_type v = value_type())
  186. {
  187. return this->emplace(boost::move(v));
  188. }
  189. #endif
  190. template <typename A0>
  191. std::pair<iterator, bool> emplace(BOOST_FWD_REF(A0) a0)
  192. {
  193. return table_.emplace_unique(
  194. table::extractor::extract(boost::forward<A0>(a0)),
  195. boost::unordered::detail::create_emplace_args(
  196. boost::forward<A0>(a0)));
  197. }
  198. template <typename A0, typename A1>
  199. std::pair<iterator, bool> emplace(
  200. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  201. {
  202. return table_.emplace_unique(
  203. table::extractor::extract(
  204. boost::forward<A0>(a0), boost::forward<A1>(a1)),
  205. boost::unordered::detail::create_emplace_args(
  206. boost::forward<A0>(a0), boost::forward<A1>(a1)));
  207. }
  208. template <typename A0, typename A1, typename A2>
  209. std::pair<iterator, bool> emplace(
  210. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  211. {
  212. return table_.emplace_unique(
  213. table::extractor::extract(
  214. boost::forward<A0>(a0), boost::forward<A1>(a1)),
  215. boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
  216. boost::forward<A1>(a1), boost::forward<A2>(a2)));
  217. }
  218. #endif
  219. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  220. template <class... Args>
  221. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
  222. {
  223. return table_.emplace_hint_unique(hint,
  224. table::extractor::extract(boost::forward<Args>(args)...),
  225. boost::forward<Args>(args)...);
  226. }
  227. #else
  228. #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
  229. iterator emplace_hint(const_iterator hint,
  230. boost::unordered::detail::empty_emplace =
  231. boost::unordered::detail::empty_emplace(),
  232. value_type v = value_type())
  233. {
  234. return this->emplace_hint(hint, boost::move(v));
  235. }
  236. #endif
  237. template <typename A0>
  238. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0)
  239. {
  240. return table_.emplace_hint_unique(hint,
  241. table::extractor::extract(boost::forward<A0>(a0)),
  242. boost::unordered::detail::create_emplace_args(
  243. boost::forward<A0>(a0)));
  244. }
  245. template <typename A0, typename A1>
  246. iterator emplace_hint(
  247. const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  248. {
  249. return table_.emplace_hint_unique(hint,
  250. table::extractor::extract(
  251. boost::forward<A0>(a0), boost::forward<A1>(a1)),
  252. boost::unordered::detail::create_emplace_args(
  253. boost::forward<A0>(a0), boost::forward<A1>(a1)));
  254. }
  255. template <typename A0, typename A1, typename A2>
  256. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0,
  257. BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  258. {
  259. return table_.emplace_hint_unique(hint,
  260. table::extractor::extract(
  261. boost::forward<A0>(a0), boost::forward<A1>(a1)),
  262. boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
  263. boost::forward<A1>(a1), boost::forward<A2>(a2)));
  264. }
  265. #endif
  266. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  267. #define BOOST_UNORDERED_EMPLACE(z, n, _) \
  268. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  269. std::pair<iterator, bool> emplace( \
  270. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  271. { \
  272. return table_.emplace_unique( \
  273. table::extractor::extract( \
  274. boost::forward<A0>(a0), boost::forward<A1>(a1)), \
  275. boost::unordered::detail::create_emplace_args( \
  276. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
  277. } \
  278. \
  279. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  280. iterator emplace_hint( \
  281. const_iterator hint, BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  282. { \
  283. return table_.emplace_hint_unique(hint, \
  284. table::extractor::extract( \
  285. boost::forward<A0>(a0), boost::forward<A1>(a1)), \
  286. boost::unordered::detail::create_emplace_args( \
  287. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
  288. }
  289. BOOST_UNORDERED_EMPLACE(1, 4, _)
  290. BOOST_UNORDERED_EMPLACE(1, 5, _)
  291. BOOST_UNORDERED_EMPLACE(1, 6, _)
  292. BOOST_UNORDERED_EMPLACE(1, 7, _)
  293. BOOST_UNORDERED_EMPLACE(1, 8, _)
  294. BOOST_UNORDERED_EMPLACE(1, 9, _)
  295. BOOST_PP_REPEAT_FROM_TO(10, BOOST_PP_INC(BOOST_UNORDERED_EMPLACE_LIMIT),
  296. BOOST_UNORDERED_EMPLACE, _)
  297. #undef BOOST_UNORDERED_EMPLACE
  298. #endif
  299. std::pair<iterator, bool> insert(value_type const& x)
  300. {
  301. return this->emplace(x);
  302. }
  303. std::pair<iterator, bool> insert(BOOST_RV_REF(value_type) x)
  304. {
  305. return this->emplace(boost::move(x));
  306. }
  307. template <class P2>
  308. std::pair<iterator, bool> insert(BOOST_RV_REF(P2) obj,
  309. typename boost::enable_if_c<
  310. boost::is_constructible<value_type, BOOST_RV_REF(P2)>::value,
  311. void*>::type = 0)
  312. {
  313. return this->emplace(boost::forward<P2>(obj));
  314. }
  315. iterator insert(const_iterator hint, value_type const& x)
  316. {
  317. return this->emplace_hint(hint, x);
  318. }
  319. iterator insert(const_iterator hint, BOOST_RV_REF(value_type) x)
  320. {
  321. return this->emplace_hint(hint, boost::move(x));
  322. }
  323. template <class P2>
  324. iterator insert(const_iterator hint, BOOST_RV_REF(P2) obj,
  325. typename boost::enable_if_c<
  326. boost::is_constructible<value_type, BOOST_RV_REF(P2)>::value,
  327. void*>::type = 0)
  328. {
  329. return this->emplace_hint(hint, boost::forward<P2>(obj));
  330. }
  331. template <class InputIt> void insert(InputIt, InputIt);
  332. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  333. void insert(std::initializer_list<value_type>);
  334. #endif
  335. // extract
  336. node_type extract(const_iterator position)
  337. {
  338. return node_type(
  339. table_.extract_by_iterator_unique(position), table_.node_alloc());
  340. }
  341. node_type extract(const key_type& k)
  342. {
  343. return node_type(table_.extract_by_key(k), table_.node_alloc());
  344. }
  345. insert_return_type insert(BOOST_RV_REF(node_type) np)
  346. {
  347. insert_return_type result;
  348. table_.move_insert_node_type_unique(np, result);
  349. return boost::move(result);
  350. }
  351. iterator insert(const_iterator hint, BOOST_RV_REF(node_type) np)
  352. {
  353. return table_.move_insert_node_type_with_hint_unique(hint, np);
  354. }
  355. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
  356. (BOOST_COMP_GNUC && BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(4, 6, 0))
  357. private:
  358. // Note: Use r-value node_type to insert.
  359. insert_return_type insert(node_type&);
  360. iterator insert(const_iterator, node_type& np);
  361. public:
  362. #endif
  363. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  364. template <class... Args>
  365. std::pair<iterator, bool> try_emplace(
  366. key_type const& k, BOOST_FWD_REF(Args)... args)
  367. {
  368. return table_.try_emplace_unique(k, boost::forward<Args>(args)...);
  369. }
  370. template <class... Args>
  371. std::pair<iterator, bool> try_emplace(
  372. BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
  373. {
  374. return table_.try_emplace_unique(
  375. boost::move(k), boost::forward<Args>(args)...);
  376. }
  377. template <class... Args>
  378. iterator try_emplace(
  379. const_iterator hint, key_type const& k, BOOST_FWD_REF(Args)... args)
  380. {
  381. return table_.try_emplace_hint_unique(
  382. hint, k, boost::forward<Args>(args)...);
  383. }
  384. template <class... Args>
  385. iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k,
  386. BOOST_FWD_REF(Args)... args)
  387. {
  388. return table_.try_emplace_hint_unique(
  389. hint, boost::move(k), boost::forward<Args>(args)...);
  390. }
  391. #else
  392. // In order to make this a template, this handles both:
  393. // try_emplace(key const&)
  394. // try_emplace(key&&)
  395. template <typename Key>
  396. std::pair<iterator, bool> try_emplace(BOOST_FWD_REF(Key) k)
  397. {
  398. return table_.try_emplace_unique(boost::forward<Key>(k));
  399. }
  400. // In order to make this a template, this handles both:
  401. // try_emplace(const_iterator hint, key const&)
  402. // try_emplace(const_iterator hint, key&&)
  403. template <typename Key>
  404. iterator try_emplace(const_iterator hint, BOOST_FWD_REF(Key) k)
  405. {
  406. return table_.try_emplace_hint_unique(hint, boost::forward<Key>(k));
  407. }
  408. // try_emplace(key const&, Args&&...)
  409. template <typename A0>
  410. std::pair<iterator, bool> try_emplace(
  411. key_type const& k, BOOST_FWD_REF(A0) a0)
  412. {
  413. return table_.try_emplace_unique(
  414. k, boost::unordered::detail::create_emplace_args(
  415. boost::forward<A0>(a0)));
  416. }
  417. template <typename A0, typename A1>
  418. std::pair<iterator, bool> try_emplace(
  419. key_type const& k, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  420. {
  421. return table_.try_emplace_unique(
  422. k, boost::unordered::detail::create_emplace_args(
  423. boost::forward<A0>(a0), boost::forward<A1>(a1)));
  424. }
  425. template <typename A0, typename A1, typename A2>
  426. std::pair<iterator, bool> try_emplace(key_type const& k,
  427. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  428. {
  429. return table_.try_emplace_unique(k,
  430. boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
  431. boost::forward<A1>(a1), boost::forward<A2>(a2)));
  432. }
  433. // try_emplace(key&&, Args&&...)
  434. template <typename A0>
  435. std::pair<iterator, bool> try_emplace(
  436. BOOST_RV_REF(key_type) k, BOOST_FWD_REF(A0) a0)
  437. {
  438. return table_.try_emplace_unique(
  439. boost::move(k), boost::unordered::detail::create_emplace_args(
  440. boost::forward<A0>(a0)));
  441. }
  442. template <typename A0, typename A1>
  443. std::pair<iterator, bool> try_emplace(
  444. BOOST_RV_REF(key_type) k, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  445. {
  446. return table_.try_emplace_unique(
  447. boost::move(k), boost::unordered::detail::create_emplace_args(
  448. boost::forward<A0>(a0), boost::forward<A1>(a1)));
  449. }
  450. template <typename A0, typename A1, typename A2>
  451. std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k,
  452. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  453. {
  454. return table_.try_emplace_unique(boost::move(k),
  455. boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
  456. boost::forward<A1>(a1), boost::forward<A2>(a2)));
  457. }
  458. // try_emplace(const_iterator hint, key const&, Args&&...)
  459. template <typename A0>
  460. iterator try_emplace(
  461. const_iterator hint, key_type const& k, BOOST_FWD_REF(A0) a0)
  462. {
  463. return table_.try_emplace_hint_unique(
  464. hint, k, boost::unordered::detail::create_emplace_args(
  465. boost::forward<A0>(a0)));
  466. }
  467. template <typename A0, typename A1>
  468. iterator try_emplace(const_iterator hint, key_type const& k,
  469. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  470. {
  471. return table_.try_emplace_hint_unique(
  472. hint, k, boost::unordered::detail::create_emplace_args(
  473. boost::forward<A0>(a0), boost::forward<A1>(a1)));
  474. }
  475. template <typename A0, typename A1, typename A2>
  476. iterator try_emplace(const_iterator hint, key_type const& k,
  477. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  478. {
  479. return table_.try_emplace_hint_unique(hint, k,
  480. boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
  481. boost::forward<A1>(a1), boost::forward<A2>(a2)));
  482. }
  483. // try_emplace(const_iterator hint, key&&, Args&&...)
  484. template <typename A0>
  485. iterator try_emplace(
  486. const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(A0) a0)
  487. {
  488. return table_.try_emplace_hint_unique(
  489. hint, boost::move(k), boost::unordered::detail::create_emplace_args(
  490. boost::forward<A0>(a0)));
  491. }
  492. template <typename A0, typename A1>
  493. iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k,
  494. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  495. {
  496. return table_.try_emplace_hint_unique(hint, boost::move(k),
  497. boost::unordered::detail::create_emplace_args(
  498. boost::forward<A0>(a0), boost::forward<A1>(a1)));
  499. }
  500. template <typename A0, typename A1, typename A2>
  501. iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k,
  502. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  503. {
  504. return table_.try_emplace_hint_unique(hint, boost::move(k),
  505. boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
  506. boost::forward<A1>(a1), boost::forward<A2>(a2)));
  507. }
  508. #define BOOST_UNORDERED_TRY_EMPLACE(z, n, _) \
  509. \
  510. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  511. std::pair<iterator, bool> try_emplace( \
  512. key_type const& k, BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  513. { \
  514. return table_.try_emplace_unique( \
  515. k, boost::unordered::detail::create_emplace_args( \
  516. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
  517. } \
  518. \
  519. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  520. std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k, \
  521. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  522. { \
  523. return table_.try_emplace_unique(boost::move(k), \
  524. boost::unordered::detail::create_emplace_args( \
  525. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
  526. } \
  527. \
  528. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  529. iterator try_emplace(const_iterator hint, key_type const& k, \
  530. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  531. { \
  532. return table_.try_emplace_hint_unique( \
  533. hint, k, boost::unordered::detail::create_emplace_args( \
  534. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
  535. } \
  536. \
  537. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  538. iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k, \
  539. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  540. { \
  541. return table_.try_emplace_hint_unique(hint, boost::move(k), \
  542. boost::unordered::detail::create_emplace_args( \
  543. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
  544. }
  545. BOOST_UNORDERED_TRY_EMPLACE(1, 4, _)
  546. BOOST_UNORDERED_TRY_EMPLACE(1, 5, _)
  547. BOOST_UNORDERED_TRY_EMPLACE(1, 6, _)
  548. BOOST_UNORDERED_TRY_EMPLACE(1, 7, _)
  549. BOOST_UNORDERED_TRY_EMPLACE(1, 8, _)
  550. BOOST_UNORDERED_TRY_EMPLACE(1, 9, _)
  551. BOOST_PP_REPEAT_FROM_TO(10, BOOST_PP_INC(BOOST_UNORDERED_EMPLACE_LIMIT),
  552. BOOST_UNORDERED_TRY_EMPLACE, _)
  553. #undef BOOST_UNORDERED_TRY_EMPLACE
  554. #endif
  555. template <class M>
  556. std::pair<iterator, bool> insert_or_assign(
  557. key_type const& k, BOOST_FWD_REF(M) obj)
  558. {
  559. return table_.insert_or_assign_unique(k, boost::forward<M>(obj));
  560. }
  561. template <class M>
  562. std::pair<iterator, bool> insert_or_assign(
  563. BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
  564. {
  565. return table_.insert_or_assign_unique(
  566. boost::move(k), boost::forward<M>(obj));
  567. }
  568. template <class M>
  569. iterator insert_or_assign(
  570. const_iterator, key_type const& k, BOOST_FWD_REF(M) obj)
  571. {
  572. return table_.insert_or_assign_unique(k, boost::forward<M>(obj)).first;
  573. }
  574. template <class M>
  575. iterator insert_or_assign(
  576. const_iterator, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
  577. {
  578. return table_
  579. .insert_or_assign_unique(boost::move(k), boost::forward<M>(obj))
  580. .first;
  581. }
  582. iterator erase(iterator);
  583. iterator erase(const_iterator);
  584. size_type erase(const key_type&);
  585. iterator erase(const_iterator, const_iterator);
  586. BOOST_UNORDERED_DEPRECATED("Use erase instead")
  587. void quick_erase(const_iterator it) { erase(it); }
  588. BOOST_UNORDERED_DEPRECATED("Use erase instead")
  589. void erase_return_void(const_iterator it) { erase(it); }
  590. void swap(unordered_map&)
  591. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  592. boost::is_nothrow_swappable<H>::value&&
  593. boost::is_nothrow_swappable<P>::value);
  594. void clear() BOOST_NOEXCEPT { table_.clear_impl(); }
  595. template <typename H2, typename P2>
  596. void merge(boost::unordered_map<K, T, H2, P2, A>& source);
  597. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  598. template <typename H2, typename P2>
  599. void merge(boost::unordered_map<K, T, H2, P2, A>&& source);
  600. #endif
  601. template <typename H2, typename P2>
  602. void merge(boost::unordered_multimap<K, T, H2, P2, A>& source);
  603. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  604. template <typename H2, typename P2>
  605. void merge(boost::unordered_multimap<K, T, H2, P2, A>&& source);
  606. #endif
  607. // observers
  608. hasher hash_function() const;
  609. key_equal key_eq() const;
  610. // lookup
  611. iterator find(const key_type&);
  612. const_iterator find(const key_type&) const;
  613. template <class CompatibleKey, class CompatibleHash,
  614. class CompatiblePredicate>
  615. iterator find(CompatibleKey const&, CompatibleHash const&,
  616. CompatiblePredicate const&);
  617. template <class CompatibleKey, class CompatibleHash,
  618. class CompatiblePredicate>
  619. const_iterator find(CompatibleKey const&, CompatibleHash const&,
  620. CompatiblePredicate const&) const;
  621. size_type count(const key_type&) const;
  622. std::pair<iterator, iterator> equal_range(const key_type&);
  623. std::pair<const_iterator, const_iterator> equal_range(
  624. const key_type&) const;
  625. mapped_type& operator[](const key_type&);
  626. mapped_type& operator[](BOOST_RV_REF(key_type));
  627. mapped_type& at(const key_type&);
  628. mapped_type const& at(const key_type&) const;
  629. // bucket interface
  630. size_type bucket_count() const BOOST_NOEXCEPT
  631. {
  632. return table_.bucket_count_;
  633. }
  634. size_type max_bucket_count() const BOOST_NOEXCEPT
  635. {
  636. return table_.max_bucket_count();
  637. }
  638. size_type bucket_size(size_type) const;
  639. size_type bucket(const key_type& k) const
  640. {
  641. return table_.hash_to_bucket(table_.hash(k));
  642. }
  643. local_iterator begin(size_type n)
  644. {
  645. return local_iterator(table_.begin(n), n, table_.bucket_count_);
  646. }
  647. const_local_iterator begin(size_type n) const
  648. {
  649. return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
  650. }
  651. local_iterator end(size_type) { return local_iterator(); }
  652. const_local_iterator end(size_type) const
  653. {
  654. return const_local_iterator();
  655. }
  656. const_local_iterator cbegin(size_type n) const
  657. {
  658. return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
  659. }
  660. const_local_iterator cend(size_type) const
  661. {
  662. return const_local_iterator();
  663. }
  664. // hash policy
  665. float load_factor() const BOOST_NOEXCEPT;
  666. float max_load_factor() const BOOST_NOEXCEPT { return table_.mlf_; }
  667. void max_load_factor(float) BOOST_NOEXCEPT;
  668. void rehash(size_type);
  669. void reserve(size_type);
  670. #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582)
  671. friend bool operator==
  672. <K, T, H, P, A>(unordered_map const&, unordered_map const&);
  673. friend bool operator!=
  674. <K, T, H, P, A>(unordered_map const&, unordered_map const&);
  675. #endif
  676. }; // class template unordered_map
  677. #if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
  678. namespace detail {
  679. template <typename T>
  680. using iter_key_t =
  681. typename std::iterator_traits<T>::value_type::first_type;
  682. template <typename T>
  683. using iter_val_t =
  684. typename std::iterator_traits<T>::value_type::second_type;
  685. template <typename T>
  686. using iter_to_alloc_t =
  687. typename std::pair<iter_key_t<T> const, iter_val_t<T> >;
  688. }
  689. template <class InputIterator,
  690. class Hash =
  691. boost::hash<boost::unordered::detail::iter_key_t<InputIterator> >,
  692. class Pred =
  693. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  694. class Allocator = std::allocator<
  695. boost::unordered::detail::iter_to_alloc_t<InputIterator> > >
  696. unordered_map(InputIterator, InputIterator,
  697. std::size_t = boost::unordered::detail::default_bucket_count,
  698. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  699. ->unordered_map<boost::unordered::detail::iter_key_t<InputIterator>,
  700. boost::unordered::detail::iter_val_t<InputIterator>, Hash, Pred,
  701. Allocator>;
  702. template <class Key, class T, class Hash = boost::hash<Key>,
  703. class Pred = std::equal_to<Key>,
  704. class Allocator = std::allocator<std::pair<const Key, T> > >
  705. unordered_map(std::initializer_list<std::pair<const Key, T> >,
  706. std::size_t = boost::unordered::detail::default_bucket_count,
  707. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  708. ->unordered_map<Key, T, Hash, Pred, Allocator>;
  709. template <class InputIterator, class Allocator>
  710. unordered_map(InputIterator, InputIterator, std::size_t, Allocator)
  711. ->unordered_map<boost::unordered::detail::iter_key_t<InputIterator>,
  712. boost::unordered::detail::iter_val_t<InputIterator>,
  713. boost::hash<boost::unordered::detail::iter_key_t<InputIterator> >,
  714. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  715. Allocator>;
  716. template <class InputIterator, class Allocator>
  717. unordered_map(InputIterator, InputIterator, Allocator)
  718. ->unordered_map<boost::unordered::detail::iter_key_t<InputIterator>,
  719. boost::unordered::detail::iter_val_t<InputIterator>,
  720. boost::hash<boost::unordered::detail::iter_key_t<InputIterator> >,
  721. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  722. Allocator>;
  723. template <class InputIterator, class Hash, class Allocator>
  724. unordered_map(InputIterator, InputIterator, std::size_t, Hash, Allocator)
  725. ->unordered_map<boost::unordered::detail::iter_key_t<InputIterator>,
  726. boost::unordered::detail::iter_val_t<InputIterator>, Hash,
  727. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  728. Allocator>;
  729. template <class Key, class T, typename Allocator>
  730. unordered_map(
  731. std::initializer_list<std::pair<const Key, T> >, std::size_t, Allocator)
  732. ->unordered_map<Key, T, boost::hash<Key>, std::equal_to<Key>, Allocator>;
  733. template <class Key, class T, typename Allocator>
  734. unordered_map(std::initializer_list<std::pair<const Key, T> >, Allocator)
  735. ->unordered_map<Key, T, boost::hash<Key>, std::equal_to<Key>, Allocator>;
  736. template <class Key, class T, class Hash, class Allocator>
  737. unordered_map(std::initializer_list<std::pair<const Key, T> >, std::size_t,
  738. Hash, Allocator)
  739. ->unordered_map<Key, T, Hash, std::equal_to<Key>, Allocator>;
  740. #endif
  741. template <class K, class T, class H, class P, class A>
  742. class unordered_multimap
  743. {
  744. #if defined(BOOST_UNORDERED_USE_MOVE)
  745. BOOST_COPYABLE_AND_MOVABLE(unordered_multimap)
  746. #endif
  747. template <typename, typename, typename, typename, typename>
  748. friend class unordered_map;
  749. public:
  750. typedef K key_type;
  751. typedef T mapped_type;
  752. typedef std::pair<const K, T> value_type;
  753. typedef H hasher;
  754. typedef P key_equal;
  755. typedef A allocator_type;
  756. private:
  757. typedef boost::unordered::detail::map<A, K, T, H, P> types;
  758. typedef typename types::value_allocator_traits value_allocator_traits;
  759. typedef typename types::table table;
  760. typedef typename table::node_pointer node_pointer;
  761. typedef typename table::link_pointer link_pointer;
  762. public:
  763. typedef typename value_allocator_traits::pointer pointer;
  764. typedef typename value_allocator_traits::const_pointer const_pointer;
  765. typedef value_type& reference;
  766. typedef value_type const& const_reference;
  767. typedef std::size_t size_type;
  768. typedef std::ptrdiff_t difference_type;
  769. typedef typename table::iterator iterator;
  770. typedef typename table::c_iterator const_iterator;
  771. typedef typename table::l_iterator local_iterator;
  772. typedef typename table::cl_iterator const_local_iterator;
  773. typedef typename types::node_type node_type;
  774. private:
  775. table table_;
  776. public:
  777. // constructors
  778. unordered_multimap();
  779. explicit unordered_multimap(size_type, const hasher& = hasher(),
  780. const key_equal& = key_equal(),
  781. const allocator_type& = allocator_type());
  782. template <class InputIt>
  783. unordered_multimap(InputIt, InputIt,
  784. size_type = boost::unordered::detail::default_bucket_count,
  785. const hasher& = hasher(), const key_equal& = key_equal(),
  786. const allocator_type& = allocator_type());
  787. unordered_multimap(unordered_multimap const&);
  788. #if defined(BOOST_UNORDERED_USE_MOVE) || \
  789. !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  790. unordered_multimap(BOOST_RV_REF(unordered_multimap) other)
  791. BOOST_NOEXCEPT_IF(table::nothrow_move_constructible)
  792. : table_(other.table_, boost::unordered::detail::move_tag())
  793. {
  794. // The move is done in table_
  795. }
  796. #endif
  797. explicit unordered_multimap(allocator_type const&);
  798. unordered_multimap(unordered_multimap const&, allocator_type const&);
  799. unordered_multimap(
  800. BOOST_RV_REF(unordered_multimap), allocator_type const&);
  801. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  802. unordered_multimap(std::initializer_list<value_type>,
  803. size_type = boost::unordered::detail::default_bucket_count,
  804. const hasher& = hasher(), const key_equal& l = key_equal(),
  805. const allocator_type& = allocator_type());
  806. #endif
  807. explicit unordered_multimap(size_type, const allocator_type&);
  808. explicit unordered_multimap(
  809. size_type, const hasher&, const allocator_type&);
  810. template <class InputIt>
  811. unordered_multimap(InputIt, InputIt, size_type, const allocator_type&);
  812. template <class InputIt>
  813. unordered_multimap(
  814. InputIt, InputIt, size_type, const hasher&, const allocator_type&);
  815. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  816. unordered_multimap(
  817. std::initializer_list<value_type>, size_type, const allocator_type&);
  818. unordered_multimap(std::initializer_list<value_type>, size_type,
  819. const hasher&, const allocator_type&);
  820. #endif
  821. // Destructor
  822. ~unordered_multimap() BOOST_NOEXCEPT;
  823. // Assign
  824. #if defined(BOOST_UNORDERED_USE_MOVE)
  825. unordered_multimap& operator=(BOOST_COPY_ASSIGN_REF(unordered_multimap) x)
  826. {
  827. table_.assign(x.table_, boost::unordered::detail::false_type());
  828. return *this;
  829. }
  830. unordered_multimap& operator=(BOOST_RV_REF(unordered_multimap) x)
  831. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  832. boost::is_nothrow_move_assignable<H>::value&&
  833. boost::is_nothrow_move_assignable<P>::value)
  834. {
  835. table_.move_assign(x.table_, boost::unordered::detail::false_type());
  836. return *this;
  837. }
  838. #else
  839. unordered_multimap& operator=(unordered_multimap const& x)
  840. {
  841. table_.assign(x.table_, boost::unordered::detail::false_type());
  842. return *this;
  843. }
  844. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  845. unordered_multimap& operator=(unordered_multimap&& x)
  846. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  847. boost::is_nothrow_move_assignable<H>::value&&
  848. boost::is_nothrow_move_assignable<P>::value)
  849. {
  850. table_.move_assign(x.table_, boost::unordered::detail::false_type());
  851. return *this;
  852. }
  853. #endif
  854. #endif
  855. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  856. unordered_multimap& operator=(std::initializer_list<value_type>);
  857. #endif
  858. allocator_type get_allocator() const BOOST_NOEXCEPT
  859. {
  860. return table_.node_alloc();
  861. }
  862. // iterators
  863. iterator begin() BOOST_NOEXCEPT { return iterator(table_.begin()); }
  864. const_iterator begin() const BOOST_NOEXCEPT
  865. {
  866. return const_iterator(table_.begin());
  867. }
  868. iterator end() BOOST_NOEXCEPT { return iterator(); }
  869. const_iterator end() const BOOST_NOEXCEPT { return const_iterator(); }
  870. const_iterator cbegin() const BOOST_NOEXCEPT
  871. {
  872. return const_iterator(table_.begin());
  873. }
  874. const_iterator cend() const BOOST_NOEXCEPT { return const_iterator(); }
  875. // size and capacity
  876. bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; }
  877. size_type size() const BOOST_NOEXCEPT { return table_.size_; }
  878. size_type max_size() const BOOST_NOEXCEPT;
  879. // emplace
  880. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  881. template <class... Args> iterator emplace(BOOST_FWD_REF(Args)... args)
  882. {
  883. return iterator(table_.emplace_equiv(
  884. boost::unordered::detail::func::construct_node_from_args(
  885. table_.node_alloc(), boost::forward<Args>(args)...)));
  886. }
  887. #else
  888. #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
  889. // 0 argument emplace requires special treatment in case
  890. // the container is instantiated with a value type that
  891. // doesn't have a default constructor.
  892. iterator emplace(boost::unordered::detail::empty_emplace =
  893. boost::unordered::detail::empty_emplace(),
  894. value_type v = value_type())
  895. {
  896. return this->emplace(boost::move(v));
  897. }
  898. #endif
  899. template <typename A0> iterator emplace(BOOST_FWD_REF(A0) a0)
  900. {
  901. return iterator(table_.emplace_equiv(
  902. boost::unordered::detail::func::construct_node_from_args(
  903. table_.node_alloc(), boost::unordered::detail::create_emplace_args(
  904. boost::forward<A0>(a0)))));
  905. }
  906. template <typename A0, typename A1>
  907. iterator emplace(BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  908. {
  909. return iterator(table_.emplace_equiv(
  910. boost::unordered::detail::func::construct_node_from_args(
  911. table_.node_alloc(),
  912. boost::unordered::detail::create_emplace_args(
  913. boost::forward<A0>(a0), boost::forward<A1>(a1)))));
  914. }
  915. template <typename A0, typename A1, typename A2>
  916. iterator emplace(
  917. BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  918. {
  919. return iterator(table_.emplace_equiv(
  920. boost::unordered::detail::func::construct_node_from_args(
  921. table_.node_alloc(),
  922. boost::unordered::detail::create_emplace_args(
  923. boost::forward<A0>(a0), boost::forward<A1>(a1),
  924. boost::forward<A2>(a2)))));
  925. }
  926. #endif
  927. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  928. template <class... Args>
  929. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
  930. {
  931. return iterator(table_.emplace_hint_equiv(
  932. hint, boost::unordered::detail::func::construct_node_from_args(
  933. table_.node_alloc(), boost::forward<Args>(args)...)));
  934. }
  935. #else
  936. #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
  937. iterator emplace_hint(const_iterator hint,
  938. boost::unordered::detail::empty_emplace =
  939. boost::unordered::detail::empty_emplace(),
  940. value_type v = value_type())
  941. {
  942. return this->emplace_hint(hint, boost::move(v));
  943. }
  944. #endif
  945. template <typename A0>
  946. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0)
  947. {
  948. return iterator(table_.emplace_hint_equiv(hint,
  949. boost::unordered::detail::func::construct_node_from_args(
  950. table_.node_alloc(), boost::unordered::detail::create_emplace_args(
  951. boost::forward<A0>(a0)))));
  952. }
  953. template <typename A0, typename A1>
  954. iterator emplace_hint(
  955. const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
  956. {
  957. return iterator(table_.emplace_hint_equiv(
  958. hint, boost::unordered::detail::func::construct_node_from_args(
  959. table_.node_alloc(),
  960. boost::unordered::detail::create_emplace_args(
  961. boost::forward<A0>(a0), boost::forward<A1>(a1)))));
  962. }
  963. template <typename A0, typename A1, typename A2>
  964. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0,
  965. BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
  966. {
  967. return iterator(table_.emplace_hint_equiv(
  968. hint, boost::unordered::detail::func::construct_node_from_args(
  969. table_.node_alloc(),
  970. boost::unordered::detail::create_emplace_args(
  971. boost::forward<A0>(a0), boost::forward<A1>(a1),
  972. boost::forward<A2>(a2)))));
  973. }
  974. #endif
  975. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  976. #define BOOST_UNORDERED_EMPLACE(z, n, _) \
  977. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  978. iterator emplace(BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  979. { \
  980. return iterator(table_.emplace_equiv( \
  981. boost::unordered::detail::func::construct_node_from_args( \
  982. table_.node_alloc(), \
  983. boost::unordered::detail::create_emplace_args( \
  984. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))))); \
  985. } \
  986. \
  987. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
  988. iterator emplace_hint( \
  989. const_iterator hint, BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
  990. { \
  991. return iterator(table_.emplace_hint_equiv( \
  992. hint, boost::unordered::detail::func::construct_node_from_args( \
  993. table_.node_alloc(), \
  994. boost::unordered::detail::create_emplace_args( \
  995. BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))))); \
  996. }
  997. BOOST_UNORDERED_EMPLACE(1, 4, _)
  998. BOOST_UNORDERED_EMPLACE(1, 5, _)
  999. BOOST_UNORDERED_EMPLACE(1, 6, _)
  1000. BOOST_UNORDERED_EMPLACE(1, 7, _)
  1001. BOOST_UNORDERED_EMPLACE(1, 8, _)
  1002. BOOST_UNORDERED_EMPLACE(1, 9, _)
  1003. BOOST_PP_REPEAT_FROM_TO(10, BOOST_PP_INC(BOOST_UNORDERED_EMPLACE_LIMIT),
  1004. BOOST_UNORDERED_EMPLACE, _)
  1005. #undef BOOST_UNORDERED_EMPLACE
  1006. #endif
  1007. iterator insert(value_type const& x) { return this->emplace(x); }
  1008. iterator insert(BOOST_RV_REF(value_type) x)
  1009. {
  1010. return this->emplace(boost::move(x));
  1011. }
  1012. template <class P2>
  1013. iterator insert(BOOST_RV_REF(P2) obj,
  1014. typename boost::enable_if_c<
  1015. boost::is_constructible<value_type, BOOST_RV_REF(P2)>::value,
  1016. void*>::type = 0)
  1017. {
  1018. return this->emplace(boost::forward<P2>(obj));
  1019. }
  1020. iterator insert(const_iterator hint, value_type const& x)
  1021. {
  1022. return this->emplace_hint(hint, x);
  1023. }
  1024. iterator insert(const_iterator hint, BOOST_RV_REF(value_type) x)
  1025. {
  1026. return this->emplace_hint(hint, boost::move(x));
  1027. }
  1028. template <class P2>
  1029. iterator insert(const_iterator hint, BOOST_RV_REF(P2) obj,
  1030. typename boost::enable_if_c<
  1031. boost::is_constructible<value_type, BOOST_RV_REF(P2)>::value,
  1032. void*>::type = 0)
  1033. {
  1034. return this->emplace_hint(hint, boost::forward<P2>(obj));
  1035. }
  1036. template <class InputIt> void insert(InputIt, InputIt);
  1037. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1038. void insert(std::initializer_list<value_type>);
  1039. #endif
  1040. // extract
  1041. node_type extract(const_iterator position)
  1042. {
  1043. return node_type(
  1044. table_.extract_by_iterator_equiv(position), table_.node_alloc());
  1045. }
  1046. node_type extract(const key_type& k)
  1047. {
  1048. return node_type(table_.extract_by_key(k), table_.node_alloc());
  1049. }
  1050. iterator insert(BOOST_RV_REF(node_type) np)
  1051. {
  1052. return table_.move_insert_node_type_equiv(np);
  1053. }
  1054. iterator insert(const_iterator hint, BOOST_RV_REF(node_type) np)
  1055. {
  1056. return table_.move_insert_node_type_with_hint_equiv(hint, np);
  1057. }
  1058. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
  1059. (BOOST_COMP_GNUC && BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(4, 6, 0))
  1060. private:
  1061. // Note: Use r-value node_type to insert.
  1062. iterator insert(node_type&);
  1063. iterator insert(const_iterator, node_type& np);
  1064. public:
  1065. #endif
  1066. iterator erase(iterator);
  1067. iterator erase(const_iterator);
  1068. size_type erase(const key_type&);
  1069. iterator erase(const_iterator, const_iterator);
  1070. BOOST_UNORDERED_DEPRECATED("Use erase instead")
  1071. void quick_erase(const_iterator it) { erase(it); }
  1072. BOOST_UNORDERED_DEPRECATED("Use erase instead")
  1073. void erase_return_void(const_iterator it) { erase(it); }
  1074. void swap(unordered_multimap&)
  1075. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  1076. boost::is_nothrow_swappable<H>::value&&
  1077. boost::is_nothrow_swappable<P>::value);
  1078. void clear() BOOST_NOEXCEPT { table_.clear_impl(); }
  1079. template <typename H2, typename P2>
  1080. void merge(boost::unordered_multimap<K, T, H2, P2, A>& source);
  1081. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1082. template <typename H2, typename P2>
  1083. void merge(boost::unordered_multimap<K, T, H2, P2, A>&& source);
  1084. #endif
  1085. template <typename H2, typename P2>
  1086. void merge(boost::unordered_map<K, T, H2, P2, A>& source);
  1087. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1088. template <typename H2, typename P2>
  1089. void merge(boost::unordered_map<K, T, H2, P2, A>&& source);
  1090. #endif
  1091. // observers
  1092. hasher hash_function() const;
  1093. key_equal key_eq() const;
  1094. // lookup
  1095. iterator find(const key_type&);
  1096. const_iterator find(const key_type&) const;
  1097. template <class CompatibleKey, class CompatibleHash,
  1098. class CompatiblePredicate>
  1099. iterator find(CompatibleKey const&, CompatibleHash const&,
  1100. CompatiblePredicate const&);
  1101. template <class CompatibleKey, class CompatibleHash,
  1102. class CompatiblePredicate>
  1103. const_iterator find(CompatibleKey const&, CompatibleHash const&,
  1104. CompatiblePredicate const&) const;
  1105. size_type count(const key_type&) const;
  1106. std::pair<iterator, iterator> equal_range(const key_type&);
  1107. std::pair<const_iterator, const_iterator> equal_range(
  1108. const key_type&) const;
  1109. // bucket interface
  1110. size_type bucket_count() const BOOST_NOEXCEPT
  1111. {
  1112. return table_.bucket_count_;
  1113. }
  1114. size_type max_bucket_count() const BOOST_NOEXCEPT
  1115. {
  1116. return table_.max_bucket_count();
  1117. }
  1118. size_type bucket_size(size_type) const;
  1119. size_type bucket(const key_type& k) const
  1120. {
  1121. return table_.hash_to_bucket(table_.hash(k));
  1122. }
  1123. local_iterator begin(size_type n)
  1124. {
  1125. return local_iterator(table_.begin(n), n, table_.bucket_count_);
  1126. }
  1127. const_local_iterator begin(size_type n) const
  1128. {
  1129. return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
  1130. }
  1131. local_iterator end(size_type) { return local_iterator(); }
  1132. const_local_iterator end(size_type) const
  1133. {
  1134. return const_local_iterator();
  1135. }
  1136. const_local_iterator cbegin(size_type n) const
  1137. {
  1138. return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
  1139. }
  1140. const_local_iterator cend(size_type) const
  1141. {
  1142. return const_local_iterator();
  1143. }
  1144. // hash policy
  1145. float load_factor() const BOOST_NOEXCEPT;
  1146. float max_load_factor() const BOOST_NOEXCEPT { return table_.mlf_; }
  1147. void max_load_factor(float) BOOST_NOEXCEPT;
  1148. void rehash(size_type);
  1149. void reserve(size_type);
  1150. #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582)
  1151. friend bool operator==
  1152. <K, T, H, P, A>(unordered_multimap const&, unordered_multimap const&);
  1153. friend bool operator!=
  1154. <K, T, H, P, A>(unordered_multimap const&, unordered_multimap const&);
  1155. #endif
  1156. }; // class template unordered_multimap
  1157. #if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
  1158. template <class InputIterator,
  1159. class Hash =
  1160. boost::hash<boost::unordered::detail::iter_key_t<InputIterator> >,
  1161. class Pred =
  1162. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  1163. class Allocator = std::allocator<
  1164. boost::unordered::detail::iter_to_alloc_t<InputIterator> > >
  1165. unordered_multimap(InputIterator, InputIterator,
  1166. std::size_t = boost::unordered::detail::default_bucket_count,
  1167. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  1168. ->unordered_multimap<boost::unordered::detail::iter_key_t<InputIterator>,
  1169. boost::unordered::detail::iter_val_t<InputIterator>, Hash, Pred,
  1170. Allocator>;
  1171. template <class Key, class T, class Hash = boost::hash<Key>,
  1172. class Pred = std::equal_to<Key>,
  1173. class Allocator = std::allocator<std::pair<const Key, T> > >
  1174. unordered_multimap(std::initializer_list<std::pair<const Key, T> >,
  1175. std::size_t = boost::unordered::detail::default_bucket_count,
  1176. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  1177. ->unordered_multimap<Key, T, Hash, Pred, Allocator>;
  1178. template <class InputIterator, class Allocator>
  1179. unordered_multimap(InputIterator, InputIterator, std::size_t, Allocator)
  1180. ->unordered_multimap<boost::unordered::detail::iter_key_t<InputIterator>,
  1181. boost::unordered::detail::iter_val_t<InputIterator>,
  1182. boost::hash<boost::unordered::detail::iter_key_t<InputIterator> >,
  1183. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  1184. Allocator>;
  1185. template <class InputIterator, class Allocator>
  1186. unordered_multimap(InputIterator, InputIterator, Allocator)
  1187. ->unordered_multimap<boost::unordered::detail::iter_key_t<InputIterator>,
  1188. boost::unordered::detail::iter_val_t<InputIterator>,
  1189. boost::hash<boost::unordered::detail::iter_key_t<InputIterator> >,
  1190. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  1191. Allocator>;
  1192. template <class InputIterator, class Hash, class Allocator>
  1193. unordered_multimap(
  1194. InputIterator, InputIterator, std::size_t, Hash, Allocator)
  1195. ->unordered_multimap<boost::unordered::detail::iter_key_t<InputIterator>,
  1196. boost::unordered::detail::iter_val_t<InputIterator>, Hash,
  1197. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  1198. Allocator>;
  1199. template <class Key, class T, typename Allocator>
  1200. unordered_multimap(
  1201. std::initializer_list<std::pair<const Key, T> >, std::size_t, Allocator)
  1202. ->unordered_multimap<Key, T, boost::hash<Key>, std::equal_to<Key>,
  1203. Allocator>;
  1204. template <class Key, class T, typename Allocator>
  1205. unordered_multimap(
  1206. std::initializer_list<std::pair<const Key, T> >, Allocator)
  1207. ->unordered_multimap<Key, T, boost::hash<Key>, std::equal_to<Key>,
  1208. Allocator>;
  1209. template <class Key, class T, class Hash, class Allocator>
  1210. unordered_multimap(std::initializer_list<std::pair<const Key, T> >,
  1211. std::size_t, Hash, Allocator)
  1212. ->unordered_multimap<Key, T, Hash, std::equal_to<Key>, Allocator>;
  1213. #endif
  1214. ////////////////////////////////////////////////////////////////////////////
  1215. template <class K, class T, class H, class P, class A>
  1216. unordered_map<K, T, H, P, A>::unordered_map()
  1217. : table_(boost::unordered::detail::default_bucket_count, hasher(),
  1218. key_equal(), allocator_type())
  1219. {
  1220. }
  1221. template <class K, class T, class H, class P, class A>
  1222. unordered_map<K, T, H, P, A>::unordered_map(size_type n, const hasher& hf,
  1223. const key_equal& eql, const allocator_type& a)
  1224. : table_(n, hf, eql, a)
  1225. {
  1226. }
  1227. template <class K, class T, class H, class P, class A>
  1228. template <class InputIt>
  1229. unordered_map<K, T, H, P, A>::unordered_map(InputIt f, InputIt l,
  1230. size_type n, const hasher& hf, const key_equal& eql,
  1231. const allocator_type& a)
  1232. : table_(boost::unordered::detail::initial_size(f, l, n), hf, eql, a)
  1233. {
  1234. this->insert(f, l);
  1235. }
  1236. template <class K, class T, class H, class P, class A>
  1237. unordered_map<K, T, H, P, A>::unordered_map(unordered_map const& other)
  1238. : table_(other.table_,
  1239. unordered_map::value_allocator_traits::
  1240. select_on_container_copy_construction(other.get_allocator()))
  1241. {
  1242. if (other.table_.size_) {
  1243. table_.copy_buckets(
  1244. other.table_, boost::unordered::detail::true_type());
  1245. }
  1246. }
  1247. template <class K, class T, class H, class P, class A>
  1248. unordered_map<K, T, H, P, A>::unordered_map(allocator_type const& a)
  1249. : table_(boost::unordered::detail::default_bucket_count, hasher(),
  1250. key_equal(), a)
  1251. {
  1252. }
  1253. template <class K, class T, class H, class P, class A>
  1254. unordered_map<K, T, H, P, A>::unordered_map(
  1255. unordered_map const& other, allocator_type const& a)
  1256. : table_(other.table_, a)
  1257. {
  1258. if (other.table_.size_) {
  1259. table_.copy_buckets(
  1260. other.table_, boost::unordered::detail::true_type());
  1261. }
  1262. }
  1263. template <class K, class T, class H, class P, class A>
  1264. unordered_map<K, T, H, P, A>::unordered_map(
  1265. BOOST_RV_REF(unordered_map) other, allocator_type const& a)
  1266. : table_(other.table_, a, boost::unordered::detail::move_tag())
  1267. {
  1268. table_.move_construct_buckets(other.table_);
  1269. }
  1270. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1271. template <class K, class T, class H, class P, class A>
  1272. unordered_map<K, T, H, P, A>::unordered_map(
  1273. std::initializer_list<value_type> list, size_type n, const hasher& hf,
  1274. const key_equal& eql, const allocator_type& a)
  1275. : table_(
  1276. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1277. hf, eql, a)
  1278. {
  1279. this->insert(list.begin(), list.end());
  1280. }
  1281. #endif
  1282. template <class K, class T, class H, class P, class A>
  1283. unordered_map<K, T, H, P, A>::unordered_map(
  1284. size_type n, const allocator_type& a)
  1285. : table_(n, hasher(), key_equal(), a)
  1286. {
  1287. }
  1288. template <class K, class T, class H, class P, class A>
  1289. unordered_map<K, T, H, P, A>::unordered_map(
  1290. size_type n, const hasher& hf, const allocator_type& a)
  1291. : table_(n, hf, key_equal(), a)
  1292. {
  1293. }
  1294. template <class K, class T, class H, class P, class A>
  1295. template <class InputIt>
  1296. unordered_map<K, T, H, P, A>::unordered_map(
  1297. InputIt f, InputIt l, size_type n, const allocator_type& a)
  1298. : table_(boost::unordered::detail::initial_size(f, l, n), hasher(),
  1299. key_equal(), a)
  1300. {
  1301. this->insert(f, l);
  1302. }
  1303. template <class K, class T, class H, class P, class A>
  1304. template <class InputIt>
  1305. unordered_map<K, T, H, P, A>::unordered_map(InputIt f, InputIt l,
  1306. size_type n, const hasher& hf, const allocator_type& a)
  1307. : table_(
  1308. boost::unordered::detail::initial_size(f, l, n), hf, key_equal(), a)
  1309. {
  1310. this->insert(f, l);
  1311. }
  1312. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1313. template <class K, class T, class H, class P, class A>
  1314. unordered_map<K, T, H, P, A>::unordered_map(
  1315. std::initializer_list<value_type> list, size_type n,
  1316. const allocator_type& a)
  1317. : table_(
  1318. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1319. hasher(), key_equal(), a)
  1320. {
  1321. this->insert(list.begin(), list.end());
  1322. }
  1323. template <class K, class T, class H, class P, class A>
  1324. unordered_map<K, T, H, P, A>::unordered_map(
  1325. std::initializer_list<value_type> list, size_type n, const hasher& hf,
  1326. const allocator_type& a)
  1327. : table_(
  1328. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1329. hf, key_equal(), a)
  1330. {
  1331. this->insert(list.begin(), list.end());
  1332. }
  1333. #endif
  1334. template <class K, class T, class H, class P, class A>
  1335. unordered_map<K, T, H, P, A>::~unordered_map() BOOST_NOEXCEPT
  1336. {
  1337. }
  1338. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1339. template <class K, class T, class H, class P, class A>
  1340. unordered_map<K, T, H, P, A>& unordered_map<K, T, H, P, A>::operator=(
  1341. std::initializer_list<value_type> list)
  1342. {
  1343. this->clear();
  1344. this->insert(list.begin(), list.end());
  1345. return *this;
  1346. }
  1347. #endif
  1348. // size and capacity
  1349. template <class K, class T, class H, class P, class A>
  1350. std::size_t unordered_map<K, T, H, P, A>::max_size() const BOOST_NOEXCEPT
  1351. {
  1352. using namespace std;
  1353. // size <= mlf_ * count
  1354. return boost::unordered::detail::double_to_size(
  1355. ceil(static_cast<double>(table_.mlf_) *
  1356. static_cast<double>(table_.max_bucket_count()))) -
  1357. 1;
  1358. }
  1359. // modifiers
  1360. template <class K, class T, class H, class P, class A>
  1361. template <class InputIt>
  1362. void unordered_map<K, T, H, P, A>::insert(InputIt first, InputIt last)
  1363. {
  1364. if (first != last) {
  1365. table_.insert_range_unique(
  1366. table::extractor::extract(*first), first, last);
  1367. }
  1368. }
  1369. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1370. template <class K, class T, class H, class P, class A>
  1371. void unordered_map<K, T, H, P, A>::insert(
  1372. std::initializer_list<value_type> list)
  1373. {
  1374. this->insert(list.begin(), list.end());
  1375. }
  1376. #endif
  1377. template <class K, class T, class H, class P, class A>
  1378. typename unordered_map<K, T, H, P, A>::iterator
  1379. unordered_map<K, T, H, P, A>::erase(iterator position)
  1380. {
  1381. node_pointer node = table::get_node(position);
  1382. BOOST_ASSERT(node);
  1383. node_pointer next = table::next_node(node);
  1384. table_.erase_nodes_unique(node, next);
  1385. return iterator(next);
  1386. }
  1387. template <class K, class T, class H, class P, class A>
  1388. typename unordered_map<K, T, H, P, A>::iterator
  1389. unordered_map<K, T, H, P, A>::erase(const_iterator position)
  1390. {
  1391. node_pointer node = table::get_node(position);
  1392. BOOST_ASSERT(node);
  1393. node_pointer next = table::next_node(node);
  1394. table_.erase_nodes_unique(node, next);
  1395. return iterator(next);
  1396. }
  1397. template <class K, class T, class H, class P, class A>
  1398. typename unordered_map<K, T, H, P, A>::size_type
  1399. unordered_map<K, T, H, P, A>::erase(const key_type& k)
  1400. {
  1401. return table_.erase_key_unique(k);
  1402. }
  1403. template <class K, class T, class H, class P, class A>
  1404. typename unordered_map<K, T, H, P, A>::iterator
  1405. unordered_map<K, T, H, P, A>::erase(
  1406. const_iterator first, const_iterator last)
  1407. {
  1408. node_pointer last_node = table::get_node(last);
  1409. if (first == last)
  1410. return iterator(last_node);
  1411. table_.erase_nodes_unique(table::get_node(first), last_node);
  1412. return iterator(last_node);
  1413. }
  1414. template <class K, class T, class H, class P, class A>
  1415. void unordered_map<K, T, H, P, A>::swap(unordered_map& other)
  1416. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  1417. boost::is_nothrow_swappable<H>::value&&
  1418. boost::is_nothrow_swappable<P>::value)
  1419. {
  1420. table_.swap(other.table_);
  1421. }
  1422. template <class K, class T, class H, class P, class A>
  1423. template <typename H2, typename P2>
  1424. void unordered_map<K, T, H, P, A>::merge(
  1425. boost::unordered_map<K, T, H2, P2, A>& source)
  1426. {
  1427. table_.merge_unique(source.table_);
  1428. }
  1429. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1430. template <class K, class T, class H, class P, class A>
  1431. template <typename H2, typename P2>
  1432. void unordered_map<K, T, H, P, A>::merge(
  1433. boost::unordered_map<K, T, H2, P2, A>&& source)
  1434. {
  1435. table_.merge_unique(source.table_);
  1436. }
  1437. #endif
  1438. template <class K, class T, class H, class P, class A>
  1439. template <typename H2, typename P2>
  1440. void unordered_map<K, T, H, P, A>::merge(
  1441. boost::unordered_multimap<K, T, H2, P2, A>& source)
  1442. {
  1443. table_.merge_unique(source.table_);
  1444. }
  1445. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1446. template <class K, class T, class H, class P, class A>
  1447. template <typename H2, typename P2>
  1448. void unordered_map<K, T, H, P, A>::merge(
  1449. boost::unordered_multimap<K, T, H2, P2, A>&& source)
  1450. {
  1451. table_.merge_unique(source.table_);
  1452. }
  1453. #endif
  1454. // observers
  1455. template <class K, class T, class H, class P, class A>
  1456. typename unordered_map<K, T, H, P, A>::hasher
  1457. unordered_map<K, T, H, P, A>::hash_function() const
  1458. {
  1459. return table_.hash_function();
  1460. }
  1461. template <class K, class T, class H, class P, class A>
  1462. typename unordered_map<K, T, H, P, A>::key_equal
  1463. unordered_map<K, T, H, P, A>::key_eq() const
  1464. {
  1465. return table_.key_eq();
  1466. }
  1467. // lookup
  1468. template <class K, class T, class H, class P, class A>
  1469. typename unordered_map<K, T, H, P, A>::iterator
  1470. unordered_map<K, T, H, P, A>::find(const key_type& k)
  1471. {
  1472. return iterator(table_.find_node(k));
  1473. }
  1474. template <class K, class T, class H, class P, class A>
  1475. typename unordered_map<K, T, H, P, A>::const_iterator
  1476. unordered_map<K, T, H, P, A>::find(const key_type& k) const
  1477. {
  1478. return const_iterator(table_.find_node(k));
  1479. }
  1480. template <class K, class T, class H, class P, class A>
  1481. template <class CompatibleKey, class CompatibleHash,
  1482. class CompatiblePredicate>
  1483. typename unordered_map<K, T, H, P, A>::iterator
  1484. unordered_map<K, T, H, P, A>::find(CompatibleKey const& k,
  1485. CompatibleHash const& hash, CompatiblePredicate const& eq)
  1486. {
  1487. return iterator(
  1488. table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq));
  1489. }
  1490. template <class K, class T, class H, class P, class A>
  1491. template <class CompatibleKey, class CompatibleHash,
  1492. class CompatiblePredicate>
  1493. typename unordered_map<K, T, H, P, A>::const_iterator
  1494. unordered_map<K, T, H, P, A>::find(CompatibleKey const& k,
  1495. CompatibleHash const& hash, CompatiblePredicate const& eq) const
  1496. {
  1497. return const_iterator(
  1498. table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq));
  1499. }
  1500. template <class K, class T, class H, class P, class A>
  1501. typename unordered_map<K, T, H, P, A>::size_type
  1502. unordered_map<K, T, H, P, A>::count(const key_type& k) const
  1503. {
  1504. return table_.find_node(k) ? 1 : 0;
  1505. }
  1506. template <class K, class T, class H, class P, class A>
  1507. std::pair<typename unordered_map<K, T, H, P, A>::iterator,
  1508. typename unordered_map<K, T, H, P, A>::iterator>
  1509. unordered_map<K, T, H, P, A>::equal_range(const key_type& k)
  1510. {
  1511. node_pointer n = table_.find_node(k);
  1512. return std::make_pair(iterator(n), iterator(n ? table::next_node(n) : n));
  1513. }
  1514. template <class K, class T, class H, class P, class A>
  1515. std::pair<typename unordered_map<K, T, H, P, A>::const_iterator,
  1516. typename unordered_map<K, T, H, P, A>::const_iterator>
  1517. unordered_map<K, T, H, P, A>::equal_range(const key_type& k) const
  1518. {
  1519. node_pointer n = table_.find_node(k);
  1520. return std::make_pair(
  1521. const_iterator(n), const_iterator(n ? table::next_node(n) : n));
  1522. }
  1523. template <class K, class T, class H, class P, class A>
  1524. typename unordered_map<K, T, H, P, A>::mapped_type&
  1525. unordered_map<K, T, H, P, A>::operator[](const key_type& k)
  1526. {
  1527. return table_.try_emplace_unique(k).first->second;
  1528. }
  1529. template <class K, class T, class H, class P, class A>
  1530. typename unordered_map<K, T, H, P, A>::mapped_type&
  1531. unordered_map<K, T, H, P, A>::operator[](BOOST_RV_REF(key_type) k)
  1532. {
  1533. return table_.try_emplace_unique(boost::move(k)).first->second;
  1534. }
  1535. template <class K, class T, class H, class P, class A>
  1536. typename unordered_map<K, T, H, P, A>::mapped_type&
  1537. unordered_map<K, T, H, P, A>::at(const key_type& k)
  1538. {
  1539. if (table_.size_) {
  1540. node_pointer n = table_.find_node(k);
  1541. if (n)
  1542. return n->value().second;
  1543. }
  1544. boost::throw_exception(
  1545. std::out_of_range("Unable to find key in unordered_map."));
  1546. }
  1547. template <class K, class T, class H, class P, class A>
  1548. typename unordered_map<K, T, H, P, A>::mapped_type const&
  1549. unordered_map<K, T, H, P, A>::at(const key_type& k) const
  1550. {
  1551. if (table_.size_) {
  1552. node_pointer n = table_.find_node(k);
  1553. if (n)
  1554. return n->value().second;
  1555. }
  1556. boost::throw_exception(
  1557. std::out_of_range("Unable to find key in unordered_map."));
  1558. }
  1559. template <class K, class T, class H, class P, class A>
  1560. typename unordered_map<K, T, H, P, A>::size_type
  1561. unordered_map<K, T, H, P, A>::bucket_size(size_type n) const
  1562. {
  1563. return table_.bucket_size(n);
  1564. }
  1565. // hash policy
  1566. template <class K, class T, class H, class P, class A>
  1567. float unordered_map<K, T, H, P, A>::load_factor() const BOOST_NOEXCEPT
  1568. {
  1569. BOOST_ASSERT(table_.bucket_count_ != 0);
  1570. return static_cast<float>(table_.size_) /
  1571. static_cast<float>(table_.bucket_count_);
  1572. }
  1573. template <class K, class T, class H, class P, class A>
  1574. void unordered_map<K, T, H, P, A>::max_load_factor(float m) BOOST_NOEXCEPT
  1575. {
  1576. table_.max_load_factor(m);
  1577. }
  1578. template <class K, class T, class H, class P, class A>
  1579. void unordered_map<K, T, H, P, A>::rehash(size_type n)
  1580. {
  1581. table_.rehash(n);
  1582. }
  1583. template <class K, class T, class H, class P, class A>
  1584. void unordered_map<K, T, H, P, A>::reserve(size_type n)
  1585. {
  1586. table_.rehash(static_cast<std::size_t>(
  1587. std::ceil(static_cast<double>(n) / table_.mlf_)));
  1588. }
  1589. template <class K, class T, class H, class P, class A>
  1590. inline bool operator==(unordered_map<K, T, H, P, A> const& m1,
  1591. unordered_map<K, T, H, P, A> const& m2)
  1592. {
  1593. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1594. struct dummy
  1595. {
  1596. unordered_map<K, T, H, P, A> x;
  1597. };
  1598. #endif
  1599. return m1.table_.equals_unique(m2.table_);
  1600. }
  1601. template <class K, class T, class H, class P, class A>
  1602. inline bool operator!=(unordered_map<K, T, H, P, A> const& m1,
  1603. unordered_map<K, T, H, P, A> const& m2)
  1604. {
  1605. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1606. struct dummy
  1607. {
  1608. unordered_map<K, T, H, P, A> x;
  1609. };
  1610. #endif
  1611. return !m1.table_.equals_unique(m2.table_);
  1612. }
  1613. template <class K, class T, class H, class P, class A>
  1614. inline void swap(
  1615. unordered_map<K, T, H, P, A>& m1, unordered_map<K, T, H, P, A>& m2)
  1616. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(m1.swap(m2)))
  1617. {
  1618. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1619. struct dummy
  1620. {
  1621. unordered_map<K, T, H, P, A> x;
  1622. };
  1623. #endif
  1624. m1.swap(m2);
  1625. }
  1626. ////////////////////////////////////////////////////////////////////////////
  1627. template <class K, class T, class H, class P, class A>
  1628. unordered_multimap<K, T, H, P, A>::unordered_multimap()
  1629. : table_(boost::unordered::detail::default_bucket_count, hasher(),
  1630. key_equal(), allocator_type())
  1631. {
  1632. }
  1633. template <class K, class T, class H, class P, class A>
  1634. unordered_multimap<K, T, H, P, A>::unordered_multimap(size_type n,
  1635. const hasher& hf, const key_equal& eql, const allocator_type& a)
  1636. : table_(n, hf, eql, a)
  1637. {
  1638. }
  1639. template <class K, class T, class H, class P, class A>
  1640. template <class InputIt>
  1641. unordered_multimap<K, T, H, P, A>::unordered_multimap(InputIt f, InputIt l,
  1642. size_type n, const hasher& hf, const key_equal& eql,
  1643. const allocator_type& a)
  1644. : table_(boost::unordered::detail::initial_size(f, l, n), hf, eql, a)
  1645. {
  1646. this->insert(f, l);
  1647. }
  1648. template <class K, class T, class H, class P, class A>
  1649. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1650. unordered_multimap const& other)
  1651. : table_(other.table_,
  1652. unordered_multimap::value_allocator_traits::
  1653. select_on_container_copy_construction(other.get_allocator()))
  1654. {
  1655. if (other.table_.size_) {
  1656. table_.copy_buckets(
  1657. other.table_, boost::unordered::detail::false_type());
  1658. }
  1659. }
  1660. template <class K, class T, class H, class P, class A>
  1661. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1662. allocator_type const& a)
  1663. : table_(boost::unordered::detail::default_bucket_count, hasher(),
  1664. key_equal(), a)
  1665. {
  1666. }
  1667. template <class K, class T, class H, class P, class A>
  1668. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1669. unordered_multimap const& other, allocator_type const& a)
  1670. : table_(other.table_, a)
  1671. {
  1672. if (other.table_.size_) {
  1673. table_.copy_buckets(
  1674. other.table_, boost::unordered::detail::false_type());
  1675. }
  1676. }
  1677. template <class K, class T, class H, class P, class A>
  1678. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1679. BOOST_RV_REF(unordered_multimap) other, allocator_type const& a)
  1680. : table_(other.table_, a, boost::unordered::detail::move_tag())
  1681. {
  1682. table_.move_construct_buckets(other.table_);
  1683. }
  1684. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1685. template <class K, class T, class H, class P, class A>
  1686. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1687. std::initializer_list<value_type> list, size_type n, const hasher& hf,
  1688. const key_equal& eql, const allocator_type& a)
  1689. : table_(
  1690. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1691. hf, eql, a)
  1692. {
  1693. this->insert(list.begin(), list.end());
  1694. }
  1695. #endif
  1696. template <class K, class T, class H, class P, class A>
  1697. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1698. size_type n, const allocator_type& a)
  1699. : table_(n, hasher(), key_equal(), a)
  1700. {
  1701. }
  1702. template <class K, class T, class H, class P, class A>
  1703. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1704. size_type n, const hasher& hf, const allocator_type& a)
  1705. : table_(n, hf, key_equal(), a)
  1706. {
  1707. }
  1708. template <class K, class T, class H, class P, class A>
  1709. template <class InputIt>
  1710. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1711. InputIt f, InputIt l, size_type n, const allocator_type& a)
  1712. : table_(boost::unordered::detail::initial_size(f, l, n), hasher(),
  1713. key_equal(), a)
  1714. {
  1715. this->insert(f, l);
  1716. }
  1717. template <class K, class T, class H, class P, class A>
  1718. template <class InputIt>
  1719. unordered_multimap<K, T, H, P, A>::unordered_multimap(InputIt f, InputIt l,
  1720. size_type n, const hasher& hf, const allocator_type& a)
  1721. : table_(
  1722. boost::unordered::detail::initial_size(f, l, n), hf, key_equal(), a)
  1723. {
  1724. this->insert(f, l);
  1725. }
  1726. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1727. template <class K, class T, class H, class P, class A>
  1728. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1729. std::initializer_list<value_type> list, size_type n,
  1730. const allocator_type& a)
  1731. : table_(
  1732. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1733. hasher(), key_equal(), a)
  1734. {
  1735. this->insert(list.begin(), list.end());
  1736. }
  1737. template <class K, class T, class H, class P, class A>
  1738. unordered_multimap<K, T, H, P, A>::unordered_multimap(
  1739. std::initializer_list<value_type> list, size_type n, const hasher& hf,
  1740. const allocator_type& a)
  1741. : table_(
  1742. boost::unordered::detail::initial_size(list.begin(), list.end(), n),
  1743. hf, key_equal(), a)
  1744. {
  1745. this->insert(list.begin(), list.end());
  1746. }
  1747. #endif
  1748. template <class K, class T, class H, class P, class A>
  1749. unordered_multimap<K, T, H, P, A>::~unordered_multimap() BOOST_NOEXCEPT
  1750. {
  1751. }
  1752. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1753. template <class K, class T, class H, class P, class A>
  1754. unordered_multimap<K, T, H, P, A>& unordered_multimap<K, T, H, P, A>::
  1755. operator=(std::initializer_list<value_type> list)
  1756. {
  1757. this->clear();
  1758. this->insert(list.begin(), list.end());
  1759. return *this;
  1760. }
  1761. #endif
  1762. // size and capacity
  1763. template <class K, class T, class H, class P, class A>
  1764. std::size_t
  1765. unordered_multimap<K, T, H, P, A>::max_size() const BOOST_NOEXCEPT
  1766. {
  1767. using namespace std;
  1768. // size <= mlf_ * count
  1769. return boost::unordered::detail::double_to_size(
  1770. ceil(static_cast<double>(table_.mlf_) *
  1771. static_cast<double>(table_.max_bucket_count()))) -
  1772. 1;
  1773. }
  1774. // modifiers
  1775. template <class K, class T, class H, class P, class A>
  1776. template <class InputIt>
  1777. void unordered_multimap<K, T, H, P, A>::insert(InputIt first, InputIt last)
  1778. {
  1779. table_.insert_range_equiv(first, last);
  1780. }
  1781. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1782. template <class K, class T, class H, class P, class A>
  1783. void unordered_multimap<K, T, H, P, A>::insert(
  1784. std::initializer_list<value_type> list)
  1785. {
  1786. this->insert(list.begin(), list.end());
  1787. }
  1788. #endif
  1789. template <class K, class T, class H, class P, class A>
  1790. typename unordered_multimap<K, T, H, P, A>::iterator
  1791. unordered_multimap<K, T, H, P, A>::erase(iterator position)
  1792. {
  1793. node_pointer node = table::get_node(position);
  1794. BOOST_ASSERT(node);
  1795. node_pointer next = table::next_node(node);
  1796. table_.erase_nodes_equiv(node, next);
  1797. return iterator(next);
  1798. }
  1799. template <class K, class T, class H, class P, class A>
  1800. typename unordered_multimap<K, T, H, P, A>::iterator
  1801. unordered_multimap<K, T, H, P, A>::erase(const_iterator position)
  1802. {
  1803. node_pointer node = table::get_node(position);
  1804. BOOST_ASSERT(node);
  1805. node_pointer next = table::next_node(node);
  1806. table_.erase_nodes_equiv(node, next);
  1807. return iterator(next);
  1808. }
  1809. template <class K, class T, class H, class P, class A>
  1810. typename unordered_multimap<K, T, H, P, A>::size_type
  1811. unordered_multimap<K, T, H, P, A>::erase(const key_type& k)
  1812. {
  1813. return table_.erase_key_equiv(k);
  1814. }
  1815. template <class K, class T, class H, class P, class A>
  1816. typename unordered_multimap<K, T, H, P, A>::iterator
  1817. unordered_multimap<K, T, H, P, A>::erase(
  1818. const_iterator first, const_iterator last)
  1819. {
  1820. node_pointer last_node = table::get_node(last);
  1821. if (first == last)
  1822. return iterator(last_node);
  1823. table_.erase_nodes_equiv(table::get_node(first), last_node);
  1824. return iterator(last_node);
  1825. }
  1826. template <class K, class T, class H, class P, class A>
  1827. void unordered_multimap<K, T, H, P, A>::swap(unordered_multimap& other)
  1828. BOOST_NOEXCEPT_IF(value_allocator_traits::is_always_equal::value&&
  1829. boost::is_nothrow_swappable<H>::value&&
  1830. boost::is_nothrow_swappable<P>::value)
  1831. {
  1832. table_.swap(other.table_);
  1833. }
  1834. // observers
  1835. template <class K, class T, class H, class P, class A>
  1836. typename unordered_multimap<K, T, H, P, A>::hasher
  1837. unordered_multimap<K, T, H, P, A>::hash_function() const
  1838. {
  1839. return table_.hash_function();
  1840. }
  1841. template <class K, class T, class H, class P, class A>
  1842. typename unordered_multimap<K, T, H, P, A>::key_equal
  1843. unordered_multimap<K, T, H, P, A>::key_eq() const
  1844. {
  1845. return table_.key_eq();
  1846. }
  1847. template <class K, class T, class H, class P, class A>
  1848. template <typename H2, typename P2>
  1849. void unordered_multimap<K, T, H, P, A>::merge(
  1850. boost::unordered_multimap<K, T, H2, P2, A>& source)
  1851. {
  1852. while (!source.empty()) {
  1853. insert(source.extract(source.begin()));
  1854. }
  1855. }
  1856. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1857. template <class K, class T, class H, class P, class A>
  1858. template <typename H2, typename P2>
  1859. void unordered_multimap<K, T, H, P, A>::merge(
  1860. boost::unordered_multimap<K, T, H2, P2, A>&& source)
  1861. {
  1862. while (!source.empty()) {
  1863. insert(source.extract(source.begin()));
  1864. }
  1865. }
  1866. #endif
  1867. template <class K, class T, class H, class P, class A>
  1868. template <typename H2, typename P2>
  1869. void unordered_multimap<K, T, H, P, A>::merge(
  1870. boost::unordered_map<K, T, H2, P2, A>& source)
  1871. {
  1872. while (!source.empty()) {
  1873. insert(source.extract(source.begin()));
  1874. }
  1875. }
  1876. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1877. template <class K, class T, class H, class P, class A>
  1878. template <typename H2, typename P2>
  1879. void unordered_multimap<K, T, H, P, A>::merge(
  1880. boost::unordered_map<K, T, H2, P2, A>&& source)
  1881. {
  1882. while (!source.empty()) {
  1883. insert(source.extract(source.begin()));
  1884. }
  1885. }
  1886. #endif
  1887. // lookup
  1888. template <class K, class T, class H, class P, class A>
  1889. typename unordered_multimap<K, T, H, P, A>::iterator
  1890. unordered_multimap<K, T, H, P, A>::find(const key_type& k)
  1891. {
  1892. return iterator(table_.find_node(k));
  1893. }
  1894. template <class K, class T, class H, class P, class A>
  1895. typename unordered_multimap<K, T, H, P, A>::const_iterator
  1896. unordered_multimap<K, T, H, P, A>::find(const key_type& k) const
  1897. {
  1898. return const_iterator(table_.find_node(k));
  1899. }
  1900. template <class K, class T, class H, class P, class A>
  1901. template <class CompatibleKey, class CompatibleHash,
  1902. class CompatiblePredicate>
  1903. typename unordered_multimap<K, T, H, P, A>::iterator
  1904. unordered_multimap<K, T, H, P, A>::find(CompatibleKey const& k,
  1905. CompatibleHash const& hash, CompatiblePredicate const& eq)
  1906. {
  1907. return iterator(
  1908. table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq));
  1909. }
  1910. template <class K, class T, class H, class P, class A>
  1911. template <class CompatibleKey, class CompatibleHash,
  1912. class CompatiblePredicate>
  1913. typename unordered_multimap<K, T, H, P, A>::const_iterator
  1914. unordered_multimap<K, T, H, P, A>::find(CompatibleKey const& k,
  1915. CompatibleHash const& hash, CompatiblePredicate const& eq) const
  1916. {
  1917. return const_iterator(
  1918. table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq));
  1919. }
  1920. template <class K, class T, class H, class P, class A>
  1921. typename unordered_multimap<K, T, H, P, A>::size_type
  1922. unordered_multimap<K, T, H, P, A>::count(const key_type& k) const
  1923. {
  1924. node_pointer n = table_.find_node(k);
  1925. return n ? table_.group_count(n) : 0;
  1926. }
  1927. template <class K, class T, class H, class P, class A>
  1928. std::pair<typename unordered_multimap<K, T, H, P, A>::iterator,
  1929. typename unordered_multimap<K, T, H, P, A>::iterator>
  1930. unordered_multimap<K, T, H, P, A>::equal_range(const key_type& k)
  1931. {
  1932. node_pointer n = table_.find_node(k);
  1933. return std::make_pair(
  1934. iterator(n), iterator(n ? table_.next_group(n) : n));
  1935. }
  1936. template <class K, class T, class H, class P, class A>
  1937. std::pair<typename unordered_multimap<K, T, H, P, A>::const_iterator,
  1938. typename unordered_multimap<K, T, H, P, A>::const_iterator>
  1939. unordered_multimap<K, T, H, P, A>::equal_range(const key_type& k) const
  1940. {
  1941. node_pointer n = table_.find_node(k);
  1942. return std::make_pair(
  1943. const_iterator(n), const_iterator(n ? table_.next_group(n) : n));
  1944. }
  1945. template <class K, class T, class H, class P, class A>
  1946. typename unordered_multimap<K, T, H, P, A>::size_type
  1947. unordered_multimap<K, T, H, P, A>::bucket_size(size_type n) const
  1948. {
  1949. return table_.bucket_size(n);
  1950. }
  1951. // hash policy
  1952. template <class K, class T, class H, class P, class A>
  1953. float unordered_multimap<K, T, H, P, A>::load_factor() const BOOST_NOEXCEPT
  1954. {
  1955. BOOST_ASSERT(table_.bucket_count_ != 0);
  1956. return static_cast<float>(table_.size_) /
  1957. static_cast<float>(table_.bucket_count_);
  1958. }
  1959. template <class K, class T, class H, class P, class A>
  1960. void unordered_multimap<K, T, H, P, A>::max_load_factor(
  1961. float m) BOOST_NOEXCEPT
  1962. {
  1963. table_.max_load_factor(m);
  1964. }
  1965. template <class K, class T, class H, class P, class A>
  1966. void unordered_multimap<K, T, H, P, A>::rehash(size_type n)
  1967. {
  1968. table_.rehash(n);
  1969. }
  1970. template <class K, class T, class H, class P, class A>
  1971. void unordered_multimap<K, T, H, P, A>::reserve(size_type n)
  1972. {
  1973. table_.rehash(static_cast<std::size_t>(
  1974. std::ceil(static_cast<double>(n) / table_.mlf_)));
  1975. }
  1976. template <class K, class T, class H, class P, class A>
  1977. inline bool operator==(unordered_multimap<K, T, H, P, A> const& m1,
  1978. unordered_multimap<K, T, H, P, A> const& m2)
  1979. {
  1980. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1981. struct dummy
  1982. {
  1983. unordered_multimap<K, T, H, P, A> x;
  1984. };
  1985. #endif
  1986. return m1.table_.equals_equiv(m2.table_);
  1987. }
  1988. template <class K, class T, class H, class P, class A>
  1989. inline bool operator!=(unordered_multimap<K, T, H, P, A> const& m1,
  1990. unordered_multimap<K, T, H, P, A> const& m2)
  1991. {
  1992. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  1993. struct dummy
  1994. {
  1995. unordered_multimap<K, T, H, P, A> x;
  1996. };
  1997. #endif
  1998. return !m1.table_.equals_equiv(m2.table_);
  1999. }
  2000. template <class K, class T, class H, class P, class A>
  2001. inline void swap(unordered_multimap<K, T, H, P, A>& m1,
  2002. unordered_multimap<K, T, H, P, A>& m2)
  2003. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(m1.swap(m2)))
  2004. {
  2005. #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
  2006. struct dummy
  2007. {
  2008. unordered_multimap<K, T, H, P, A> x;
  2009. };
  2010. #endif
  2011. m1.swap(m2);
  2012. }
  2013. template <typename N, class K, class T, class A> class node_handle_map
  2014. {
  2015. BOOST_MOVABLE_BUT_NOT_COPYABLE(node_handle_map)
  2016. template <typename Types> friend struct ::boost::unordered::detail::table;
  2017. template <class K2, class T2, class H2, class P2, class A2>
  2018. friend class boost::unordered::unordered_map;
  2019. template <class K2, class T2, class H2, class P2, class A2>
  2020. friend class boost::unordered::unordered_multimap;
  2021. typedef typename boost::unordered::detail::rebind_wrap<A,
  2022. std::pair<K const, T> >::type value_allocator;
  2023. typedef boost::unordered::detail::allocator_traits<value_allocator>
  2024. value_allocator_traits;
  2025. typedef N node;
  2026. typedef typename boost::unordered::detail::rebind_wrap<A, node>::type
  2027. node_allocator;
  2028. typedef boost::unordered::detail::allocator_traits<node_allocator>
  2029. node_allocator_traits;
  2030. typedef typename node_allocator_traits::pointer node_pointer;
  2031. public:
  2032. typedef K key_type;
  2033. typedef T mapped_type;
  2034. typedef A allocator_type;
  2035. private:
  2036. node_pointer ptr_;
  2037. boost::unordered::detail::optional<value_allocator> alloc_;
  2038. node_handle_map(node_pointer ptr, allocator_type const& a)
  2039. : ptr_(ptr), alloc_(a)
  2040. {
  2041. }
  2042. public:
  2043. BOOST_CONSTEXPR node_handle_map() BOOST_NOEXCEPT : ptr_(), alloc_() {}
  2044. ~node_handle_map()
  2045. {
  2046. if (ptr_) {
  2047. node_allocator node_alloc(*alloc_);
  2048. boost::unordered::detail::node_tmp<node_allocator> tmp(
  2049. ptr_, node_alloc);
  2050. }
  2051. }
  2052. node_handle_map(BOOST_RV_REF(node_handle_map) n) BOOST_NOEXCEPT
  2053. : ptr_(n.ptr_),
  2054. alloc_(boost::move(n.alloc_))
  2055. {
  2056. n.ptr_ = node_pointer();
  2057. }
  2058. node_handle_map& operator=(BOOST_RV_REF(node_handle_map) n)
  2059. {
  2060. BOOST_ASSERT(!alloc_.has_value() ||
  2061. value_allocator_traits::
  2062. propagate_on_container_move_assignment::value ||
  2063. (n.alloc_.has_value() && alloc_ == n.alloc_));
  2064. if (ptr_) {
  2065. node_allocator node_alloc(*alloc_);
  2066. boost::unordered::detail::node_tmp<node_allocator> tmp(
  2067. ptr_, node_alloc);
  2068. ptr_ = node_pointer();
  2069. }
  2070. if (!alloc_.has_value() ||
  2071. value_allocator_traits::propagate_on_container_move_assignment::
  2072. value) {
  2073. alloc_ = boost::move(n.alloc_);
  2074. }
  2075. ptr_ = n.ptr_;
  2076. n.ptr_ = node_pointer();
  2077. return *this;
  2078. }
  2079. key_type& key() const
  2080. {
  2081. return const_cast<key_type&>(ptr_->value().first);
  2082. }
  2083. mapped_type& mapped() const { return ptr_->value().second; }
  2084. allocator_type get_allocator() const { return *alloc_; }
  2085. BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
  2086. bool operator!() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; }
  2087. bool empty() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; }
  2088. void swap(node_handle_map& n) BOOST_NOEXCEPT_IF(
  2089. value_allocator_traits::propagate_on_container_swap::value ||
  2090. value_allocator_traits::is_always_equal::value)
  2091. {
  2092. BOOST_ASSERT(
  2093. !alloc_.has_value() || !n.alloc_.has_value() ||
  2094. value_allocator_traits::propagate_on_container_swap::value ||
  2095. alloc_ == n.alloc_);
  2096. if (value_allocator_traits::propagate_on_container_swap::value ||
  2097. !alloc_.has_value() || !n.alloc_.has_value()) {
  2098. boost::swap(alloc_, n.alloc_);
  2099. }
  2100. boost::swap(ptr_, n.ptr_);
  2101. }
  2102. };
  2103. template <class N, class K, class T, class A>
  2104. void swap(node_handle_map<N, K, T, A>& x, node_handle_map<N, K, T, A>& y)
  2105. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(x.swap(y)))
  2106. {
  2107. x.swap(y);
  2108. }
  2109. template <class N, class K, class T, class A> struct insert_return_type_map
  2110. {
  2111. private:
  2112. BOOST_MOVABLE_BUT_NOT_COPYABLE(insert_return_type_map)
  2113. typedef typename boost::unordered::detail::rebind_wrap<A,
  2114. std::pair<K const, T> >::type value_allocator;
  2115. typedef N node_;
  2116. public:
  2117. bool inserted;
  2118. boost::unordered::iterator_detail::iterator<node_> position;
  2119. boost::unordered::node_handle_map<N, K, T, A> node;
  2120. insert_return_type_map() : inserted(false), position(), node() {}
  2121. insert_return_type_map(BOOST_RV_REF(insert_return_type_map)
  2122. x) BOOST_NOEXCEPT : inserted(x.inserted),
  2123. position(x.position),
  2124. node(boost::move(x.node))
  2125. {
  2126. }
  2127. insert_return_type_map& operator=(BOOST_RV_REF(insert_return_type_map) x)
  2128. {
  2129. inserted = x.inserted;
  2130. position = x.position;
  2131. node = boost::move(x.node);
  2132. return *this;
  2133. }
  2134. };
  2135. template <class N, class K, class T, class A>
  2136. void swap(insert_return_type_map<N, K, T, A>& x,
  2137. insert_return_type_map<N, K, T, A>& y)
  2138. {
  2139. boost::swap(x.node, y.node);
  2140. boost::swap(x.inserted, y.inserted);
  2141. boost::swap(x.position, y.position);
  2142. }
  2143. } // namespace unordered
  2144. } // namespace boost
  2145. #if defined(BOOST_MSVC)
  2146. #pragma warning(pop)
  2147. #endif
  2148. #endif // BOOST_UNORDERED_UNORDERED_MAP_HPP_INCLUDED