map.hpp 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_MAP_HPP
  11. #define BOOST_CONTAINER_MAP_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #include <boost/container/detail/config_begin.hpp>
  19. #include <boost/container/detail/workaround.hpp>
  20. // container
  21. #include <boost/container/container_fwd.hpp>
  22. #include <boost/container/new_allocator.hpp> //new_allocator
  23. #include <boost/container/throw_exception.hpp>
  24. // container/detail
  25. #include <boost/container/detail/mpl.hpp>
  26. #include <boost/container/detail/tree.hpp>
  27. #include <boost/container/detail/type_traits.hpp>
  28. #include <boost/container/detail/value_init.hpp>
  29. #include <boost/container/detail/pair.hpp>
  30. #include <boost/container/detail/pair_key_mapped_of_value.hpp>
  31. // move
  32. #include <boost/move/traits.hpp>
  33. #include <boost/move/utility_core.hpp>
  34. // move/detail
  35. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  36. #include <boost/move/detail/fwd_macros.hpp>
  37. #endif
  38. #include <boost/move/detail/move_helpers.hpp>
  39. // intrusive/detail
  40. #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
  41. #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal
  42. // other
  43. #include <boost/static_assert.hpp>
  44. #include <boost/core/no_exceptions_support.hpp>
  45. // std
  46. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  47. #include <initializer_list>
  48. #endif
  49. namespace boost {
  50. namespace container {
  51. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  52. //! A map is a kind of associative container that supports unique keys (contains at
  53. //! most one of each key value) and provides for fast retrieval of values of another
  54. //! type T based on the keys. The map class supports bidirectional iterators.
  55. //!
  56. //! A map satisfies all of the requirements of a container and of a reversible
  57. //! container and of an associative container. The <code>value_type</code> stored
  58. //! by this container is the value_type is std::pair<const Key, T>.
  59. //!
  60. //! \tparam Key is the key_type of the map
  61. //! \tparam T is the <code>mapped_type</code>
  62. //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
  63. //! \tparam Allocator is the allocator to allocate the <code>value_type</code>s
  64. //! (e.g. <i>allocator< std::pair<const Key, T> > </i>).
  65. //! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options.
  66. template < class Key, class T, class Compare = std::less<Key>
  67. , class Allocator = new_allocator< std::pair< const Key, T> >, class Options = tree_assoc_defaults >
  68. #else
  69. template <class Key, class T, class Compare, class Allocator, class Options>
  70. #endif
  71. class map
  72. ///@cond
  73. : public dtl::tree
  74. < std::pair<const Key, T>
  75. , dtl::select1st<Key>
  76. , Compare, Allocator, Options>
  77. ///@endcond
  78. {
  79. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  80. private:
  81. BOOST_COPYABLE_AND_MOVABLE(map)
  82. typedef dtl::select1st<Key> select_1st_t;
  83. typedef std::pair<const Key, T> value_type_impl;
  84. typedef dtl::tree
  85. <value_type_impl, select_1st_t, Compare, Allocator, Options> base_t;
  86. typedef dtl::pair <Key, T> movable_value_type_impl;
  87. typedef typename base_t::value_compare value_compare_impl;
  88. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  89. public:
  90. //////////////////////////////////////////////
  91. //
  92. // types
  93. //
  94. //////////////////////////////////////////////
  95. typedef Key key_type;
  96. typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
  97. typedef T mapped_type;
  98. typedef typename boost::container::allocator_traits<Allocator>::value_type value_type;
  99. typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
  100. typedef typename boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
  101. typedef typename boost::container::allocator_traits<Allocator>::reference reference;
  102. typedef typename boost::container::allocator_traits<Allocator>::const_reference const_reference;
  103. typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
  104. typedef typename boost::container::allocator_traits<Allocator>::difference_type difference_type;
  105. typedef Allocator allocator_type;
  106. typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
  107. typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
  108. typedef Compare key_compare;
  109. typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
  110. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
  111. typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
  112. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
  113. typedef std::pair<key_type, mapped_type> nonconst_value_type;
  114. typedef BOOST_CONTAINER_IMPDEF(movable_value_type_impl) movable_value_type;
  115. typedef BOOST_CONTAINER_IMPDEF(node_handle<
  116. typename base_t::stored_allocator_type
  117. BOOST_MOVE_I pair_key_mapped_of_value
  118. <key_type BOOST_MOVE_I mapped_type> >) node_type;
  119. typedef BOOST_CONTAINER_IMPDEF
  120. (insert_return_type_base<iterator BOOST_MOVE_I node_type>) insert_return_type;
  121. //allocator_type::value_type type must be std::pair<CONST Key, T>
  122. BOOST_STATIC_ASSERT((dtl::is_same<typename allocator_type::value_type, std::pair<const Key, T> >::value));
  123. //////////////////////////////////////////////
  124. //
  125. // construct/copy/destroy
  126. //
  127. //////////////////////////////////////////////
  128. //! <b>Effects</b>: Default constructs an empty map.
  129. //!
  130. //! <b>Complexity</b>: Constant.
  131. BOOST_CONTAINER_FORCEINLINE
  132. map() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<Allocator>::value &&
  133. dtl::is_nothrow_default_constructible<Compare>::value)
  134. : base_t()
  135. {}
  136. //! <b>Effects</b>: Constructs an empty map using the specified comparison object
  137. //! and allocator.
  138. //!
  139. //! <b>Complexity</b>: Constant.
  140. BOOST_CONTAINER_FORCEINLINE map(const Compare& comp, const allocator_type& a)
  141. : base_t(comp, a)
  142. {}
  143. //! <b>Effects</b>: Constructs an empty map using the specified comparison object.
  144. //!
  145. //! <b>Complexity</b>: Constant.
  146. BOOST_CONTAINER_FORCEINLINE explicit map(const Compare& comp)
  147. : base_t(comp)
  148. {}
  149. //! <b>Effects</b>: Constructs an empty map using the specified allocator.
  150. //!
  151. //! <b>Complexity</b>: Constant.
  152. BOOST_CONTAINER_FORCEINLINE explicit map(const allocator_type& a)
  153. : base_t(a)
  154. {}
  155. //! <b>Effects</b>: Constructs an empty map and
  156. //! inserts elements from the range [first ,last ).
  157. //!
  158. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  159. //! the predicate and otherwise N logN, where N is last - first.
  160. template <class InputIterator>
  161. BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last)
  162. : base_t(true, first, last)
  163. {}
  164. //! <b>Effects</b>: Constructs an empty map using the specified
  165. //! allocator, and inserts elements from the range [first ,last ).
  166. //!
  167. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  168. //! the predicate and otherwise N logN, where N is last - first.
  169. template <class InputIterator>
  170. BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last, const allocator_type& a)
  171. : base_t(true, first, last, Compare(), a)
  172. {}
  173. //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
  174. //! inserts elements from the range [first ,last ).
  175. //!
  176. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  177. //! the predicate and otherwise N logN, where N is last - first.
  178. template <class InputIterator>
  179. BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last, const Compare& comp)
  180. : base_t(true, first, last, comp)
  181. {}
  182. //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
  183. //! allocator, and inserts elements from the range [first ,last ).
  184. //!
  185. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  186. //! the predicate and otherwise N logN, where N is last - first.
  187. template <class InputIterator>
  188. BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
  189. : base_t(true, first, last, comp, a)
  190. {}
  191. //! <b>Effects</b>: Constructs an empty map and
  192. //! inserts elements from the ordered unique range [first ,last). This function
  193. //! is more efficient than the normal range creation for ordered ranges.
  194. //!
  195. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
  196. //! unique values.
  197. //!
  198. //! <b>Complexity</b>: Linear in N.
  199. //!
  200. //! <b>Note</b>: Non-standard extension.
  201. template <class InputIterator>
  202. BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, InputIterator first, InputIterator last)
  203. : base_t(ordered_range, first, last)
  204. {}
  205. //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
  206. //! inserts elements from the ordered unique range [first ,last). This function
  207. //! is more efficient than the normal range creation for ordered ranges.
  208. //!
  209. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
  210. //! unique values.
  211. //!
  212. //! <b>Complexity</b>: Linear in N.
  213. //!
  214. //! <b>Note</b>: Non-standard extension.
  215. template <class InputIterator>
  216. BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp)
  217. : base_t(ordered_range, first, last, comp)
  218. {}
  219. //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
  220. //! allocator, and inserts elements from the ordered unique range [first ,last). This function
  221. //! is more efficient than the normal range creation for ordered ranges.
  222. //!
  223. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
  224. //! unique values.
  225. //!
  226. //! <b>Complexity</b>: Linear in N.
  227. //!
  228. //! <b>Note</b>: Non-standard extension.
  229. template <class InputIterator>
  230. BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, InputIterator first, InputIterator last
  231. , const Compare& comp, const allocator_type& a)
  232. : base_t(ordered_range, first, last, comp, a)
  233. {}
  234. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  235. //! <b>Effects</b>: Constructs an empty map and
  236. //! inserts elements from the range [il.begin(), il.end()).
  237. //!
  238. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted according
  239. //! to the predicate and otherwise N logN, where N is il.first() - il.end().
  240. BOOST_CONTAINER_FORCEINLINE map(std::initializer_list<value_type> il)
  241. : base_t(true, il.begin(), il.end())
  242. {}
  243. //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
  244. //! inserts elements from the range [il.begin(), il.end()).
  245. //!
  246. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  247. //! the predicate and otherwise N logN, where N is il.first() - il.end().
  248. BOOST_CONTAINER_FORCEINLINE map(std::initializer_list<value_type> il, const Compare& comp)
  249. : base_t(true, il.begin(), il.end(), comp)
  250. {}
  251. //! <b>Effects</b>: Constructs an empty map using the specified
  252. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  253. //!
  254. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  255. //! the predicate and otherwise N logN, where N is il.first() - il.end().
  256. BOOST_CONTAINER_FORCEINLINE map(std::initializer_list<value_type> il, const allocator_type& a)
  257. : base_t(true, il.begin(), il.end(), Compare(), a)
  258. {}
  259. //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
  260. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  261. //!
  262. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  263. //! the predicate and otherwise N logN, where N is il.first() - il.end().
  264. BOOST_CONTAINER_FORCEINLINE map(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
  265. : base_t(true, il.begin(), il.end(), comp, a)
  266. {}
  267. //! <b>Effects</b>: Constructs an empty map and inserts elements from the ordered unique range [il.begin(), il.end()).
  268. //! This function is more efficient than the normal range creation for ordered ranges.
  269. //!
  270. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  271. //! unique values.
  272. //!
  273. //! <b>Complexity</b>: Linear in N.
  274. //!
  275. //! <b>Note</b>: Non-standard extension.
  276. BOOST_CONTAINER_FORCEINLINE map(ordered_unique_range_t, std::initializer_list<value_type> il)
  277. : base_t(ordered_range, il.begin(), il.end())
  278. {}
  279. //! <b>Effects</b>: Constructs an empty map using the specified comparison object,
  280. //! and inserts elements from the ordered unique range [il.begin(), il.end()). This function
  281. //! is more efficient than the normal range creation for ordered ranges.
  282. //!
  283. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  284. //! unique values.
  285. //!
  286. //! <b>Complexity</b>: Linear in N.
  287. //!
  288. //! <b>Note</b>: Non-standard extension.
  289. BOOST_CONTAINER_FORCEINLINE map(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp)
  290. : base_t(ordered_range, il.begin(), il.end(), comp)
  291. {}
  292. //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
  293. //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
  294. //! is more efficient than the normal range creation for ordered ranges.
  295. //!
  296. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  297. //! unique values.
  298. //!
  299. //! <b>Complexity</b>: Linear in N.
  300. //!
  301. //! <b>Note</b>: Non-standard extension.
  302. BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, std::initializer_list<value_type> il
  303. , const Compare& comp, const allocator_type& a)
  304. : base_t(ordered_range, il.begin(), il.end(), comp, a)
  305. {}
  306. #endif
  307. //! <b>Effects</b>: Copy constructs a map.
  308. //!
  309. //! <b>Complexity</b>: Linear in x.size().
  310. BOOST_CONTAINER_FORCEINLINE map(const map& x)
  311. : base_t(static_cast<const base_t&>(x))
  312. {}
  313. //! <b>Effects</b>: Move constructs a map. Constructs *this using x's resources.
  314. //!
  315. //! <b>Complexity</b>: Constant.
  316. //!
  317. //! <b>Postcondition</b>: x is emptied.
  318. BOOST_CONTAINER_FORCEINLINE map(BOOST_RV_REF(map) x)
  319. BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
  320. : base_t(BOOST_MOVE_BASE(base_t, x))
  321. {}
  322. //! <b>Effects</b>: Copy constructs a map using the specified allocator.
  323. //!
  324. //! <b>Complexity</b>: Linear in x.size().
  325. BOOST_CONTAINER_FORCEINLINE map(const map& x, const allocator_type &a)
  326. : base_t(static_cast<const base_t&>(x), a)
  327. {}
  328. //! <b>Effects</b>: Move constructs a map using the specified allocator.
  329. //! Constructs *this using x's resources.
  330. //!
  331. //! <b>Complexity</b>: Constant if x == x.get_allocator(), linear otherwise.
  332. //!
  333. //! <b>Postcondition</b>: x is emptied.
  334. BOOST_CONTAINER_FORCEINLINE map(BOOST_RV_REF(map) x, const allocator_type &a)
  335. : base_t(BOOST_MOVE_BASE(base_t, x), a)
  336. {}
  337. //! <b>Effects</b>: Makes *this a copy of x.
  338. //!
  339. //! <b>Complexity</b>: Linear in x.size().
  340. BOOST_CONTAINER_FORCEINLINE map& operator=(BOOST_COPY_ASSIGN_REF(map) x)
  341. { return static_cast<map&>(this->base_t::operator=(static_cast<const base_t&>(x))); }
  342. //! <b>Effects</b>: this->swap(x.get()).
  343. //!
  344. //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
  345. //! is false and (allocation throws or value_type's move constructor throws)
  346. //!
  347. //! <b>Complexity</b>: Constant if allocator_traits_type::
  348. //! propagate_on_container_move_assignment is true or
  349. //! this->get>allocator() == x.get_allocator(). Linear otherwise.
  350. BOOST_CONTAINER_FORCEINLINE map& operator=(BOOST_RV_REF(map) x)
  351. BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
  352. allocator_traits_type::is_always_equal::value) &&
  353. boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
  354. { return static_cast<map&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
  355. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  356. //! <b>Effects</b>: Assign content of il to *this.
  357. //!
  358. BOOST_CONTAINER_FORCEINLINE map& operator=(std::initializer_list<value_type> il)
  359. {
  360. this->clear();
  361. insert(il.begin(), il.end());
  362. return *this;
  363. }
  364. #endif
  365. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  366. //! <b>Effects</b>: Returns a copy of the allocator that
  367. //! was passed to the object's constructor.
  368. //!
  369. //! <b>Complexity</b>: Constant.
  370. allocator_type get_allocator() const;
  371. //! <b>Effects</b>: Returns a reference to the internal allocator.
  372. //!
  373. //! <b>Throws</b>: Nothing
  374. //!
  375. //! <b>Complexity</b>: Constant.
  376. //!
  377. //! <b>Note</b>: Non-standard extension.
  378. stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW;
  379. //! <b>Effects</b>: Returns a reference to the internal allocator.
  380. //!
  381. //! <b>Throws</b>: Nothing
  382. //!
  383. //! <b>Complexity</b>: Constant.
  384. //!
  385. //! <b>Note</b>: Non-standard extension.
  386. const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW;
  387. //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
  388. //!
  389. //! <b>Throws</b>: Nothing.
  390. //!
  391. //! <b>Complexity</b>: Constant.
  392. iterator begin() BOOST_NOEXCEPT_OR_NOTHROW;
  393. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  394. //!
  395. //! <b>Throws</b>: Nothing.
  396. //!
  397. //! <b>Complexity</b>: Constant.
  398. const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW;
  399. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  400. //!
  401. //! <b>Throws</b>: Nothing.
  402. //!
  403. //! <b>Complexity</b>: Constant.
  404. const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  405. //! <b>Effects</b>: Returns an iterator to the end of the container.
  406. //!
  407. //! <b>Throws</b>: Nothing.
  408. //!
  409. //! <b>Complexity</b>: Constant.
  410. iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
  411. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  412. //!
  413. //! <b>Throws</b>: Nothing.
  414. //!
  415. //! <b>Complexity</b>: Constant.
  416. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
  417. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  418. //!
  419. //! <b>Throws</b>: Nothing.
  420. //!
  421. //! <b>Complexity</b>: Constant.
  422. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
  423. //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
  424. //! of the reversed container.
  425. //!
  426. //! <b>Throws</b>: Nothing.
  427. //!
  428. //! <b>Complexity</b>: Constant.
  429. reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
  430. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  431. //! of the reversed container.
  432. //!
  433. //! <b>Throws</b>: Nothing.
  434. //!
  435. //! <b>Complexity</b>: Constant.
  436. const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  437. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  438. //! of the reversed container.
  439. //!
  440. //! <b>Throws</b>: Nothing.
  441. //!
  442. //! <b>Complexity</b>: Constant.
  443. const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  444. //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
  445. //! of the reversed container.
  446. //!
  447. //! <b>Throws</b>: Nothing.
  448. //!
  449. //! <b>Complexity</b>: Constant.
  450. reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
  451. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  452. //! of the reversed container.
  453. //!
  454. //! <b>Throws</b>: Nothing.
  455. //!
  456. //! <b>Complexity</b>: Constant.
  457. const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
  458. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  459. //! of the reversed container.
  460. //!
  461. //! <b>Throws</b>: Nothing.
  462. //!
  463. //! <b>Complexity</b>: Constant.
  464. const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
  465. //! <b>Effects</b>: Returns true if the container contains no elements.
  466. //!
  467. //! <b>Throws</b>: Nothing.
  468. //!
  469. //! <b>Complexity</b>: Constant.
  470. bool empty() const BOOST_NOEXCEPT_OR_NOTHROW;
  471. //! <b>Effects</b>: Returns the number of the elements contained in the container.
  472. //!
  473. //! <b>Throws</b>: Nothing.
  474. //!
  475. //! <b>Complexity</b>: Constant.
  476. size_type size() const BOOST_NOEXCEPT_OR_NOTHROW;
  477. //! <b>Effects</b>: Returns the largest possible size of the container.
  478. //!
  479. //! <b>Throws</b>: Nothing.
  480. //!
  481. //! <b>Complexity</b>: Constant.
  482. size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW;
  483. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  484. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  485. //! <b>Effects</b>: If there is no key equivalent to x in the map, inserts
  486. //! value_type(x, T()) into the map.
  487. //!
  488. //! <b>Returns</b>: A reference to the mapped_type corresponding to x in *this.
  489. //!
  490. //! <b>Complexity</b>: Logarithmic.
  491. mapped_type& operator[](const key_type &k);
  492. //! <b>Effects</b>: If there is no key equivalent to x in the map, inserts
  493. //! value_type(boost::move(x), T()) into the map (the key is move-constructed)
  494. //!
  495. //! <b>Returns</b>: A reference to the mapped_type corresponding to x in *this.
  496. //!
  497. //! <b>Complexity</b>: Logarithmic.
  498. mapped_type& operator[](key_type &&k);
  499. #elif defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN)
  500. //in compilers like GCC 3.4, we can't catch temporaries
  501. BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](const key_type &k) { return this->priv_subscript(k); }
  502. BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](BOOST_RV_REF(key_type) k) { return this->priv_subscript(::boost::move(k)); }
  503. #else
  504. BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript)
  505. #endif
  506. //! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
  507. //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
  508. //! as if by insert, constructing it from value_type(k, forward<M>(obj)).
  509. //!
  510. //! No iterators or references are invalidated. If the insertion is successful, pointers and references
  511. //! to the element obtained while it is held in the node handle are invalidated, and pointers and
  512. //! references obtained to that element before it was extracted become valid.
  513. //!
  514. //! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
  515. //! took place. The iterator component is pointing at the element that was inserted or updated.
  516. //!
  517. //! <b>Complexity</b>: Logarithmic in the size of the container.
  518. template <class M>
  519. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(const key_type& k, BOOST_FWD_REF(M) obj)
  520. { return this->base_t::insert_or_assign(const_iterator(), k, ::boost::forward<M>(obj)); }
  521. //! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
  522. //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
  523. //! as if by insert, constructing it from value_type(k, move(obj)).
  524. //!
  525. //! No iterators or references are invalidated. If the insertion is successful, pointers and references
  526. //! to the element obtained while it is held in the node handle are invalidated, and pointers and
  527. //! references obtained to that element before it was extracted become valid.
  528. //!
  529. //! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
  530. //! took place. The iterator component is pointing at the element that was inserted or updated.
  531. //!
  532. //! <b>Complexity</b>: Logarithmic in the size of the container.
  533. template <class M>
  534. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
  535. { return this->base_t::insert_or_assign(const_iterator(), ::boost::move(k), ::boost::forward<M>(obj)); }
  536. //! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
  537. //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
  538. //! as if by insert, constructing it from value_type(k, forward<M>(obj)) and the new element
  539. //! to the container as close as possible to the position just before hint.
  540. //!
  541. //! No iterators or references are invalidated. If the insertion is successful, pointers and references
  542. //! to the element obtained while it is held in the node handle are invalidated, and pointers and
  543. //! references obtained to that element before it was extracted become valid.
  544. //!
  545. //! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
  546. //! took place. The iterator component is pointing at the element that was inserted or updated.
  547. //!
  548. //! <b>Complexity</b>: Logarithmic in the size of the container in general, but amortized constant if
  549. //! the new element is inserted just before hint.
  550. template <class M>
  551. BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, const key_type& k, BOOST_FWD_REF(M) obj)
  552. { return this->base_t::insert_or_assign(hint, k, ::boost::forward<M>(obj)); }
  553. //! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
  554. //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
  555. //! as if by insert, constructing it from value_type(k, move(obj)) and the new element
  556. //! to the container as close as possible to the position just before hint.
  557. //!
  558. //! No iterators or references are invalidated. If the insertion is successful, pointers and references
  559. //! to the element obtained while it is held in the node handle are invalidated, and pointers and
  560. //! references obtained to that element before it was extracted become valid.
  561. //!
  562. //! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
  563. //! took place. The iterator component is pointing at the element that was inserted or updated.
  564. //!
  565. //! <b>Complexity</b>: Logarithmic in the size of the container in general, but amortized constant if
  566. //! the new element is inserted just before hint.
  567. template <class M>
  568. BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
  569. { return this->base_t::insert_or_assign(hint, ::boost::move(k), ::boost::forward<M>(obj)); }
  570. //! <b>Returns</b>: A reference to the element whose key is equivalent to x.
  571. //! Throws: An exception object of type out_of_range if no such element is present.
  572. //! <b>Complexity</b>: logarithmic.
  573. T& at(const key_type& k)
  574. {
  575. iterator i = this->find(k);
  576. if(i == this->end()){
  577. throw_out_of_range("map::at key not found");
  578. }
  579. return i->second;
  580. }
  581. //! <b>Returns</b>: A reference to the element whose key is equivalent to x.
  582. //! Throws: An exception object of type out_of_range if no such element is present.
  583. //! <b>Complexity</b>: logarithmic.
  584. const T& at(const key_type& k) const
  585. {
  586. const_iterator i = this->find(k);
  587. if(i == this->end()){
  588. throw_out_of_range("map::at key not found");
  589. }
  590. return i->second;
  591. }
  592. //////////////////////////////////////////////
  593. //
  594. // modifiers
  595. //
  596. //////////////////////////////////////////////
  597. //! <b>Effects</b>: Inserts x if and only if there is no element in the container
  598. //! with key equivalent to the key of x.
  599. //!
  600. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  601. //! if the insertion takes place, and the iterator component of the pair
  602. //! points to the element with key equivalent to the key of x.
  603. //!
  604. //! <b>Complexity</b>: Logarithmic.
  605. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(const value_type& x)
  606. { return this->base_t::insert_unique(x); }
  607. //! <b>Effects</b>: Inserts a new value_type created from the pair if and only if
  608. //! there is no element in the container with key equivalent to the key of x.
  609. //!
  610. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  611. //! if the insertion takes place, and the iterator component of the pair
  612. //! points to the element with key equivalent to the key of x.
  613. //!
  614. //! <b>Complexity</b>: Logarithmic.
  615. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(const nonconst_value_type& x)
  616. { return this->try_emplace(x.first, x.second); }
  617. //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
  618. //! only if there is no element in the container with key equivalent to the key of x.
  619. //!
  620. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  621. //! if the insertion takes place, and the iterator component of the pair
  622. //! points to the element with key equivalent to the key of x.
  623. //!
  624. //! <b>Complexity</b>: Logarithmic.
  625. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(nonconst_value_type) x)
  626. { return this->try_emplace(boost::move(x.first), boost::move(x.second)); }
  627. //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
  628. //! only if there is no element in the container with key equivalent to the key of x.
  629. //!
  630. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  631. //! if the insertion takes place, and the iterator component of the pair
  632. //! points to the element with key equivalent to the key of x.
  633. //!
  634. //! <b>Complexity</b>: Logarithmic.
  635. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(movable_value_type) x)
  636. { return this->try_emplace(boost::move(x.first), boost::move(x.second)); }
  637. //! <b>Effects</b>: Move constructs a new value from x if and only if there is
  638. //! no element in the container with key equivalent to the key of x.
  639. //!
  640. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  641. //! if the insertion takes place, and the iterator component of the pair
  642. //! points to the element with key equivalent to the key of x.
  643. //!
  644. //! <b>Complexity</b>: Logarithmic.
  645. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(value_type) x)
  646. { return this->base_t::insert_unique(boost::move(x)); }
  647. //! <b>Effects</b>: Inserts a copy of x in the container if and only if there is
  648. //! no element in the container with key equivalent to the key of x.
  649. //! p is a hint pointing to where the insert should start to search.
  650. //!
  651. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  652. //! to the key of x.
  653. //!
  654. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  655. //! is inserted right before p.
  656. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
  657. { return this->base_t::insert_unique(p, x); }
  658. //! <b>Effects</b>: Move constructs a new value from x if and only if there is
  659. //! no element in the container with key equivalent to the key of x.
  660. //! p is a hint pointing to where the insert should start to search.
  661. //!
  662. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  663. //! to the key of x.
  664. //!
  665. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  666. //! is inserted right before p.
  667. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(nonconst_value_type) x)
  668. { return this->try_emplace(p, boost::move(x.first), boost::move(x.second)); }
  669. //! <b>Effects</b>: Move constructs a new value from x if and only if there is
  670. //! no element in the container with key equivalent to the key of x.
  671. //! p is a hint pointing to where the insert should start to search.
  672. //!
  673. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  674. //! to the key of x.
  675. //!
  676. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  677. //! is inserted right before p.
  678. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
  679. { return this->try_emplace(p, boost::move(x.first), boost::move(x.second)); }
  680. //! <b>Effects</b>: Inserts a copy of x in the container.
  681. //! p is a hint pointing to where the insert should start to search.
  682. //!
  683. //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
  684. //!
  685. //! <b>Complexity</b>: Logarithmic.
  686. iterator insert(const_iterator p, const nonconst_value_type& x)
  687. { return this->try_emplace(p, x.first, x.second); }
  688. //! <b>Effects</b>: Inserts an element move constructed from x in the container.
  689. //! p is a hint pointing to where the insert should start to search.
  690. //!
  691. //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
  692. //!
  693. //! <b>Complexity</b>: Logarithmic.
  694. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
  695. { return this->base_t::insert_unique(p, boost::move(x)); }
  696. //! <b>Requires</b>: first, last are not iterators into *this.
  697. //!
  698. //! <b>Effects</b>: inserts each element from the range [first,last) if and only
  699. //! if there is no element with key equivalent to the key of that element.
  700. //!
  701. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  702. template <class InputIterator>
  703. BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
  704. { this->base_t::insert_unique(first, last); }
  705. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  706. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
  707. //! if there is no element with key equivalent to the key of that element.
  708. //!
  709. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
  710. BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
  711. { this->base_t::insert_unique(il.begin(), il.end()); }
  712. #endif
  713. //! <b>Requires</b>: nh is empty or this->get_allocator() == nh.get_allocator().
  714. //!
  715. //! <b>Effects</b>: If nh is empty, has no effect. Otherwise, inserts the element owned
  716. //! by nh if and only if there is no element in the container with a key equivalent to nh.key().
  717. //!
  718. //! <b>Returns</b>: If nh is empty, insert_return_type.inserted is false, insert_return_type.position
  719. //! is end(), and insert_return_type.node is empty. Otherwise if the insertion took place,
  720. //! insert_return_type.inserted is true, insert_return_type.position points to the inserted element,
  721. //! and insert_return_type.node is empty; if the insertion failed, insert_return_type.inserted is
  722. //! false, insert_return_type.node has the previous value of nh, and insert_return_type.position
  723. //! points to an element with a key equivalent to nh.key().
  724. //!
  725. //! <b>Complexity</b>: Logarithmic
  726. insert_return_type insert(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  727. {
  728. typename base_t::node_type n(boost::move(nh));
  729. typename base_t::insert_return_type base_ret(this->base_t::insert_unique_node(boost::move(n)));
  730. return insert_return_type (base_ret.inserted, base_ret.position, boost::move(base_ret.node));
  731. }
  732. //! <b>Effects</b>: Same as `insert(node_type && nh)` but the element is inserted as close as possible
  733. //! to the position just prior to "hint".
  734. //!
  735. //! <b>Complexity</b>: logarithmic in general, but amortized constant if the element is inserted
  736. //! right before "hint".
  737. insert_return_type insert(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  738. {
  739. typename base_t::node_type n(boost::move(nh));
  740. typename base_t::insert_return_type base_ret(this->base_t::insert_unique_node(hint, boost::move(n)));
  741. return insert_return_type (base_ret.inserted, base_ret.position, boost::move(base_ret.node));
  742. }
  743. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  744. //! <b>Effects</b>: Inserts an object x of type T constructed with
  745. //! std::forward<Args>(args)... in the container if and only if there is
  746. //! no element in the container with an equivalent key.
  747. //! p is a hint pointing to where the insert should start to search.
  748. //!
  749. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  750. //! if the insertion takes place, and the iterator component of the pair
  751. //! points to the element with key equivalent to the key of x.
  752. //!
  753. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  754. //! is inserted right before p.
  755. template <class... Args>
  756. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_FWD_REF(Args)... args)
  757. { return this->base_t::emplace_unique(boost::forward<Args>(args)...); }
  758. //! <b>Effects</b>: Inserts an object of type T constructed with
  759. //! std::forward<Args>(args)... in the container if and only if there is
  760. //! no element in the container with an equivalent key.
  761. //! p is a hint pointing to where the insert should start to search.
  762. //!
  763. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  764. //! to the key of x.
  765. //!
  766. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  767. //! is inserted right before p.
  768. template <class... Args>
  769. BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
  770. { return this->base_t::emplace_hint_unique(p, boost::forward<Args>(args)...); }
  771. //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
  772. //! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
  773. //!
  774. //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
  775. //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
  776. //! forward_as_tuple(forward<Args>(args)...).
  777. //!
  778. //! <b>Returns</b>: The bool component of the returned pair is true if and only if the
  779. //! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
  780. //!
  781. //! <b>Complexity</b>: Logarithmic.
  782. template <class... Args>
  783. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k, BOOST_FWD_REF(Args)... args)
  784. { return this->base_t::try_emplace(const_iterator(), k, boost::forward<Args>(args)...); }
  785. //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
  786. //! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
  787. //!
  788. //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
  789. //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
  790. //! forward_as_tuple(forward<Args>(args)...).
  791. //!
  792. //! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
  793. //!
  794. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
  795. //! is inserted right before p.
  796. template <class... Args>
  797. BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k, BOOST_FWD_REF(Args)... args)
  798. { return this->base_t::try_emplace(hint, k, boost::forward<Args>(args)...).first; }
  799. //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
  800. //! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
  801. //!
  802. //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
  803. //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
  804. //! forward_as_tuple(forward<Args>(args)...).
  805. //!
  806. //! <b>Returns</b>: The bool component of the returned pair is true if and only if the
  807. //! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
  808. //!
  809. //! <b>Complexity</b>: Logarithmic.
  810. template <class... Args>
  811. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
  812. { return this->base_t::try_emplace(const_iterator(), boost::move(k), boost::forward<Args>(args)...); }
  813. //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
  814. //! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
  815. //!
  816. //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
  817. //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
  818. //! forward_as_tuple(forward<Args>(args)...).
  819. //!
  820. //! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
  821. //!
  822. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
  823. //! is inserted right before p.
  824. template <class... Args>
  825. BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
  826. { return this->base_t::try_emplace(hint, boost::move(k), boost::forward<Args>(args)...).first; }
  827. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  828. #define BOOST_CONTAINER_MAP_EMPLACE_CODE(N) \
  829. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  830. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_MOVE_UREF##N)\
  831. { return this->base_t::emplace_unique(BOOST_MOVE_FWD##N); }\
  832. \
  833. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  834. BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  835. { return this->base_t::emplace_hint_unique(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
  836. \
  837. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  838. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  839. { return this->base_t::try_emplace(const_iterator(), k BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
  840. \
  841. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  842. BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  843. { return this->base_t::try_emplace(hint, k BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first; }\
  844. \
  845. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  846. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  847. { return this->base_t::try_emplace(const_iterator(), boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
  848. \
  849. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  850. BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  851. { return this->base_t::try_emplace(hint, boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first; }\
  852. //
  853. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_MAP_EMPLACE_CODE)
  854. #undef BOOST_CONTAINER_MAP_EMPLACE_CODE
  855. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  856. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  857. //! <b>Effects</b>: Erases the element pointed to by p.
  858. //!
  859. //! <b>Returns</b>: Returns an iterator pointing to the element immediately
  860. //! following q prior to the element being erased. If no such element exists,
  861. //! returns end().
  862. //!
  863. //! <b>Complexity</b>: Amortized constant time
  864. iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW;
  865. //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
  866. //!
  867. //! <b>Returns</b>: Returns the number of erased elements.
  868. //!
  869. //! <b>Complexity</b>: log(size()) + count(k)
  870. size_type erase(const key_type& x) BOOST_NOEXCEPT_OR_NOTHROW;
  871. //! <b>Effects</b>: Erases all the elements in the range [first, last).
  872. //!
  873. //! <b>Returns</b>: Returns last.
  874. //!
  875. //! <b>Complexity</b>: log(size())+N where N is the distance from first to last.
  876. iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW;
  877. #endif
  878. //! <b>Effects</b>: Removes the first element in the container with key equivalent to k.
  879. //!
  880. //! <b>Returns</b>: A node_type owning the element if found, otherwise an empty node_type.
  881. //!
  882. //! <b>Complexity</b>: log(a.size()).
  883. node_type extract(const key_type& k)
  884. {
  885. typename base_t::node_type base_nh(this->base_t::extract(k));
  886. node_type nh(boost::move(base_nh));
  887. return BOOST_MOVE_RET(node_type, nh);
  888. }
  889. //! <b>Effects</b>: Removes the element pointed to by "position".
  890. //!
  891. //! <b>Returns</b>: A node_type owning the element, otherwise an empty node_type.
  892. //!
  893. //! <b>Complexity</b>: Amortized constant.
  894. node_type extract(const_iterator position)
  895. {
  896. typename base_t::node_type base_nh(this->base_t::extract(position));
  897. node_type nh(boost::move(base_nh));
  898. return BOOST_MOVE_RET(node_type, nh);
  899. }
  900. //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
  901. //!
  902. //! <b>Effects</b>: Attempts to extract each element in source and insert it into a using
  903. //! the comparison object of *this. If there is an element in a with key equivalent to the
  904. //! key of an element from source, then that element is not extracted from source.
  905. //!
  906. //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
  907. //! to those same elements but as members of *this. Iterators referring to the transferred
  908. //! elements will continue to refer to their elements, but they now behave as iterators into *this,
  909. //! not into source.
  910. //!
  911. //! <b>Throws</b>: Nothing unless the comparison object throws.
  912. //!
  913. //! <b>Complexity</b>: N log(a.size() + N) (N has the value source.size())
  914. template<class C2>
  915. BOOST_CONTAINER_FORCEINLINE void merge(map<Key, T, C2, Allocator, Options>& source)
  916. {
  917. typedef dtl::tree
  918. <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
  919. this->merge_unique(static_cast<base2_t&>(source));
  920. }
  921. //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
  922. template<class C2>
  923. BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG map<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
  924. { return this->merge(static_cast<map<Key, T, C2, Allocator, Options>&>(source)); }
  925. //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
  926. template<class C2>
  927. BOOST_CONTAINER_FORCEINLINE void merge(multimap<Key, T, C2, Allocator, Options>& source)
  928. {
  929. typedef dtl::tree
  930. <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
  931. this->base_t::merge_unique(static_cast<base2_t&>(source));
  932. }
  933. //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
  934. template<class C2>
  935. BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG multimap<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
  936. { return this->merge(static_cast<multimap<Key, T, C2, Allocator, Options>&>(source)); }
  937. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  938. //! <b>Effects</b>: Swaps the contents of *this and x.
  939. //!
  940. //! <b>Throws</b>: Nothing.
  941. //!
  942. //! <b>Complexity</b>: Constant.
  943. void swap(map& x)
  944. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  945. && boost::container::dtl::is_nothrow_swappable<Compare>::value )
  946. //! <b>Effects</b>: erase(a.begin(),a.end()).
  947. //!
  948. //! <b>Postcondition</b>: size() == 0.
  949. //!
  950. //! <b>Complexity</b>: linear in size().
  951. void clear() BOOST_NOEXCEPT_OR_NOTHROW;
  952. //! <b>Effects</b>: Returns the comparison object out
  953. //! of which a was constructed.
  954. //!
  955. //! <b>Complexity</b>: Constant.
  956. key_compare key_comp() const;
  957. //! <b>Effects</b>: Returns an object of value_compare constructed out
  958. //! of the comparison object.
  959. //!
  960. //! <b>Complexity</b>: Constant.
  961. value_compare value_comp() const;
  962. //! <b>Returns</b>: An iterator pointing to an element with the key
  963. //! equivalent to x, or end() if such an element is not found.
  964. //!
  965. //! <b>Complexity</b>: Logarithmic.
  966. iterator find(const key_type& x);
  967. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  968. //! equivalent to x, or end() if such an element is not found.
  969. //!
  970. //! <b>Complexity</b>: Logarithmic.
  971. const_iterator find(const key_type& x) const;
  972. //! <b>Requires</b>: This overload is available only if
  973. //! key_compare::is_transparent exists.
  974. //!
  975. //! <b>Returns</b>: An iterator pointing to an element with the key
  976. //! equivalent to x, or end() if such an element is not found.
  977. //!
  978. //! <b>Complexity</b>: Logarithmic.
  979. template<typename K>
  980. iterator find(const K& x);
  981. //! <b>Requires</b>: This overload is available only if
  982. //! key_compare::is_transparent exists.
  983. //!
  984. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  985. //! equivalent to x, or end() if such an element is not found.
  986. //!
  987. //! <b>Complexity</b>: Logarithmic.
  988. template<typename K>
  989. const_iterator find(const K& x) const;
  990. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  991. //! <b>Returns</b>: The number of elements with key equivalent to x.
  992. //!
  993. //! <b>Complexity</b>: log(size())+count(k)
  994. BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const
  995. { return static_cast<size_type>(this->find(x) != this->cend()); }
  996. //! <b>Requires</b>: This overload is available only if
  997. //! key_compare::is_transparent exists.
  998. //!
  999. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1000. //!
  1001. //! <b>Complexity</b>: log(size())+count(k)
  1002. template<typename K>
  1003. BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
  1004. { return static_cast<size_type>(this->find(x) != this->cend()); }
  1005. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1006. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1007. //! than k, or a.end() if such an element is not found.
  1008. //!
  1009. //! <b>Complexity</b>: Logarithmic
  1010. iterator lower_bound(const key_type& x);
  1011. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1012. //! less than k, or a.end() if such an element is not found.
  1013. //!
  1014. //! <b>Complexity</b>: Logarithmic
  1015. const_iterator lower_bound(const key_type& x) const;
  1016. //! <b>Requires</b>: This overload is available only if
  1017. //! key_compare::is_transparent exists.
  1018. //!
  1019. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1020. //! than k, or a.end() if such an element is not found.
  1021. //!
  1022. //! <b>Complexity</b>: Logarithmic
  1023. template<typename K>
  1024. iterator lower_bound(const K& x);
  1025. //! <b>Requires</b>: This overload is available only if
  1026. //! key_compare::is_transparent exists.
  1027. //!
  1028. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1029. //! less than k, or a.end() if such an element is not found.
  1030. //!
  1031. //! <b>Complexity</b>: Logarithmic
  1032. template<typename K>
  1033. const_iterator lower_bound(const K& x) const;
  1034. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1035. //! than x, or end() if such an element is not found.
  1036. //!
  1037. //! <b>Complexity</b>: Logarithmic
  1038. iterator upper_bound(const key_type& x);
  1039. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1040. //! less than x, or end() if such an element is not found.
  1041. //!
  1042. //! <b>Complexity</b>: Logarithmic
  1043. const_iterator upper_bound(const key_type& x) const;
  1044. //! <b>Requires</b>: This overload is available only if
  1045. //! key_compare::is_transparent exists.
  1046. //!
  1047. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1048. //! than x, or end() if such an element is not found.
  1049. //!
  1050. //! <b>Complexity</b>: Logarithmic
  1051. template<typename K>
  1052. iterator upper_bound(const K& x);
  1053. //! <b>Requires</b>: This overload is available only if
  1054. //! key_compare::is_transparent exists.
  1055. //!
  1056. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1057. //! less than x, or end() if such an element is not found.
  1058. //!
  1059. //! <b>Complexity</b>: Logarithmic
  1060. template<typename K>
  1061. const_iterator upper_bound(const K& x) const;
  1062. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1063. //!
  1064. //! <b>Complexity</b>: Logarithmic
  1065. std::pair<iterator,iterator> equal_range(const key_type& x);
  1066. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1067. //!
  1068. //! <b>Complexity</b>: Logarithmic
  1069. std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
  1070. //! <b>Requires</b>: This overload is available only if
  1071. //! key_compare::is_transparent exists.
  1072. //!
  1073. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1074. //!
  1075. //! <b>Complexity</b>: Logarithmic
  1076. template<typename K>
  1077. std::pair<iterator,iterator> equal_range(const K& x);
  1078. //! <b>Requires</b>: This overload is available only if
  1079. //! key_compare::is_transparent exists.
  1080. //!
  1081. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1082. //!
  1083. //! <b>Complexity</b>: Logarithmic
  1084. template<typename K>
  1085. std::pair<const_iterator,const_iterator> equal_range(const K& x) const;
  1086. //! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees.
  1087. //!
  1088. //! <b>Complexity</b>: Linear
  1089. void rebalance();
  1090. //! <b>Effects</b>: Returns true if x and y are equal
  1091. //!
  1092. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1093. friend bool operator==(const map& x, const map& y);
  1094. //! <b>Effects</b>: Returns true if x and y are unequal
  1095. //!
  1096. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1097. friend bool operator!=(const map& x, const map& y);
  1098. //! <b>Effects</b>: Returns true if x is less than y
  1099. //!
  1100. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1101. friend bool operator<(const map& x, const map& y);
  1102. //! <b>Effects</b>: Returns true if x is greater than y
  1103. //!
  1104. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1105. friend bool operator>(const map& x, const map& y);
  1106. //! <b>Effects</b>: Returns true if x is equal or less than y
  1107. //!
  1108. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1109. friend bool operator<=(const map& x, const map& y);
  1110. //! <b>Effects</b>: Returns true if x is equal or greater than y
  1111. //!
  1112. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1113. friend bool operator>=(const map& x, const map& y);
  1114. //! <b>Effects</b>: x.swap(y)
  1115. //!
  1116. //! <b>Complexity</b>: Constant.
  1117. friend void swap(map& x, map& y);
  1118. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1119. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1120. private:
  1121. template<class KeyConvertible>
  1122. BOOST_CONTAINER_FORCEINLINE mapped_type& priv_subscript(BOOST_FWD_REF(KeyConvertible) k)
  1123. {
  1124. return this->try_emplace(boost::forward<KeyConvertible>(k)).first->second;
  1125. }
  1126. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1127. };
  1128. #if __cplusplus >= 201703L
  1129. template <typename InputIterator>
  1130. map(InputIterator, InputIterator) ->
  1131. map< typename dtl::remove_const< typename iterator_traits<InputIterator>::value_type::first_type>::type
  1132. , typename iterator_traits<InputIterator>::value_type::second_type>;
  1133. template <typename InputIterator, typename Allocator>
  1134. map(InputIterator, InputIterator, Allocator const&) ->
  1135. map< typename dtl::remove_const< typename iterator_traits<InputIterator>::value_type::first_type>::type
  1136. , typename iterator_traits<InputIterator>::value_type::second_type
  1137. , std::less<typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type>
  1138. , Allocator>;
  1139. template <typename InputIterator, typename Compare>
  1140. map(InputIterator, InputIterator, Compare const&) ->
  1141. map< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1142. , typename iterator_traits<InputIterator>::value_type::second_type
  1143. , Compare>;
  1144. template <typename InputIterator, typename Compare, typename Allocator>
  1145. map(InputIterator, InputIterator, Compare const&, Allocator const&) ->
  1146. map< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1147. , typename iterator_traits<InputIterator>::value_type::second_type
  1148. , Compare
  1149. , Allocator>;
  1150. template <typename InputIterator>
  1151. map(ordered_unique_range_t, InputIterator, InputIterator) ->
  1152. map< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1153. , typename iterator_traits<InputIterator>::value_type::second_type>;
  1154. template <typename InputIterator, typename Allocator>
  1155. map(ordered_unique_range_t, InputIterator, InputIterator, Allocator const&) ->
  1156. map< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1157. , typename iterator_traits<InputIterator>::value_type::second_type
  1158. , std::less<typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type>
  1159. , Allocator>;
  1160. template <typename InputIterator, typename Compare>
  1161. map(ordered_unique_range_t, InputIterator, InputIterator, Compare const&) ->
  1162. map< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1163. , typename iterator_traits<InputIterator>::value_type::second_type
  1164. , Compare>;
  1165. template <typename InputIterator, typename Compare, typename Allocator>
  1166. map(ordered_unique_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
  1167. map< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1168. , typename iterator_traits<InputIterator>::value_type::second_type
  1169. , Compare
  1170. , Allocator>;
  1171. #endif
  1172. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1173. } //namespace container {
  1174. //!has_trivial_destructor_after_move<> == true_type
  1175. //!specialization for optimizations
  1176. template <class Key, class T, class Compare, class Allocator>
  1177. struct has_trivial_destructor_after_move<boost::container::map<Key, T, Compare, Allocator> >
  1178. {
  1179. typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
  1180. static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
  1181. ::boost::has_trivial_destructor_after_move<pointer>::value &&
  1182. ::boost::has_trivial_destructor_after_move<Compare>::value;
  1183. };
  1184. namespace container {
  1185. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1186. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  1187. //! A multimap is a kind of associative container that supports equivalent keys
  1188. //! (possibly containing multiple copies of the same key value) and provides for
  1189. //! fast retrieval of values of another type T based on the keys. The multimap class
  1190. //! supports bidirectional iterators.
  1191. //!
  1192. //! A multimap satisfies all of the requirements of a container and of a reversible
  1193. //! container and of an associative container. The <code>value_type</code> stored
  1194. //! by this container is the value_type is std::pair<const Key, T>.
  1195. //!
  1196. //! \tparam Key is the key_type of the map
  1197. //! \tparam Value is the <code>mapped_type</code>
  1198. //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
  1199. //! \tparam Allocator is the allocator to allocate the <code>value_type</code>s
  1200. //! (e.g. <i>allocator< std::pair<const Key, T> > </i>).
  1201. //! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options.
  1202. template < class Key, class T, class Compare = std::less<Key>
  1203. , class Allocator = new_allocator< std::pair< const Key, T> >, class Options = tree_assoc_defaults>
  1204. #else
  1205. template <class Key, class T, class Compare, class Allocator, class Options>
  1206. #endif
  1207. class multimap
  1208. ///@cond
  1209. : public dtl::tree
  1210. < std::pair<const Key, T>
  1211. , dtl::select1st<Key>
  1212. , Compare, Allocator, Options>
  1213. ///@endcond
  1214. {
  1215. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1216. private:
  1217. BOOST_COPYABLE_AND_MOVABLE(multimap)
  1218. typedef dtl::select1st<Key> select_1st_t;
  1219. typedef std::pair<const Key, T> value_type_impl;
  1220. typedef dtl::tree
  1221. <value_type_impl, select_1st_t, Compare, Allocator, Options> base_t;
  1222. typedef dtl::pair <Key, T> movable_value_type_impl;
  1223. typedef typename base_t::value_compare value_compare_impl;
  1224. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1225. typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
  1226. public:
  1227. //////////////////////////////////////////////
  1228. //
  1229. // types
  1230. //
  1231. //////////////////////////////////////////////
  1232. typedef Key key_type;
  1233. typedef T mapped_type;
  1234. typedef typename boost::container::allocator_traits<Allocator>::value_type value_type;
  1235. typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
  1236. typedef typename boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
  1237. typedef typename boost::container::allocator_traits<Allocator>::reference reference;
  1238. typedef typename boost::container::allocator_traits<Allocator>::const_reference const_reference;
  1239. typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
  1240. typedef typename boost::container::allocator_traits<Allocator>::difference_type difference_type;
  1241. typedef Allocator allocator_type;
  1242. typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
  1243. typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
  1244. typedef Compare key_compare;
  1245. typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
  1246. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
  1247. typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
  1248. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
  1249. typedef std::pair<key_type, mapped_type> nonconst_value_type;
  1250. typedef BOOST_CONTAINER_IMPDEF(movable_value_type_impl) movable_value_type;
  1251. typedef BOOST_CONTAINER_IMPDEF(node_handle<
  1252. typename base_t::stored_allocator_type
  1253. BOOST_MOVE_I pair_key_mapped_of_value
  1254. <key_type BOOST_MOVE_I mapped_type> >) node_type;
  1255. //allocator_type::value_type type must be std::pair<CONST Key, T>
  1256. BOOST_STATIC_ASSERT((dtl::is_same<typename allocator_type::value_type, std::pair<const Key, T> >::value));
  1257. //////////////////////////////////////////////
  1258. //
  1259. // construct/copy/destroy
  1260. //
  1261. //////////////////////////////////////////////
  1262. //! <b>Effects</b>: Default constructs an empty multimap.
  1263. //!
  1264. //! <b>Complexity</b>: Constant.
  1265. BOOST_CONTAINER_FORCEINLINE multimap()
  1266. BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<Allocator>::value &&
  1267. dtl::is_nothrow_default_constructible<Compare>::value)
  1268. : base_t()
  1269. {}
  1270. //! <b>Effects</b>: Constructs an empty multimap using the specified allocator
  1271. //! object and allocator.
  1272. //!
  1273. //! <b>Complexity</b>: Constant.
  1274. BOOST_CONTAINER_FORCEINLINE explicit multimap(const allocator_type& a)
  1275. : base_t(a)
  1276. {}
  1277. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison.
  1278. //!
  1279. //! <b>Complexity</b>: Constant.
  1280. BOOST_CONTAINER_FORCEINLINE explicit multimap(const Compare& comp)
  1281. : base_t(comp)
  1282. {}
  1283. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison and allocator.
  1284. //!
  1285. //! <b>Complexity</b>: Constant.
  1286. BOOST_CONTAINER_FORCEINLINE multimap(const Compare& comp, const allocator_type& a)
  1287. : base_t(comp, a)
  1288. {}
  1289. //! <b>Effects</b>: Constructs an empty multimap and
  1290. //! inserts elements from the range [first ,last ).
  1291. //!
  1292. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1293. //! the predicate and otherwise N logN, where N is last - first.
  1294. template <class InputIterator>
  1295. BOOST_CONTAINER_FORCEINLINE multimap(InputIterator first, InputIterator last)
  1296. : base_t(false, first, last)
  1297. {}
  1298. //! <b>Effects</b>: Constructs an empty multimap using the specified
  1299. //! allocator, and inserts elements from the range [first ,last ).
  1300. //!
  1301. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1302. //! the predicate and otherwise N logN, where N is last - first.
  1303. template <class InputIterator>
  1304. BOOST_CONTAINER_FORCEINLINE multimap(InputIterator first, InputIterator last, const allocator_type& a)
  1305. : base_t(false, first, last, Compare(), a)
  1306. {}
  1307. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  1308. //! inserts elements from the range [first ,last ).
  1309. //!
  1310. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1311. //! the predicate and otherwise N logN, where N is last - first.
  1312. template <class InputIterator>
  1313. BOOST_CONTAINER_FORCEINLINE multimap(InputIterator first, InputIterator last, const Compare& comp)
  1314. : base_t(false, first, last, comp)
  1315. {}
  1316. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object
  1317. //! and allocator, and inserts elements from the range [first ,last ).
  1318. //!
  1319. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1320. //! the predicate and otherwise N logN, where N is last - first.
  1321. template <class InputIterator>
  1322. BOOST_CONTAINER_FORCEINLINE multimap(InputIterator first, InputIterator last,
  1323. const Compare& comp, const allocator_type& a)
  1324. : base_t(false, first, last, comp, a)
  1325. {}
  1326. //! <b>Effects</b>: Constructs an empty multimap and
  1327. //! inserts elements from the ordered range [first ,last). This function
  1328. //! is more efficient than the normal range creation for ordered ranges.
  1329. //!
  1330. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1331. //!
  1332. //! <b>Complexity</b>: Linear in N.
  1333. //!
  1334. //! <b>Note</b>: Non-standard extension.
  1335. template <class InputIterator>
  1336. BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, InputIterator first, InputIterator last)
  1337. : base_t(ordered_range, first, last)
  1338. {}
  1339. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  1340. //! inserts elements from the ordered range [first ,last). This function
  1341. //! is more efficient than the normal range creation for ordered ranges.
  1342. //!
  1343. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1344. //!
  1345. //! <b>Complexity</b>: Linear in N.
  1346. //!
  1347. //! <b>Note</b>: Non-standard extension.
  1348. template <class InputIterator>
  1349. BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp)
  1350. : base_t(ordered_range, first, last, comp)
  1351. {}
  1352. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  1353. //! allocator, and inserts elements from the ordered range [first ,last). This function
  1354. //! is more efficient than the normal range creation for ordered ranges.
  1355. //!
  1356. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1357. //!
  1358. //! <b>Complexity</b>: Linear in N.
  1359. //!
  1360. //! <b>Note</b>: Non-standard extension.
  1361. template <class InputIterator>
  1362. BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp,
  1363. const allocator_type& a)
  1364. : base_t(ordered_range, first, last, comp, a)
  1365. {}
  1366. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1367. //! <b>Effects</b>: Constructs an empty multimap and
  1368. //! and inserts elements from the range [il.begin(), il.end()).
  1369. //!
  1370. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1371. //! the predicate and otherwise N logN, where N is il.first() - il.end().
  1372. BOOST_CONTAINER_FORCEINLINE multimap(std::initializer_list<value_type> il)
  1373. : base_t(false, il.begin(), il.end())
  1374. {}
  1375. //! <b>Effects</b>: Constructs an empty multimap using the specified
  1376. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  1377. //!
  1378. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1379. //! the predicate and otherwise N logN, where N is il.first() - il.end().
  1380. BOOST_CONTAINER_FORCEINLINE multimap(std::initializer_list<value_type> il, const allocator_type& a)
  1381. : base_t(false, il.begin(), il.end(), Compare(), a)
  1382. {}
  1383. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  1384. //! inserts elements from the range [il.begin(), il.end()).
  1385. //!
  1386. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1387. //! the predicate and otherwise N logN, where N is il.first() - il.end().
  1388. BOOST_CONTAINER_FORCEINLINE multimap(std::initializer_list<value_type> il, const Compare& comp)
  1389. : base_t(false, il.begin(), il.end(), comp)
  1390. {}
  1391. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  1392. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  1393. //!
  1394. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1395. //! the predicate and otherwise N logN, where N is il.first() - il.end().
  1396. BOOST_CONTAINER_FORCEINLINE multimap(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
  1397. : base_t(false, il.begin(), il.end(), comp, a)
  1398. {}
  1399. //! <b>Effects</b>: Constructs an empty map and
  1400. //! inserts elements from the ordered range [il.begin(), il.end()). This function
  1401. //! is more efficient than the normal range creation for ordered ranges.
  1402. //!
  1403. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1404. //!
  1405. //! <b>Complexity</b>: Linear in N.
  1406. //!
  1407. //! <b>Note</b>: Non-standard extension.
  1408. BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, std::initializer_list<value_type> il)
  1409. : base_t(ordered_range, il.begin(), il.end())
  1410. {}
  1411. //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
  1412. //! inserts elements from the ordered range [il.begin(), il.end()). This function
  1413. //! is more efficient than the normal range creation for ordered ranges.
  1414. //!
  1415. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1416. //!
  1417. //! <b>Complexity</b>: Linear in N.
  1418. //!
  1419. //! <b>Note</b>: Non-standard extension.
  1420. BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp)
  1421. : base_t(ordered_range, il.begin(), il.end(), comp)
  1422. {}
  1423. //! <b>Effects</b>: Constructs an empty map and
  1424. //! inserts elements from the ordered range [il.begin(), il.end()). This function
  1425. //! is more efficient than the normal range creation for ordered ranges.
  1426. //!
  1427. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1428. //!
  1429. //! <b>Complexity</b>: Linear in N.
  1430. //!
  1431. //! <b>Note</b>: Non-standard extension.
  1432. BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
  1433. : base_t(ordered_range, il.begin(), il.end(), comp, a)
  1434. {}
  1435. #endif
  1436. //! <b>Effects</b>: Copy constructs a multimap.
  1437. //!
  1438. //! <b>Complexity</b>: Linear in x.size().
  1439. BOOST_CONTAINER_FORCEINLINE multimap(const multimap& x)
  1440. : base_t(static_cast<const base_t&>(x))
  1441. {}
  1442. //! <b>Effects</b>: Move constructs a multimap. Constructs *this using x's resources.
  1443. //!
  1444. //! <b>Complexity</b>: Constant.
  1445. //!
  1446. //! <b>Postcondition</b>: x is emptied.
  1447. BOOST_CONTAINER_FORCEINLINE multimap(BOOST_RV_REF(multimap) x)
  1448. BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
  1449. : base_t(BOOST_MOVE_BASE(base_t, x))
  1450. {}
  1451. //! <b>Effects</b>: Copy constructs a multimap.
  1452. //!
  1453. //! <b>Complexity</b>: Linear in x.size().
  1454. BOOST_CONTAINER_FORCEINLINE multimap(const multimap& x, const allocator_type &a)
  1455. : base_t(static_cast<const base_t&>(x), a)
  1456. {}
  1457. //! <b>Effects</b>: Move constructs a multimap using the specified allocator.
  1458. //! Constructs *this using x's resources.
  1459. //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
  1460. //!
  1461. //! <b>Postcondition</b>: x is emptied.
  1462. BOOST_CONTAINER_FORCEINLINE multimap(BOOST_RV_REF(multimap) x, const allocator_type &a)
  1463. : base_t(BOOST_MOVE_BASE(base_t, x), a)
  1464. {}
  1465. //! <b>Effects</b>: Makes *this a copy of x.
  1466. //!
  1467. //! <b>Complexity</b>: Linear in x.size().
  1468. BOOST_CONTAINER_FORCEINLINE multimap& operator=(BOOST_COPY_ASSIGN_REF(multimap) x)
  1469. { return static_cast<multimap&>(this->base_t::operator=(static_cast<const base_t&>(x))); }
  1470. //! <b>Effects</b>: this->swap(x.get()).
  1471. //!
  1472. //! <b>Complexity</b>: Constant.
  1473. BOOST_CONTAINER_FORCEINLINE multimap& operator=(BOOST_RV_REF(multimap) x)
  1474. BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
  1475. allocator_traits_type::is_always_equal::value) &&
  1476. boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
  1477. { return static_cast<multimap&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
  1478. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1479. //! <b>Effects</b>: Assign content of il to *this.
  1480. //!
  1481. BOOST_CONTAINER_FORCEINLINE multimap& operator=(std::initializer_list<value_type> il)
  1482. {
  1483. this->clear();
  1484. insert(il.begin(), il.end());
  1485. return *this;
  1486. }
  1487. #endif
  1488. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1489. //! @copydoc ::boost::container::set::get_allocator()
  1490. allocator_type get_allocator() const;
  1491. //! @copydoc ::boost::container::set::get_stored_allocator()
  1492. stored_allocator_type &get_stored_allocator();
  1493. //! @copydoc ::boost::container::set::get_stored_allocator() const
  1494. const stored_allocator_type &get_stored_allocator() const;
  1495. //! @copydoc ::boost::container::set::begin()
  1496. iterator begin();
  1497. //! @copydoc ::boost::container::set::begin() const
  1498. const_iterator begin() const;
  1499. //! @copydoc ::boost::container::set::cbegin() const
  1500. const_iterator cbegin() const;
  1501. //! @copydoc ::boost::container::set::end()
  1502. iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
  1503. //! @copydoc ::boost::container::set::end() const
  1504. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
  1505. //! @copydoc ::boost::container::set::cend() const
  1506. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
  1507. //! @copydoc ::boost::container::set::rbegin()
  1508. reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
  1509. //! @copydoc ::boost::container::set::rbegin() const
  1510. const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  1511. //! @copydoc ::boost::container::set::crbegin() const
  1512. const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  1513. //! @copydoc ::boost::container::set::rend()
  1514. reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
  1515. //! @copydoc ::boost::container::set::rend() const
  1516. const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
  1517. //! @copydoc ::boost::container::set::crend() const
  1518. const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
  1519. //! @copydoc ::boost::container::set::empty() const
  1520. bool empty() const;
  1521. //! @copydoc ::boost::container::set::size() const
  1522. size_type size() const;
  1523. //! @copydoc ::boost::container::set::max_size() const
  1524. size_type max_size() const;
  1525. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1526. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1527. //! <b>Effects</b>: Inserts an object of type T constructed with
  1528. //! std::forward<Args>(args)... in the container.
  1529. //! p is a hint pointing to where the insert should start to search.
  1530. //!
  1531. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1532. //! to the key of x.
  1533. //!
  1534. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1535. //! is inserted right before p.
  1536. template <class... Args>
  1537. BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_FWD_REF(Args)... args)
  1538. { return this->base_t::emplace_equal(boost::forward<Args>(args)...); }
  1539. //! <b>Effects</b>: Inserts an object of type T constructed with
  1540. //! std::forward<Args>(args)... in the container.
  1541. //! p is a hint pointing to where the insert should start to search.
  1542. //!
  1543. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1544. //! to the key of x.
  1545. //!
  1546. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1547. //! is inserted right before p.
  1548. template <class... Args>
  1549. BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
  1550. { return this->base_t::emplace_hint_equal(p, boost::forward<Args>(args)...); }
  1551. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  1552. #define BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE(N) \
  1553. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  1554. BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_MOVE_UREF##N)\
  1555. { return this->base_t::emplace_equal(BOOST_MOVE_FWD##N); }\
  1556. \
  1557. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  1558. BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  1559. { return this->base_t::emplace_hint_equal(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
  1560. //
  1561. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE)
  1562. #undef BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE
  1563. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  1564. //! <b>Effects</b>: Inserts x and returns the iterator pointing to the
  1565. //! newly inserted element.
  1566. //!
  1567. //! <b>Complexity</b>: Logarithmic.
  1568. BOOST_CONTAINER_FORCEINLINE iterator insert(const value_type& x)
  1569. { return this->base_t::insert_equal(x); }
  1570. //! <b>Effects</b>: Inserts a new value constructed from x and returns
  1571. //! the iterator pointing to the newly inserted element.
  1572. //!
  1573. //! <b>Complexity</b>: Logarithmic.
  1574. BOOST_CONTAINER_FORCEINLINE iterator insert(const nonconst_value_type& x)
  1575. { return this->base_t::emplace_equal(x); }
  1576. //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
  1577. //! the iterator pointing to the newly inserted element.
  1578. //!
  1579. //! <b>Complexity</b>: Logarithmic.
  1580. BOOST_CONTAINER_FORCEINLINE iterator insert(BOOST_RV_REF(nonconst_value_type) x)
  1581. { return this->base_t::emplace_equal(boost::move(x)); }
  1582. //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
  1583. //! the iterator pointing to the newly inserted element.
  1584. //!
  1585. //! <b>Complexity</b>: Logarithmic.
  1586. iterator insert(BOOST_RV_REF(movable_value_type) x)
  1587. { return this->base_t::emplace_equal(boost::move(x)); }
  1588. //! <b>Effects</b>: Inserts a copy of x in the container.
  1589. //! p is a hint pointing to where the insert should start to search.
  1590. //!
  1591. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1592. //! to the key of x.
  1593. //!
  1594. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1595. //! is inserted right before p.
  1596. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
  1597. { return this->base_t::insert_equal(p, x); }
  1598. //! <b>Effects</b>: Inserts a new value constructed from x in the container.
  1599. //! p is a hint pointing to where the insert should start to search.
  1600. //!
  1601. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1602. //! to the key of x.
  1603. //!
  1604. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1605. //! is inserted right before p.
  1606. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const nonconst_value_type& x)
  1607. { return this->base_t::emplace_hint_equal(p, x); }
  1608. //! <b>Effects</b>: Inserts a new value move constructed from x in the container.
  1609. //! p is a hint pointing to where the insert should start to search.
  1610. //!
  1611. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1612. //! to the key of x.
  1613. //!
  1614. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1615. //! is inserted right before p.
  1616. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(nonconst_value_type) x)
  1617. { return this->base_t::emplace_hint_equal(p, boost::move(x)); }
  1618. //! <b>Effects</b>: Inserts a new value move constructed from x in the container.
  1619. //! p is a hint pointing to where the insert should start to search.
  1620. //!
  1621. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1622. //! to the key of x.
  1623. //!
  1624. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1625. //! is inserted right before p.
  1626. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
  1627. { return this->base_t::emplace_hint_equal(p, boost::move(x)); }
  1628. //! <b>Requires</b>: first, last are not iterators into *this.
  1629. //!
  1630. //! <b>Effects</b>: inserts each element from the range [first,last) .
  1631. //!
  1632. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  1633. template <class InputIterator>
  1634. BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
  1635. { this->base_t::insert_equal(first, last); }
  1636. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1637. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end().
  1638. //!
  1639. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
  1640. BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
  1641. { this->base_t::insert_equal(il.begin(), il.end()); }
  1642. #endif
  1643. //! <b>Requires</b>: nh is empty or this->get_allocator() == nh.get_allocator().
  1644. //!
  1645. //! <b>Effects/Returns</b>: If nh is empty, has no effect and returns end(). Otherwise, inserts
  1646. //! the element owned by nh and returns an iterator pointing to the newly inserted element.
  1647. //! If a range containing elements with keys equivalent to nh.key() exists,
  1648. //! the element is inserted at the end of that range. nh is always emptied.
  1649. //!
  1650. //! <b>Complexity</b>: Logarithmic
  1651. iterator insert(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  1652. {
  1653. typename base_t::node_type n(boost::move(nh));
  1654. return this->base_t::insert_equal_node(boost::move(n));
  1655. }
  1656. //! <b>Effects</b>: Same as `insert(node_type && nh)` but the element is inserted as close as possible
  1657. //! to the position just prior to "hint".
  1658. //!
  1659. //! <b>Complexity</b>: logarithmic in general, but amortized constant if the element is inserted
  1660. //! right before "hint".
  1661. iterator insert(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  1662. {
  1663. typename base_t::node_type n(boost::move(nh));
  1664. return this->base_t::insert_equal_node(hint, boost::move(n));
  1665. }
  1666. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1667. //! @copydoc ::boost::container::set::erase(const_iterator)
  1668. iterator erase(const_iterator p);
  1669. //! @copydoc ::boost::container::set::erase(const key_type&)
  1670. size_type erase(const key_type& x);
  1671. //! @copydoc ::boost::container::set::erase(const_iterator,const_iterator)
  1672. iterator erase(const_iterator first, const_iterator last);
  1673. #endif
  1674. //! @copydoc ::boost::container::map::extract(const key_type&)
  1675. node_type extract(const key_type& k)
  1676. {
  1677. typename base_t::node_type base_nh(this->base_t::extract(k));
  1678. return node_type(boost::move(base_nh));
  1679. }
  1680. //! @copydoc ::boost::container::map::extract(const_iterator)
  1681. node_type extract(const_iterator position)
  1682. {
  1683. typename base_t::node_type base_nh(this->base_t::extract(position));
  1684. return node_type (boost::move(base_nh));
  1685. }
  1686. //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
  1687. //!
  1688. //! <b>Effects</b>: Extracts each element in source and insert it into a using
  1689. //! the comparison object of *this.
  1690. //!
  1691. //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
  1692. //! to those same elements but as members of *this. Iterators referring to the transferred
  1693. //! elements will continue to refer to their elements, but they now behave as iterators into *this,
  1694. //! not into source.
  1695. //!
  1696. //! <b>Throws</b>: Nothing unless the comparison object throws.
  1697. //!
  1698. //! <b>Complexity</b>: N log(a.size() + N) (N has the value source.size())
  1699. template<class C2>
  1700. BOOST_CONTAINER_FORCEINLINE void merge(multimap<Key, T, C2, Allocator, Options>& source)
  1701. {
  1702. typedef dtl::tree
  1703. <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
  1704. this->base_t::merge_equal(static_cast<base2_t&>(source));
  1705. }
  1706. //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
  1707. template<class C2>
  1708. BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG multimap<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
  1709. { return this->merge(static_cast<multimap<Key, T, C2, Allocator, Options>&>(source)); }
  1710. //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
  1711. template<class C2>
  1712. BOOST_CONTAINER_FORCEINLINE void merge(map<Key, T, C2, Allocator, Options>& source)
  1713. {
  1714. typedef dtl::tree
  1715. <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
  1716. this->base_t::merge_equal(static_cast<base2_t&>(source));
  1717. }
  1718. //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
  1719. template<class C2>
  1720. BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG map<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
  1721. { return this->merge(static_cast<map<Key, T, C2, Allocator, Options>&>(source)); }
  1722. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1723. //! @copydoc ::boost::container::set::swap
  1724. void swap(multiset& x)
  1725. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  1726. && boost::container::dtl::is_nothrow_swappable<Compare>::value );
  1727. //! @copydoc ::boost::container::set::clear
  1728. void clear() BOOST_NOEXCEPT_OR_NOTHROW;
  1729. //! @copydoc ::boost::container::set::key_comp
  1730. key_compare key_comp() const;
  1731. //! @copydoc ::boost::container::set::value_comp
  1732. value_compare value_comp() const;
  1733. //! <b>Returns</b>: An iterator pointing to an element with the key
  1734. //! equivalent to x, or end() if such an element is not found.
  1735. //!
  1736. //! <b>Complexity</b>: Logarithmic.
  1737. iterator find(const key_type& x);
  1738. //! <b>Returns</b>: A const iterator pointing to an element with the key
  1739. //! equivalent to x, or end() if such an element is not found.
  1740. //!
  1741. //! <b>Complexity</b>: Logarithmic.
  1742. const_iterator find(const key_type& x) const;
  1743. //! <b>Requires</b>: This overload is available only if
  1744. //! key_compare::is_transparent exists.
  1745. //!
  1746. //! <b>Returns</b>: An iterator pointing to an element with the key
  1747. //! equivalent to x, or end() if such an element is not found.
  1748. //!
  1749. //! <b>Complexity</b>: Logarithmic.
  1750. template<typename K>
  1751. iterator find(const K& x);
  1752. //! <b>Requires</b>: This overload is available only if
  1753. //! key_compare::is_transparent exists.
  1754. //!
  1755. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  1756. //! equivalent to x, or end() if such an element is not found.
  1757. //!
  1758. //! <b>Complexity</b>: Logarithmic.
  1759. template<typename K>
  1760. const_iterator find(const K& x) const;
  1761. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1762. //!
  1763. //! <b>Complexity</b>: log(size())+count(k)
  1764. size_type count(const key_type& x) const;
  1765. //! <b>Requires</b>: This overload is available only if
  1766. //! key_compare::is_transparent exists.
  1767. //!
  1768. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1769. //!
  1770. //! <b>Complexity</b>: log(size())+count(k)
  1771. template<typename K>
  1772. size_type count(const K& x) const;
  1773. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1774. //! than k, or a.end() if such an element is not found.
  1775. //!
  1776. //! <b>Complexity</b>: Logarithmic
  1777. iterator lower_bound(const key_type& x);
  1778. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1779. //! less than k, or a.end() if such an element is not found.
  1780. //!
  1781. //! <b>Complexity</b>: Logarithmic
  1782. const_iterator lower_bound(const key_type& x) const;
  1783. //! <b>Requires</b>: This overload is available only if
  1784. //! key_compare::is_transparent exists.
  1785. //!
  1786. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1787. //! than k, or a.end() if such an element is not found.
  1788. //!
  1789. //! <b>Complexity</b>: Logarithmic
  1790. template<typename K>
  1791. iterator lower_bound(const K& x);
  1792. //! <b>Requires</b>: This overload is available only if
  1793. //! key_compare::is_transparent exists.
  1794. //!
  1795. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1796. //! less than k, or a.end() if such an element is not found.
  1797. //!
  1798. //! <b>Complexity</b>: Logarithmic
  1799. template<typename K>
  1800. const_iterator lower_bound(const K& x) const;
  1801. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1802. //! than x, or end() if such an element is not found.
  1803. //!
  1804. //! <b>Complexity</b>: Logarithmic
  1805. iterator upper_bound(const key_type& x);
  1806. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1807. //! less than x, or end() if such an element is not found.
  1808. //!
  1809. //! <b>Complexity</b>: Logarithmic
  1810. const_iterator upper_bound(const key_type& x) const;
  1811. //! <b>Requires</b>: This overload is available only if
  1812. //! key_compare::is_transparent exists.
  1813. //!
  1814. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1815. //! than x, or end() if such an element is not found.
  1816. //!
  1817. //! <b>Complexity</b>: Logarithmic
  1818. template<typename K>
  1819. iterator upper_bound(const K& x);
  1820. //! <b>Requires</b>: This overload is available only if
  1821. //! key_compare::is_transparent exists.
  1822. //!
  1823. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1824. //! less than x, or end() if such an element is not found.
  1825. //!
  1826. //! <b>Complexity</b>: Logarithmic
  1827. template<typename K>
  1828. const_iterator upper_bound(const K& x) const;
  1829. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1830. //!
  1831. //! <b>Complexity</b>: Logarithmic
  1832. std::pair<iterator,iterator> equal_range(const key_type& x);
  1833. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1834. //!
  1835. //! <b>Complexity</b>: Logarithmic
  1836. std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
  1837. //! <b>Requires</b>: This overload is available only if
  1838. //! key_compare::is_transparent exists.
  1839. //!
  1840. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1841. //!
  1842. //! <b>Complexity</b>: Logarithmic
  1843. template<typename K>
  1844. std::pair<iterator,iterator> equal_range(const K& x);
  1845. //! <b>Requires</b>: This overload is available only if
  1846. //! key_compare::is_transparent exists.
  1847. //!
  1848. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1849. //!
  1850. //! <b>Complexity</b>: Logarithmic
  1851. template<typename K>
  1852. std::pair<const_iterator,const_iterator> equal_range(const K& x) const;
  1853. //! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees.
  1854. //!
  1855. //! <b>Complexity</b>: Linear
  1856. void rebalance();
  1857. //! <b>Effects</b>: Returns true if x and y are equal
  1858. //!
  1859. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1860. friend bool operator==(const multimap& x, const multimap& y);
  1861. //! <b>Effects</b>: Returns true if x and y are unequal
  1862. //!
  1863. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1864. friend bool operator!=(const multimap& x, const multimap& y);
  1865. //! <b>Effects</b>: Returns true if x is less than y
  1866. //!
  1867. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1868. friend bool operator<(const multimap& x, const multimap& y);
  1869. //! <b>Effects</b>: Returns true if x is greater than y
  1870. //!
  1871. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1872. friend bool operator>(const multimap& x, const multimap& y);
  1873. //! <b>Effects</b>: Returns true if x is equal or less than y
  1874. //!
  1875. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1876. friend bool operator<=(const multimap& x, const multimap& y);
  1877. //! <b>Effects</b>: Returns true if x is equal or greater than y
  1878. //!
  1879. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1880. friend bool operator>=(const multimap& x, const multimap& y);
  1881. //! <b>Effects</b>: x.swap(y)
  1882. //!
  1883. //! <b>Complexity</b>: Constant.
  1884. friend void swap(multimap& x, multimap& y);
  1885. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1886. };
  1887. #if __cplusplus >= 201703L
  1888. template <typename InputIterator>
  1889. multimap(InputIterator, InputIterator) ->
  1890. multimap<typename dtl::remove_const< typename iterator_traits<InputIterator>::value_type::first_type>::type
  1891. , typename iterator_traits<InputIterator>::value_type::second_type>;
  1892. template <typename InputIterator, typename Allocator>
  1893. multimap(InputIterator, InputIterator, Allocator const&) ->
  1894. multimap<typename dtl::remove_const< typename iterator_traits<InputIterator>::value_type::first_type>::type
  1895. , typename iterator_traits<InputIterator>::value_type::second_type
  1896. , std::less<typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type>
  1897. , Allocator>;
  1898. template <typename InputIterator, typename Compare>
  1899. multimap(InputIterator, InputIterator, Compare const&) ->
  1900. multimap< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1901. , typename iterator_traits<InputIterator>::value_type::second_type
  1902. , Compare>;
  1903. template <typename InputIterator, typename Compare, typename Allocator>
  1904. multimap(InputIterator, InputIterator, Compare const&, Allocator const&) ->
  1905. multimap< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1906. , typename iterator_traits<InputIterator>::value_type::second_type
  1907. , Compare
  1908. , Allocator>;
  1909. template <typename InputIterator>
  1910. multimap(ordered_range_t, InputIterator, InputIterator) ->
  1911. multimap< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1912. , typename iterator_traits<InputIterator>::value_type::second_type>;
  1913. template <typename InputIterator, typename Allocator>
  1914. multimap(ordered_range_t, InputIterator, InputIterator, Allocator const&) ->
  1915. multimap< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1916. , typename iterator_traits<InputIterator>::value_type::second_type
  1917. , std::less<typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type>
  1918. , Allocator>;
  1919. template <typename InputIterator, typename Compare>
  1920. multimap(ordered_range_t, InputIterator, InputIterator, Compare const&) ->
  1921. multimap< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1922. , typename iterator_traits<InputIterator>::value_type::second_type
  1923. , Compare>;
  1924. template <typename InputIterator, typename Compare, typename Allocator>
  1925. multimap(ordered_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
  1926. multimap< typename dtl::remove_const<typename iterator_traits<InputIterator>::value_type::first_type>::type
  1927. , typename iterator_traits<InputIterator>::value_type::second_type
  1928. , Compare
  1929. , Allocator>;
  1930. #endif
  1931. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1932. } //namespace container {
  1933. //!has_trivial_destructor_after_move<> == true_type
  1934. //!specialization for optimizations
  1935. template <class Key, class T, class Compare, class Allocator>
  1936. struct has_trivial_destructor_after_move<boost::container::multimap<Key, T, Compare, Allocator> >
  1937. {
  1938. typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
  1939. static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
  1940. ::boost::has_trivial_destructor_after_move<pointer>::value &&
  1941. ::boost::has_trivial_destructor_after_move<Compare>::value;
  1942. };
  1943. namespace container {
  1944. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1945. }}
  1946. #include <boost/container/detail/config_end.hpp>
  1947. #endif // BOOST_CONTAINER_MAP_HPP