map.hpp 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313
  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. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  876. //! <b>Effects</b>: Erases the element pointed to by p.
  877. //!
  878. //! <b>Returns</b>: Returns an iterator pointing to the element immediately
  879. //! following q prior to the element being erased. If no such element exists,
  880. //! returns end().
  881. //!
  882. //! <b>Complexity</b>: Amortized constant time
  883. iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW;
  884. //! <b>Effects</b>: Erases all the elements in the range [first, last).
  885. //!
  886. //! <b>Returns</b>: Returns last.
  887. //!
  888. //! <b>Complexity</b>: log(size())+N where N is the distance from first to last.
  889. iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW;
  890. #else
  891. using base_t::erase;
  892. #endif // #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  893. //! <b>Effects</b>: Removes the first element in the container with key equivalent to k.
  894. //!
  895. //! <b>Returns</b>: A node_type owning the element if found, otherwise an empty node_type.
  896. //!
  897. //! <b>Complexity</b>: log(size()).
  898. node_type extract(const key_type& k)
  899. {
  900. typename base_t::node_type base_nh(this->base_t::extract(k));
  901. node_type nh(boost::move(base_nh));
  902. return BOOST_MOVE_RET(node_type, nh);
  903. }
  904. //! <b>Effects</b>: Removes the element pointed to by "position".
  905. //!
  906. //! <b>Returns</b>: A node_type owning the element, otherwise an empty node_type.
  907. //!
  908. //! <b>Complexity</b>: Amortized constant.
  909. node_type extract(const_iterator position)
  910. {
  911. typename base_t::node_type base_nh(this->base_t::extract(position));
  912. node_type nh(boost::move(base_nh));
  913. return BOOST_MOVE_RET(node_type, nh);
  914. }
  915. //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
  916. //!
  917. //! <b>Effects</b>: Attempts to extract each element in source and insert it into a using
  918. //! the comparison object of *this. If there is an element in a with key equivalent to the
  919. //! key of an element from source, then that element is not extracted from source.
  920. //!
  921. //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
  922. //! to those same elements but as members of *this. Iterators referring to the transferred
  923. //! elements will continue to refer to their elements, but they now behave as iterators into *this,
  924. //! not into source.
  925. //!
  926. //! <b>Throws</b>: Nothing unless the comparison object throws.
  927. //!
  928. //! <b>Complexity</b>: N log(size() + N) (N has the value source.size())
  929. template<class C2>
  930. inline void merge(map<Key, T, C2, Allocator, Options>& source)
  931. {
  932. typedef dtl::tree
  933. <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
  934. this->merge_unique(static_cast<base2_t&>(source));
  935. }
  936. //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
  937. template<class C2>
  938. inline void merge(BOOST_RV_REF_BEG map<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
  939. { return this->merge(static_cast<map<Key, T, C2, Allocator, Options>&>(source)); }
  940. //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
  941. template<class C2>
  942. inline void merge(multimap<Key, T, C2, Allocator, Options>& source)
  943. {
  944. typedef dtl::tree
  945. <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
  946. this->base_t::merge_unique(static_cast<base2_t&>(source));
  947. }
  948. //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
  949. template<class C2>
  950. inline void merge(BOOST_RV_REF_BEG multimap<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
  951. { return this->merge(static_cast<multimap<Key, T, C2, Allocator, Options>&>(source)); }
  952. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  953. //! <b>Effects</b>: Swaps the contents of *this and x.
  954. //!
  955. //! <b>Throws</b>: Nothing.
  956. //!
  957. //! <b>Complexity</b>: Constant.
  958. void swap(map& x)
  959. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  960. && boost::container::dtl::is_nothrow_swappable<Compare>::value );
  961. //! <b>Effects</b>: erase(begin(),end()).
  962. //!
  963. //! <b>Postcondition</b>: size() == 0.
  964. //!
  965. //! <b>Complexity</b>: linear in size().
  966. void clear() BOOST_NOEXCEPT_OR_NOTHROW;
  967. //! <b>Effects</b>: Returns the comparison object out
  968. //! of which a was constructed.
  969. //!
  970. //! <b>Complexity</b>: Constant.
  971. key_compare key_comp() const;
  972. //! <b>Effects</b>: Returns an object of value_compare constructed out
  973. //! of the comparison object.
  974. //!
  975. //! <b>Complexity</b>: Constant.
  976. value_compare value_comp() const;
  977. //! <b>Returns</b>: An iterator pointing to an element with the key
  978. //! equivalent to x, or end() if such an element is not found.
  979. //!
  980. //! <b>Complexity</b>: Logarithmic.
  981. iterator find(const key_type& x);
  982. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  983. //! equivalent to x, or end() if such an element is not found.
  984. //!
  985. //! <b>Complexity</b>: Logarithmic.
  986. const_iterator find(const key_type& x) const;
  987. //! <b>Requires</b>: This overload is available only if
  988. //! key_compare::is_transparent exists.
  989. //!
  990. //! <b>Returns</b>: An iterator pointing to an element with the key
  991. //! equivalent to x, or end() if such an element is not found.
  992. //!
  993. //! <b>Complexity</b>: Logarithmic.
  994. template<typename K>
  995. iterator find(const K& x);
  996. //! <b>Requires</b>: This overload is available only if
  997. //! key_compare::is_transparent exists.
  998. //!
  999. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  1000. //! equivalent to x, or end() if such an element is not found.
  1001. //!
  1002. //! <b>Complexity</b>: Logarithmic.
  1003. template<typename K>
  1004. const_iterator find(const K& x) const;
  1005. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1006. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1007. //!
  1008. //! <b>Complexity</b>: log(size())+count(k)
  1009. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  1010. size_type count(const key_type& x) const
  1011. { return static_cast<size_type>(this->find(x) != this->cend()); }
  1012. //! <b>Requires</b>: This overload is available only if
  1013. //! key_compare::is_transparent exists.
  1014. //!
  1015. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1016. //!
  1017. //! <b>Complexity</b>: log(size())+count(k)
  1018. template<typename K>
  1019. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  1020. size_type count(const K& x) const
  1021. { return static_cast<size_type>(this->find(x) != this->cend()); }
  1022. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1023. //! <b>Returns</b>: Returns true if there is an element with key
  1024. //! equivalent to key in the container, otherwise false.
  1025. //!
  1026. //! <b>Complexity</b>: log(size()).
  1027. bool contains(const key_type& x) const;
  1028. //! <b>Requires</b>: This overload is available only if
  1029. //! key_compare::is_transparent exists.
  1030. //!
  1031. //! <b>Returns</b>: Returns true if there is an element with key
  1032. //! equivalent to key in the container, otherwise false.
  1033. //!
  1034. //! <b>Complexity</b>: log(size()).
  1035. template<typename K>
  1036. bool contains(const K& x) const;
  1037. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1038. //! than x, or end() if such an element is not found.
  1039. //!
  1040. //! <b>Complexity</b>: Logarithmic
  1041. iterator lower_bound(const key_type& x);
  1042. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1043. //! less than x, or end() if such an element is not found.
  1044. //!
  1045. //! <b>Complexity</b>: Logarithmic
  1046. const_iterator lower_bound(const key_type& x) const;
  1047. //! <b>Requires</b>: This overload is available only if
  1048. //! key_compare::is_transparent exists.
  1049. //!
  1050. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1051. //! than x, or end() if such an element is not found.
  1052. //!
  1053. //! <b>Complexity</b>: Logarithmic
  1054. template<typename K>
  1055. iterator lower_bound(const K& x);
  1056. //! <b>Requires</b>: This overload is available only if
  1057. //! key_compare::is_transparent exists.
  1058. //!
  1059. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1060. //! less than x, or end() if such an element is not found.
  1061. //!
  1062. //! <b>Complexity</b>: Logarithmic
  1063. template<typename K>
  1064. const_iterator lower_bound(const K& x) const;
  1065. //! <b>Returns</b>: An iterator pointing to the first element with key greater
  1066. //! than x, or end() if such an element is not found.
  1067. //!
  1068. //! <b>Complexity</b>: Logarithmic
  1069. iterator upper_bound(const key_type& x);
  1070. //! <b>Returns</b>: A const iterator pointing to the first element with key
  1071. //! greater than x, or end() if such an element is not found.
  1072. //!
  1073. //! <b>Complexity</b>: Logarithmic
  1074. const_iterator upper_bound(const key_type& x) const;
  1075. //! <b>Requires</b>: This overload is available only if
  1076. //! key_compare::is_transparent exists.
  1077. //!
  1078. //! <b>Returns</b>: An iterator pointing to the first element with key greater
  1079. //! than x, or end() if such an element is not found.
  1080. //!
  1081. //! <b>Complexity</b>: Logarithmic
  1082. template<typename K>
  1083. iterator upper_bound(const K& x);
  1084. //! <b>Requires</b>: This overload is available only if
  1085. //! key_compare::is_transparent exists.
  1086. //!
  1087. //! <b>Returns</b>: A const iterator pointing to the first element with key
  1088. //! greater than x, or end() if such an element is not found.
  1089. //!
  1090. //! <b>Complexity</b>: Logarithmic
  1091. template<typename K>
  1092. const_iterator upper_bound(const K& x) const;
  1093. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1094. //!
  1095. //! <b>Complexity</b>: Logarithmic
  1096. std::pair<iterator,iterator> equal_range(const key_type& x);
  1097. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1098. //!
  1099. //! <b>Complexity</b>: Logarithmic
  1100. std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
  1101. //! <b>Requires</b>: This overload is available only if
  1102. //! key_compare::is_transparent exists.
  1103. //!
  1104. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1105. //!
  1106. //! <b>Complexity</b>: Logarithmic
  1107. template<typename K>
  1108. std::pair<iterator,iterator> equal_range(const K& x);
  1109. //! <b>Requires</b>: This overload is available only if
  1110. //! key_compare::is_transparent exists.
  1111. //!
  1112. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1113. //!
  1114. //! <b>Complexity</b>: Logarithmic
  1115. template<typename K>
  1116. std::pair<const_iterator,const_iterator> equal_range(const K& x) const;
  1117. //! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees.
  1118. //!
  1119. //! <b>Complexity</b>: Linear
  1120. void rebalance();
  1121. //! <b>Effects</b>: Returns true if x and y are equal
  1122. //!
  1123. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1124. friend bool operator==(const map& x, const map& y);
  1125. //! <b>Effects</b>: Returns true if x and y are unequal
  1126. //!
  1127. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1128. friend bool operator!=(const map& x, const map& y);
  1129. //! <b>Effects</b>: Returns true if x is less than y
  1130. //!
  1131. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1132. friend bool operator<(const map& x, const map& y);
  1133. //! <b>Effects</b>: Returns true if x is greater than y
  1134. //!
  1135. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1136. friend bool operator>(const map& x, const map& y);
  1137. //! <b>Effects</b>: Returns true if x is equal or less than y
  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 is equal or greater than y
  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>: x.swap(y)
  1146. //!
  1147. //! <b>Complexity</b>: Constant.
  1148. friend void swap(map& x, map& y)
  1149. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  1150. && boost::container::dtl::is_nothrow_swappable<Compare>::value );
  1151. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1152. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1153. private:
  1154. template<class KeyConvertible>
  1155. inline mapped_type& priv_subscript(BOOST_FWD_REF(KeyConvertible) k)
  1156. {
  1157. return this->try_emplace(boost::forward<KeyConvertible>(k)).first->second;
  1158. }
  1159. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1160. };
  1161. #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
  1162. template <typename InputIterator>
  1163. map(InputIterator, InputIterator) ->
  1164. map< it_based_non_const_first_type_t<InputIterator>
  1165. , it_based_second_type_t<InputIterator>>;
  1166. template < typename InputIterator, typename AllocatorOrCompare>
  1167. map(InputIterator, InputIterator, AllocatorOrCompare const&) ->
  1168. map< it_based_non_const_first_type_t<InputIterator>
  1169. , it_based_second_type_t<InputIterator>
  1170. , typename dtl::if_c< // Compare
  1171. dtl::is_allocator<AllocatorOrCompare>::value
  1172. , std::less<it_based_non_const_first_type_t<InputIterator>>
  1173. , AllocatorOrCompare
  1174. >::type
  1175. , typename dtl::if_c< // Allocator
  1176. dtl::is_allocator<AllocatorOrCompare>::value
  1177. , AllocatorOrCompare
  1178. , new_allocator<std::pair<it_based_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
  1179. >::type
  1180. >;
  1181. template < typename InputIterator, typename Compare, typename Allocator
  1182. , typename = dtl::require_nonallocator_t<Compare>
  1183. , typename = dtl::require_allocator_t<Allocator>>
  1184. map(InputIterator, InputIterator, Compare const&, Allocator const&) ->
  1185. map< it_based_non_const_first_type_t<InputIterator>
  1186. , it_based_second_type_t<InputIterator>
  1187. , Compare
  1188. , Allocator>;
  1189. template <typename InputIterator>
  1190. map(ordered_unique_range_t, InputIterator, InputIterator) ->
  1191. map< it_based_non_const_first_type_t<InputIterator>
  1192. , it_based_second_type_t<InputIterator>>;
  1193. template < typename InputIterator, typename AllocatorOrCompare>
  1194. map(ordered_unique_range_t, InputIterator, InputIterator, AllocatorOrCompare const&) ->
  1195. map< it_based_non_const_first_type_t<InputIterator>
  1196. , it_based_second_type_t<InputIterator>
  1197. , typename dtl::if_c< // Compare
  1198. dtl::is_allocator<AllocatorOrCompare>::value
  1199. , std::less<it_based_non_const_first_type_t<InputIterator>>
  1200. , AllocatorOrCompare
  1201. >::type
  1202. , typename dtl::if_c< // Allocator
  1203. dtl::is_allocator<AllocatorOrCompare>::value
  1204. , AllocatorOrCompare
  1205. , new_allocator<std::pair<it_based_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
  1206. >::type
  1207. >;
  1208. template < typename InputIterator, typename Compare, typename Allocator
  1209. , typename = dtl::require_nonallocator_t<Compare>
  1210. , typename = dtl::require_allocator_t<Allocator>>
  1211. map(ordered_unique_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
  1212. map< it_based_non_const_first_type_t<InputIterator>
  1213. , it_based_second_type_t<InputIterator>
  1214. , Compare
  1215. , Allocator>;
  1216. #endif
  1217. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1218. } //namespace container {
  1219. //!has_trivial_destructor_after_move<> == true_type
  1220. //!specialization for optimizations
  1221. template <class Key, class T, class Compare, class Allocator, class Options>
  1222. struct has_trivial_destructor_after_move<boost::container::map<Key, T, Compare, Allocator, Options> >
  1223. {
  1224. typedef ::boost::container::dtl::tree<std::pair<const Key, T>, int, Compare, Allocator, Options> tree;
  1225. static const bool value = ::boost::has_trivial_destructor_after_move<tree>::value;
  1226. };
  1227. namespace container {
  1228. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1229. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  1230. //! A multimap is a kind of associative container that supports equivalent keys
  1231. //! (possibly containing multiple copies of the same key value) and provides for
  1232. //! fast retrieval of values of another type T based on the keys. The multimap class
  1233. //! supports bidirectional iterators.
  1234. //!
  1235. //! A multimap satisfies all of the requirements of a container and of a reversible
  1236. //! container and of an associative container. The <code>value_type</code> stored
  1237. //! by this container is the value_type is std::pair<const Key, T>.
  1238. //!
  1239. //! \tparam Key is the key_type of the map
  1240. //! \tparam Value is the <code>mapped_type</code>
  1241. //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
  1242. //! \tparam Allocator is the allocator to allocate the <code>value_type</code>s
  1243. //! (e.g. <i>allocator< std::pair<const Key, T> > </i>).
  1244. //! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options.
  1245. template < class Key, class T, class Compare = std::less<Key>
  1246. , class Allocator = new_allocator< std::pair< const Key, T> >, class Options = tree_assoc_defaults>
  1247. #else
  1248. template <class Key, class T, class Compare, class Allocator, class Options>
  1249. #endif
  1250. class multimap
  1251. ///@cond
  1252. : public dtl::tree
  1253. < std::pair<const Key, T>
  1254. , int
  1255. , Compare, Allocator, Options>
  1256. ///@endcond
  1257. {
  1258. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1259. private:
  1260. BOOST_COPYABLE_AND_MOVABLE(multimap)
  1261. typedef int select_1st_t;
  1262. typedef std::pair<const Key, T> value_type_impl;
  1263. typedef dtl::tree
  1264. <value_type_impl, select_1st_t, Compare, Allocator, Options> base_t;
  1265. typedef dtl::pair <Key, T> movable_value_type_impl;
  1266. typedef typename base_t::value_compare value_compare_impl;
  1267. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1268. public:
  1269. //////////////////////////////////////////////
  1270. //
  1271. // types
  1272. //
  1273. //////////////////////////////////////////////
  1274. typedef Key key_type;
  1275. typedef T mapped_type;
  1276. typedef typename base_t::allocator_type allocator_type;
  1277. typedef ::boost::container::allocator_traits<allocator_type> allocator_traits_type;
  1278. typedef typename boost::container::allocator_traits<allocator_type>::value_type value_type;
  1279. typedef typename boost::container::allocator_traits<allocator_type>::pointer pointer;
  1280. typedef typename boost::container::allocator_traits<allocator_type>::const_pointer const_pointer;
  1281. typedef typename boost::container::allocator_traits<allocator_type>::reference reference;
  1282. typedef typename boost::container::allocator_traits<allocator_type>::const_reference const_reference;
  1283. typedef typename boost::container::allocator_traits<allocator_type>::size_type size_type;
  1284. typedef typename boost::container::allocator_traits<allocator_type>::difference_type difference_type;
  1285. typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
  1286. typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
  1287. typedef Compare key_compare;
  1288. typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
  1289. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
  1290. typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
  1291. typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
  1292. //typedef std::pair<key_type, mapped_type> nonconst_value_type;
  1293. typedef BOOST_CONTAINER_IMPDEF(movable_value_type_impl) movable_value_type;
  1294. typedef BOOST_CONTAINER_IMPDEF(node_handle<
  1295. typename base_t::stored_allocator_type
  1296. BOOST_MOVE_I pair_key_mapped_of_value
  1297. <key_type BOOST_MOVE_I mapped_type> >) node_type;
  1298. //allocator_type::value_type type must be std::pair<CONST Key, T>
  1299. BOOST_CONTAINER_STATIC_ASSERT((dtl::is_same<typename allocator_type::value_type, std::pair<const Key, T> >::value));
  1300. //////////////////////////////////////////////
  1301. //
  1302. // construct/copy/destroy
  1303. //
  1304. //////////////////////////////////////////////
  1305. //! <b>Effects</b>: Default constructs an empty multimap.
  1306. //!
  1307. //! <b>Complexity</b>: Constant.
  1308. inline multimap()
  1309. BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<allocator_type>::value &&
  1310. dtl::is_nothrow_default_constructible<Compare>::value)
  1311. : base_t()
  1312. {}
  1313. //! <b>Effects</b>: Constructs an empty multimap using the specified allocator
  1314. //! object and allocator.
  1315. //!
  1316. //! <b>Complexity</b>: Constant.
  1317. inline explicit multimap(const allocator_type& a)
  1318. : base_t(a)
  1319. {}
  1320. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison.
  1321. //!
  1322. //! <b>Complexity</b>: Constant.
  1323. inline explicit multimap(const Compare& comp)
  1324. : base_t(comp)
  1325. {}
  1326. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison and allocator.
  1327. //!
  1328. //! <b>Complexity</b>: Constant.
  1329. inline multimap(const Compare& comp, const allocator_type& a)
  1330. : base_t(comp, a)
  1331. {}
  1332. //! <b>Effects</b>: Constructs an empty multimap and
  1333. //! inserts elements from the range [first ,last ).
  1334. //!
  1335. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1336. //! the predicate and otherwise N logN, where N is last - first.
  1337. template <class InputIterator>
  1338. inline multimap(InputIterator first, InputIterator last)
  1339. : base_t(false, first, last)
  1340. {}
  1341. //! <b>Effects</b>: Constructs an empty multimap using the specified
  1342. //! allocator, and inserts elements from the range [first ,last ).
  1343. //!
  1344. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1345. //! the predicate and otherwise N logN, where N is last - first.
  1346. template <class InputIterator>
  1347. inline multimap(InputIterator first, InputIterator last, const allocator_type& a)
  1348. : base_t(false, first, last, Compare(), a)
  1349. {}
  1350. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  1351. //! inserts elements from the range [first ,last ).
  1352. //!
  1353. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1354. //! the predicate and otherwise N logN, where N is last - first.
  1355. template <class InputIterator>
  1356. inline multimap(InputIterator first, InputIterator last, const Compare& comp)
  1357. : base_t(false, first, last, comp)
  1358. {}
  1359. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object
  1360. //! and allocator, and inserts elements from the range [first ,last ).
  1361. //!
  1362. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1363. //! the predicate and otherwise N logN, where N is last - first.
  1364. template <class InputIterator>
  1365. inline multimap(InputIterator first, InputIterator last,
  1366. const Compare& comp, const allocator_type& a)
  1367. : base_t(false, first, last, comp, a)
  1368. {}
  1369. //! <b>Effects</b>: Constructs an empty multimap and
  1370. //! inserts elements from the ordered range [first ,last). This function
  1371. //! is more efficient than the normal range creation for ordered ranges.
  1372. //!
  1373. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1374. //!
  1375. //! <b>Complexity</b>: Linear in N.
  1376. //!
  1377. //! <b>Note</b>: Non-standard extension.
  1378. template <class InputIterator>
  1379. inline multimap(ordered_range_t, InputIterator first, InputIterator last)
  1380. : base_t(ordered_range, first, last)
  1381. {}
  1382. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  1383. //! inserts elements from the ordered range [first ,last). This function
  1384. //! is more efficient than the normal range creation for ordered ranges.
  1385. //!
  1386. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1387. //!
  1388. //! <b>Complexity</b>: Linear in N.
  1389. //!
  1390. //! <b>Note</b>: Non-standard extension.
  1391. template <class InputIterator>
  1392. inline multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp)
  1393. : base_t(ordered_range, first, last, comp)
  1394. {}
  1395. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  1396. //! allocator, and inserts elements from the ordered range [first ,last). This function
  1397. //! is more efficient than the normal range creation for ordered ranges.
  1398. //!
  1399. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1400. //!
  1401. //! <b>Complexity</b>: Linear in N.
  1402. //!
  1403. //! <b>Note</b>: Non-standard extension.
  1404. template <class InputIterator>
  1405. inline multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp,
  1406. const allocator_type& a)
  1407. : base_t(ordered_range, first, last, comp, a)
  1408. {}
  1409. //! <b>Effects</b>: Constructs an empty multimap using the specified allocator and
  1410. //! inserts elements from the ordered range [first ,last). This function
  1411. //! is more efficient than the normal range creation for ordered ranges.
  1412. //!
  1413. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1414. //!
  1415. //! <b>Complexity</b>: Linear in N.
  1416. //!
  1417. //! <b>Note</b>: Non-standard extension.
  1418. template <class InputIterator>
  1419. inline multimap(ordered_range_t, InputIterator first, InputIterator last, const allocator_type& a)
  1420. : base_t(ordered_range, first, last, Compare(), a)
  1421. {}
  1422. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1423. //! <b>Effects</b>: Constructs an empty multimap and
  1424. //! and inserts elements from the range [il.begin(), il.end()).
  1425. //!
  1426. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1427. //! the predicate and otherwise N logN, where N is il.first() - il.end().
  1428. inline multimap(std::initializer_list<value_type> il)
  1429. : base_t(false, il.begin(), il.end())
  1430. {}
  1431. //! <b>Effects</b>: Constructs an empty multimap using the specified
  1432. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  1433. //!
  1434. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1435. //! the predicate and otherwise N logN, where N is il.first() - il.end().
  1436. inline multimap(std::initializer_list<value_type> il, const allocator_type& a)
  1437. : base_t(false, il.begin(), il.end(), Compare(), a)
  1438. {}
  1439. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  1440. //! 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, const Compare& comp)
  1445. : base_t(false, il.begin(), il.end(), comp)
  1446. {}
  1447. //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
  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 Compare& comp, const allocator_type& a)
  1453. : base_t(false, il.begin(), il.end(), comp, a)
  1454. {}
  1455. //! <b>Effects</b>: Constructs an empty map and
  1456. //! inserts elements from the ordered range [il.begin(), il.end()). This function
  1457. //! is more efficient than the normal range creation for ordered ranges.
  1458. //!
  1459. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1460. //!
  1461. //! <b>Complexity</b>: Linear in N.
  1462. //!
  1463. //! <b>Note</b>: Non-standard extension.
  1464. inline multimap(ordered_range_t, std::initializer_list<value_type> il)
  1465. : base_t(ordered_range, il.begin(), il.end())
  1466. {}
  1467. //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
  1468. //! inserts elements from the ordered range [il.begin(), il.end()). This function
  1469. //! is more efficient than the normal range creation for ordered ranges.
  1470. //!
  1471. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1472. //!
  1473. //! <b>Complexity</b>: Linear in N.
  1474. //!
  1475. //! <b>Note</b>: Non-standard extension.
  1476. inline multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp)
  1477. : base_t(ordered_range, il.begin(), il.end(), comp)
  1478. {}
  1479. //! <b>Effects</b>: Constructs an empty map and
  1480. //! inserts elements from the ordered range [il.begin(), il.end()). This function
  1481. //! is more efficient than the normal range creation for ordered ranges.
  1482. //!
  1483. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1484. //!
  1485. //! <b>Complexity</b>: Linear in N.
  1486. //!
  1487. //! <b>Note</b>: Non-standard extension.
  1488. inline multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
  1489. : base_t(ordered_range, il.begin(), il.end(), comp, a)
  1490. {}
  1491. #endif
  1492. //! <b>Effects</b>: Copy constructs a multimap.
  1493. //!
  1494. //! <b>Complexity</b>: Linear in x.size().
  1495. inline multimap(const multimap& x)
  1496. : base_t(static_cast<const base_t&>(x))
  1497. {}
  1498. //! <b>Effects</b>: Move constructs a multimap. Constructs *this using x's resources.
  1499. //!
  1500. //! <b>Complexity</b>: Constant.
  1501. //!
  1502. //! <b>Postcondition</b>: x is emptied.
  1503. inline multimap(BOOST_RV_REF(multimap) x)
  1504. BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
  1505. : base_t(BOOST_MOVE_BASE(base_t, x))
  1506. {}
  1507. //! <b>Effects</b>: Copy constructs a multimap.
  1508. //!
  1509. //! <b>Complexity</b>: Linear in x.size().
  1510. inline multimap(const multimap& x, const allocator_type &a)
  1511. : base_t(static_cast<const base_t&>(x), a)
  1512. {}
  1513. //! <b>Effects</b>: Move constructs a multimap using the specified allocator.
  1514. //! Constructs *this using x's resources.
  1515. //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
  1516. //!
  1517. //! <b>Postcondition</b>: x is emptied.
  1518. inline multimap(BOOST_RV_REF(multimap) x, const allocator_type &a)
  1519. : base_t(BOOST_MOVE_BASE(base_t, x), a)
  1520. {}
  1521. //! <b>Effects</b>: Makes *this a copy of x.
  1522. //!
  1523. //! <b>Complexity</b>: Linear in x.size().
  1524. inline multimap& operator=(BOOST_COPY_ASSIGN_REF(multimap) x)
  1525. { return static_cast<multimap&>(this->base_t::operator=(static_cast<const base_t&>(x))); }
  1526. //! <b>Effects</b>: this->swap(x.get()).
  1527. //!
  1528. //! <b>Complexity</b>: Constant.
  1529. inline multimap& operator=(BOOST_RV_REF(multimap) x)
  1530. BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
  1531. allocator_traits_type::is_always_equal::value) &&
  1532. boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
  1533. { return static_cast<multimap&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
  1534. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1535. //! <b>Effects</b>: Assign content of il to *this.
  1536. //!
  1537. inline multimap& operator=(std::initializer_list<value_type> il)
  1538. {
  1539. this->clear();
  1540. insert(il.begin(), il.end());
  1541. return *this;
  1542. }
  1543. #endif
  1544. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1545. //! @copydoc ::boost::container::set::get_allocator()
  1546. allocator_type get_allocator() const;
  1547. //! @copydoc ::boost::container::set::get_stored_allocator()
  1548. stored_allocator_type &get_stored_allocator();
  1549. //! @copydoc ::boost::container::set::get_stored_allocator() const
  1550. const stored_allocator_type &get_stored_allocator() const;
  1551. //! @copydoc ::boost::container::set::begin()
  1552. iterator begin();
  1553. //! @copydoc ::boost::container::set::begin() const
  1554. const_iterator begin() const;
  1555. //! @copydoc ::boost::container::set::cbegin() const
  1556. const_iterator cbegin() const;
  1557. //! @copydoc ::boost::container::set::end()
  1558. iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
  1559. //! @copydoc ::boost::container::set::end() const
  1560. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
  1561. //! @copydoc ::boost::container::set::cend() const
  1562. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
  1563. //! @copydoc ::boost::container::set::rbegin()
  1564. reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
  1565. //! @copydoc ::boost::container::set::rbegin() const
  1566. const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  1567. //! @copydoc ::boost::container::set::crbegin() const
  1568. const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  1569. //! @copydoc ::boost::container::set::rend()
  1570. reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
  1571. //! @copydoc ::boost::container::set::rend() const
  1572. const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
  1573. //! @copydoc ::boost::container::set::crend() const
  1574. const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
  1575. //! @copydoc ::boost::container::set::empty() const
  1576. bool empty() const;
  1577. //! @copydoc ::boost::container::set::size() const
  1578. size_type size() const;
  1579. //! @copydoc ::boost::container::set::max_size() const
  1580. size_type max_size() const;
  1581. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1582. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1583. //! <b>Effects</b>: Inserts an object of type T constructed with
  1584. //! std::forward<Args>(args)... in the container.
  1585. //! p is a hint pointing to where the insert should start to search.
  1586. //!
  1587. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1588. //! to the key of x.
  1589. //!
  1590. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1591. //! is inserted right before p.
  1592. template <class... Args>
  1593. inline iterator emplace(BOOST_FWD_REF(Args)... args)
  1594. { return this->base_t::emplace_equal(boost::forward<Args>(args)...); }
  1595. //! <b>Effects</b>: Inserts an object of type T constructed with
  1596. //! std::forward<Args>(args)... in the container.
  1597. //! p is a hint pointing to where the insert should start to search.
  1598. //!
  1599. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1600. //! to the key of x.
  1601. //!
  1602. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1603. //! is inserted right before p.
  1604. template <class... Args>
  1605. inline iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
  1606. { return this->base_t::emplace_hint_equal(p, boost::forward<Args>(args)...); }
  1607. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  1608. #define BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE(N) \
  1609. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  1610. inline iterator emplace(BOOST_MOVE_UREF##N)\
  1611. { return this->base_t::emplace_equal(BOOST_MOVE_FWD##N); }\
  1612. \
  1613. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  1614. inline iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  1615. { return this->base_t::emplace_hint_equal(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
  1616. //
  1617. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE)
  1618. #undef BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE
  1619. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  1620. //! <b>Effects</b>: Inserts x and returns the iterator pointing to the
  1621. //! newly inserted element.
  1622. //!
  1623. //! <b>Complexity</b>: Logarithmic.
  1624. inline iterator insert(const value_type& x)
  1625. { return this->base_t::insert_equal_convertible(x); }
  1626. //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
  1627. //! the iterator pointing to the newly inserted element.
  1628. //!
  1629. //! <b>Complexity</b>: Logarithmic.
  1630. inline iterator insert(BOOST_RV_REF(value_type) x)
  1631. { return this->base_t::insert_equal_convertible(boost::move(x)); }
  1632. //! <b>Effects</b>: Inserts a new value constructed from x and returns
  1633. //! the iterator pointing to the newly inserted element.
  1634. //!
  1635. //! <b>Complexity</b>: Logarithmic.
  1636. template<class Pair>
  1637. inline BOOST_CONTAINER_DOC1ST
  1638. ( iterator
  1639. , typename dtl::enable_if_c<
  1640. dtl::is_convertible<Pair BOOST_MOVE_I value_type>::value ||
  1641. dtl::is_convertible<Pair BOOST_MOVE_I movable_value_type>::value
  1642. BOOST_MOVE_I iterator >::type)
  1643. insert(BOOST_FWD_REF(Pair) x)
  1644. { return this->base_t::emplace_equal(boost::forward<Pair>(x)); }
  1645. //! <b>Effects</b>: Inserts a copy of x in the container.
  1646. //! p is a hint pointing to where the insert should start to search.
  1647. //!
  1648. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1649. //! to the key of x.
  1650. //!
  1651. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1652. //! is inserted right before p.
  1653. inline iterator insert(const_iterator p, const value_type& x)
  1654. { return this->base_t::insert_equal_hint_convertible(p, x); }
  1655. //! <b>Effects</b>: Inserts a new value move constructed from x in the container.
  1656. //! p is a hint pointing to where the insert should start to search.
  1657. //!
  1658. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1659. //! to the key of x.
  1660. //!
  1661. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1662. //! is inserted right before p.
  1663. inline iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
  1664. { return this->base_t::insert_equal_hint_convertible(p, boost::move(x)); }
  1665. //! <b>Effects</b>: Inserts a new value constructed from x in the container.
  1666. //! p is a hint pointing to where the insert should start to search.
  1667. //!
  1668. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1669. //! to the key of x.
  1670. //!
  1671. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
  1672. //! is inserted right before p.
  1673. template<class Pair>
  1674. inline BOOST_CONTAINER_DOC1ST
  1675. ( iterator
  1676. , typename dtl::enable_if_c<
  1677. dtl::is_convertible<Pair BOOST_MOVE_I value_type>::value ||
  1678. dtl::is_convertible<Pair BOOST_MOVE_I movable_value_type>::value
  1679. BOOST_MOVE_I iterator>::type)
  1680. insert(const_iterator p, BOOST_FWD_REF(Pair) x)
  1681. { return this->base_t::emplace_hint_equal(p, boost::forward<Pair>(x)); }
  1682. //! <b>Requires</b>: first, last are not iterators into *this.
  1683. //!
  1684. //! <b>Effects</b>: inserts each element from the range [first,last) .
  1685. //!
  1686. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  1687. template <class InputIterator>
  1688. inline void insert(InputIterator first, InputIterator last)
  1689. { this->base_t::insert_equal_range(first, last); }
  1690. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1691. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end().
  1692. //!
  1693. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
  1694. inline void insert(std::initializer_list<value_type> il)
  1695. { this->base_t::insert_equal_range(il.begin(), il.end()); }
  1696. #endif
  1697. //! <b>Requires</b>: nh is empty or this->get_allocator() == nh.get_allocator().
  1698. //!
  1699. //! <b>Effects/Returns</b>: If nh is empty, has no effect and returns end(). Otherwise, inserts
  1700. //! the element owned by nh and returns an iterator pointing to the newly inserted element.
  1701. //! If a range containing elements with keys equivalent to nh.key() exists,
  1702. //! the element is inserted at the end of that range. nh is always emptied.
  1703. //!
  1704. //! <b>Complexity</b>: Logarithmic
  1705. iterator insert(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  1706. {
  1707. typename base_t::node_type n(boost::move(nh));
  1708. return this->base_t::insert_equal_node(boost::move(n));
  1709. }
  1710. //! <b>Effects</b>: Same as `insert(node_type && nh)` but the element is inserted as close as possible
  1711. //! to the position just prior to "hint".
  1712. //!
  1713. //! <b>Complexity</b>: logarithmic in general, but amortized constant if the element is inserted
  1714. //! right before "hint".
  1715. iterator insert(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  1716. {
  1717. typename base_t::node_type n(boost::move(nh));
  1718. return this->base_t::insert_equal_node(hint, boost::move(n));
  1719. }
  1720. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1721. //! @copydoc ::boost::container::set::erase(const_iterator)
  1722. iterator erase(const_iterator p);
  1723. //! @copydoc ::boost::container::set::erase(const key_type&)
  1724. size_type erase(const key_type& x);
  1725. //! @copydoc ::boost::container::set::erase(const_iterator,const_iterator)
  1726. iterator erase(const_iterator first, const_iterator last);
  1727. #endif
  1728. //! @copydoc ::boost::container::map::extract(const key_type&)
  1729. node_type extract(const key_type& k)
  1730. {
  1731. typename base_t::node_type base_nh(this->base_t::extract(k));
  1732. return node_type(boost::move(base_nh));
  1733. }
  1734. //! @copydoc ::boost::container::map::extract(const_iterator)
  1735. node_type extract(const_iterator position)
  1736. {
  1737. typename base_t::node_type base_nh(this->base_t::extract(position));
  1738. return node_type (boost::move(base_nh));
  1739. }
  1740. //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
  1741. //!
  1742. //! <b>Effects</b>: Extracts each element in source and insert it into a using
  1743. //! the comparison object of *this.
  1744. //!
  1745. //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
  1746. //! to those same elements but as members of *this. Iterators referring to the transferred
  1747. //! elements will continue to refer to their elements, but they now behave as iterators into *this,
  1748. //! not into source.
  1749. //!
  1750. //! <b>Throws</b>: Nothing unless the comparison object throws.
  1751. //!
  1752. //! <b>Complexity</b>: N log(size() + N) (N has the value source.size())
  1753. template<class C2>
  1754. inline void merge(multimap<Key, T, C2, Allocator, Options>& source)
  1755. {
  1756. typedef dtl::tree
  1757. <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
  1758. this->base_t::merge_equal(static_cast<base2_t&>(source));
  1759. }
  1760. //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
  1761. template<class C2>
  1762. inline void merge(BOOST_RV_REF_BEG multimap<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
  1763. { return this->merge(static_cast<multimap<Key, T, C2, Allocator, Options>&>(source)); }
  1764. //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
  1765. template<class C2>
  1766. inline void merge(map<Key, T, C2, Allocator, Options>& source)
  1767. {
  1768. typedef dtl::tree
  1769. <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
  1770. this->base_t::merge_equal(static_cast<base2_t&>(source));
  1771. }
  1772. //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
  1773. template<class C2>
  1774. inline void merge(BOOST_RV_REF_BEG map<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
  1775. { return this->merge(static_cast<map<Key, T, C2, Allocator, Options>&>(source)); }
  1776. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1777. //! @copydoc ::boost::container::set::swap
  1778. void swap(multiset& x)
  1779. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  1780. && boost::container::dtl::is_nothrow_swappable<Compare>::value );
  1781. //! @copydoc ::boost::container::set::clear
  1782. void clear() BOOST_NOEXCEPT_OR_NOTHROW;
  1783. //! @copydoc ::boost::container::set::key_comp
  1784. key_compare key_comp() const;
  1785. //! @copydoc ::boost::container::set::value_comp
  1786. value_compare value_comp() const;
  1787. //! <b>Returns</b>: An iterator pointing to an element with the key
  1788. //! equivalent to x, or end() if such an element is not found.
  1789. //!
  1790. //! <b>Complexity</b>: Logarithmic.
  1791. iterator find(const key_type& x);
  1792. //! <b>Returns</b>: A const iterator pointing to an element with the key
  1793. //! equivalent to x, or end() if such an element is not found.
  1794. //!
  1795. //! <b>Complexity</b>: Logarithmic.
  1796. const_iterator find(const key_type& x) const;
  1797. //! <b>Requires</b>: This overload is available only if
  1798. //! key_compare::is_transparent exists.
  1799. //!
  1800. //! <b>Returns</b>: An iterator pointing to an element with the key
  1801. //! equivalent to x, or end() if such an element is not found.
  1802. //!
  1803. //! <b>Complexity</b>: Logarithmic.
  1804. template<typename K>
  1805. iterator find(const K& x);
  1806. //! <b>Requires</b>: This overload is available only if
  1807. //! key_compare::is_transparent exists.
  1808. //!
  1809. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  1810. //! equivalent to x, or end() if such an element is not found.
  1811. //!
  1812. //! <b>Complexity</b>: Logarithmic.
  1813. template<typename K>
  1814. const_iterator find(const K& x) const;
  1815. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1816. //!
  1817. //! <b>Complexity</b>: log(size())+count(k)
  1818. size_type count(const key_type& x) const;
  1819. //! <b>Requires</b>: This overload is available only if
  1820. //! key_compare::is_transparent exists.
  1821. //!
  1822. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1823. //!
  1824. //! <b>Complexity</b>: log(size())+count(k)
  1825. template<typename K>
  1826. size_type count(const K& x) const;
  1827. //! <b>Returns</b>: Returns true if there is an element with key
  1828. //! equivalent to key in the container, otherwise false.
  1829. //!
  1830. //! <b>Complexity</b>: log(size()).
  1831. bool contains(const key_type& x) const;
  1832. //! <b>Requires</b>: This overload is available only if
  1833. //! key_compare::is_transparent exists.
  1834. //!
  1835. //! <b>Returns</b>: Returns true if there is an element with key
  1836. //! equivalent to key in the container, otherwise false.
  1837. //!
  1838. //! <b>Complexity</b>: log(size()).
  1839. template<typename K>
  1840. bool contains(const K& x) const;
  1841. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1842. //! than x, or end() if such an element is not found.
  1843. //!
  1844. //! <b>Complexity</b>: Logarithmic
  1845. iterator lower_bound(const key_type& x);
  1846. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1847. //! less than x, or end() if such an element is not found.
  1848. //!
  1849. //! <b>Complexity</b>: Logarithmic
  1850. const_iterator lower_bound(const key_type& x) const;
  1851. //! <b>Requires</b>: This overload is available only if
  1852. //! key_compare::is_transparent exists.
  1853. //!
  1854. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1855. //! than x, or end() if such an element is not found.
  1856. //!
  1857. //! <b>Complexity</b>: Logarithmic
  1858. template<typename K>
  1859. iterator lower_bound(const K& x);
  1860. //! <b>Requires</b>: This overload is available only if
  1861. //! key_compare::is_transparent exists.
  1862. //!
  1863. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1864. //! less than x, or end() if such an element is not found.
  1865. //!
  1866. //! <b>Complexity</b>: Logarithmic
  1867. template<typename K>
  1868. const_iterator lower_bound(const K& x) const;
  1869. //! <b>Returns</b>: An iterator pointing to the first element with key greater
  1870. //! than x, or end() if such an element is not found.
  1871. //!
  1872. //! <b>Complexity</b>: Logarithmic
  1873. iterator upper_bound(const key_type& x);
  1874. //! <b>Returns</b>: A const iterator pointing to the first element with key
  1875. //! greater than x, or end() if such an element is not found.
  1876. //!
  1877. //! <b>Complexity</b>: Logarithmic
  1878. const_iterator upper_bound(const key_type& x) const;
  1879. //! <b>Requires</b>: This overload is available only if
  1880. //! key_compare::is_transparent exists.
  1881. //!
  1882. //! <b>Returns</b>: An iterator pointing to the first element with key greater
  1883. //! than x, or end() if such an element is not found.
  1884. //!
  1885. //! <b>Complexity</b>: Logarithmic
  1886. template<typename K>
  1887. iterator upper_bound(const K& x);
  1888. //! <b>Requires</b>: This overload is available only if
  1889. //! key_compare::is_transparent exists.
  1890. //!
  1891. //! <b>Returns</b>: A const iterator pointing to the first element with key
  1892. //! greater than x, or end() if such an element is not found.
  1893. //!
  1894. //! <b>Complexity</b>: Logarithmic
  1895. template<typename K>
  1896. const_iterator upper_bound(const K& x) const;
  1897. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1898. //!
  1899. //! <b>Complexity</b>: Logarithmic
  1900. std::pair<iterator,iterator> equal_range(const key_type& x);
  1901. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1902. //!
  1903. //! <b>Complexity</b>: Logarithmic
  1904. std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
  1905. //! <b>Requires</b>: This overload is available only if
  1906. //! key_compare::is_transparent exists.
  1907. //!
  1908. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1909. //!
  1910. //! <b>Complexity</b>: Logarithmic
  1911. template<typename K>
  1912. std::pair<iterator,iterator> equal_range(const K& x);
  1913. //! <b>Requires</b>: This overload is available only if
  1914. //! key_compare::is_transparent exists.
  1915. //!
  1916. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1917. //!
  1918. //! <b>Complexity</b>: Logarithmic
  1919. template<typename K>
  1920. std::pair<const_iterator,const_iterator> equal_range(const K& x) const;
  1921. //! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees.
  1922. //!
  1923. //! <b>Complexity</b>: Linear
  1924. void rebalance();
  1925. //! <b>Effects</b>: Returns true if x and y are equal
  1926. //!
  1927. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1928. friend bool operator==(const multimap& x, const multimap& y);
  1929. //! <b>Effects</b>: Returns true if x and y are unequal
  1930. //!
  1931. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1932. friend bool operator!=(const multimap& x, const multimap& y);
  1933. //! <b>Effects</b>: Returns true if x is less than y
  1934. //!
  1935. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1936. friend bool operator<(const multimap& x, const multimap& y);
  1937. //! <b>Effects</b>: Returns true if x is greater than y
  1938. //!
  1939. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1940. friend bool operator>(const multimap& x, const multimap& y);
  1941. //! <b>Effects</b>: Returns true if x is equal or less than y
  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 is equal or greater than y
  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>: x.swap(y)
  1950. //!
  1951. //! <b>Complexity</b>: Constant.
  1952. friend void swap(multimap& x, multimap& y)
  1953. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  1954. && boost::container::dtl::is_nothrow_swappable<Compare>::value );
  1955. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1956. };
  1957. #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
  1958. template <typename InputIterator>
  1959. multimap(InputIterator, InputIterator) ->
  1960. multimap< it_based_non_const_first_type_t<InputIterator>
  1961. , it_based_second_type_t<InputIterator>>;
  1962. template < typename InputIterator, typename AllocatorOrCompare>
  1963. multimap(InputIterator, InputIterator, AllocatorOrCompare const&) ->
  1964. multimap< it_based_non_const_first_type_t<InputIterator>
  1965. , it_based_second_type_t<InputIterator>
  1966. , typename dtl::if_c< // Compare
  1967. dtl::is_allocator<AllocatorOrCompare>::value
  1968. , std::less<it_based_non_const_first_type_t<InputIterator>>
  1969. , AllocatorOrCompare
  1970. >::type
  1971. , typename dtl::if_c< // Allocator
  1972. dtl::is_allocator<AllocatorOrCompare>::value
  1973. , AllocatorOrCompare
  1974. , new_allocator<std::pair<it_based_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
  1975. >::type
  1976. >;
  1977. template < typename InputIterator, typename Compare, typename Allocator
  1978. , typename = dtl::require_nonallocator_t<Compare>
  1979. , typename = dtl::require_allocator_t<Allocator>>
  1980. multimap(InputIterator, InputIterator, Compare const&, Allocator const&) ->
  1981. multimap< it_based_non_const_first_type_t<InputIterator>
  1982. , it_based_second_type_t<InputIterator>
  1983. , Compare
  1984. , Allocator>;
  1985. template <typename InputIterator>
  1986. multimap(ordered_range_t, InputIterator, InputIterator) ->
  1987. multimap< it_based_non_const_first_type_t<InputIterator>
  1988. , it_based_second_type_t<InputIterator>>;
  1989. template < typename InputIterator, typename AllocatorOrCompare>
  1990. multimap(ordered_range_t, InputIterator, InputIterator, AllocatorOrCompare const&) ->
  1991. multimap< it_based_non_const_first_type_t<InputIterator>
  1992. , it_based_second_type_t<InputIterator>
  1993. , typename dtl::if_c< // Compare
  1994. dtl::is_allocator<AllocatorOrCompare>::value
  1995. , std::less<it_based_const_first_type_t<InputIterator>>
  1996. , AllocatorOrCompare
  1997. >::type
  1998. , typename dtl::if_c< // Allocator
  1999. dtl::is_allocator<AllocatorOrCompare>::value
  2000. , AllocatorOrCompare
  2001. , new_allocator<std::pair<it_based_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
  2002. >::type
  2003. >;
  2004. template < typename InputIterator, typename Compare, typename Allocator
  2005. , typename = dtl::require_nonallocator_t<Compare>
  2006. , typename = dtl::require_allocator_t<Allocator>>
  2007. multimap(ordered_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
  2008. multimap< it_based_non_const_first_type_t<InputIterator>
  2009. , it_based_second_type_t<InputIterator>
  2010. , Compare
  2011. , Allocator>;
  2012. #endif
  2013. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  2014. } //namespace container {
  2015. //!has_trivial_destructor_after_move<> == true_type
  2016. //!specialization for optimizations
  2017. template <class Key, class T, class Compare, class Allocator, class Options>
  2018. struct has_trivial_destructor_after_move<boost::container::multimap<Key, T, Compare, Allocator, Options> >
  2019. {
  2020. typedef ::boost::container::dtl::tree<std::pair<const Key, T>, int, Compare, Allocator, Options> tree;
  2021. static const bool value = ::boost::has_trivial_destructor_after_move<tree>::value;
  2022. };
  2023. namespace container {
  2024. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  2025. }}
  2026. #include <boost/container/detail/config_end.hpp>
  2027. #endif // BOOST_CONTAINER_MAP_HPP