map.hpp 100 KB

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