unordered_map.hpp 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589
  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(BOOST_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(BOOST_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(BOOST_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(BOOST_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(BOOST_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(BOOST_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(BOOST_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(BOOST_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