flat_map.hpp 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982
  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_FLAT_MAP_HPP
  11. #define BOOST_CONTAINER_FLAT_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/allocator_traits.hpp>
  22. #include <boost/container/container_fwd.hpp>
  23. #include <boost/container/new_allocator.hpp> //new_allocator
  24. #include <boost/container/throw_exception.hpp>
  25. // container/detail
  26. #include <boost/container/detail/flat_tree.hpp>
  27. #include <boost/container/detail/type_traits.hpp>
  28. #include <boost/container/detail/mpl.hpp>
  29. #include <boost/container/detail/algorithm.hpp> //equal()
  30. #include <boost/container/detail/container_or_allocator_rebind.hpp>
  31. // move
  32. #include <boost/move/utility_core.hpp>
  33. #include <boost/move/traits.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
  40. #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
  41. #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal
  42. //others
  43. #include <boost/core/no_exceptions_support.hpp>
  44. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  45. #include <initializer_list>
  46. #endif
  47. namespace boost {
  48. namespace container {
  49. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  50. template <class Key, class T, class Compare, class AllocatorOrContainer>
  51. class flat_multimap;
  52. namespace dtl{
  53. template<class D, class S>
  54. BOOST_CONTAINER_FORCEINLINE static D &force(S &s)
  55. { return *reinterpret_cast<D*>(&s); }
  56. template<class D, class S>
  57. BOOST_CONTAINER_FORCEINLINE static D force_copy(const S &s)
  58. {
  59. const D *const vp = reinterpret_cast<const D *>(&s);
  60. D ret_val(*vp);
  61. return ret_val;
  62. }
  63. } //namespace dtl{
  64. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  65. //! A flat_map is a kind of associative container that supports unique keys (contains at
  66. //! most one of each key value) and provides for fast retrieval of values of another
  67. //! type T based on the keys.
  68. //!
  69. //! A flat_map satisfies all of the requirements of a container, a reversible
  70. //! container and an associative container. A flat_map also provides
  71. //! most operations described for unique keys. For a
  72. //! flat_map<Key,T> the key_type is Key and the value_type is std::pair<Key,T>
  73. //! (unlike std::map<Key, T> which value_type is std::pair<<b>const</b> Key, T>).
  74. //!
  75. //! flat_map is similar to std::map but it's implemented by as an ordered sequence container.
  76. //! The underlying sequence container is by default <i>vector</i> but it can also work
  77. //! user-provided vector-like SequenceContainers (like <i>static_vector</i> or <i>small_vector</i>).
  78. //!
  79. //! Using vector-like sequence containers means that inserting a new element into a flat_map might invalidate
  80. //! previous iterators and references (unless that sequence container is <i>stable_vector</i> or a similar
  81. //! container that offers stable pointers and references). Similarly, erasing an element might invalidate
  82. //! iterators and references pointing to elements that come after (their keys are bigger) the erased element.
  83. //!
  84. //! This container provides random-access iterators.
  85. //!
  86. //! \tparam Key is the key_type of the map
  87. //! \tparam Value is the <code>mapped_type</code>
  88. //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
  89. //! \tparam AllocatorOrContainer is either:
  90. //! - The allocator to allocate <code>value_type</code>s (e.g. <i>allocator< std::pair<Key, T> > </i>).
  91. //! (in this case <i>sequence_type</i> will be vector<value_type, AllocatorOrContainer>)
  92. //! - The SequenceContainer to be used as the underlying <i>sequence_type</i>. It must be a vector-like
  93. //! sequence container with random-access iterators..
  94. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  95. template <class Key, class T, class Compare = std::less<Key>, class AllocatorOrContainer = new_allocator< std::pair< Key, T> > >
  96. #else
  97. template <class Key, class T, class Compare, class AllocatorOrContainer>
  98. #endif
  99. class flat_map
  100. {
  101. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  102. private:
  103. BOOST_COPYABLE_AND_MOVABLE(flat_map)
  104. //This is the tree that we should store if pair was movable
  105. typedef dtl::flat_tree<
  106. std::pair<Key, T>,
  107. dtl::select1st<Key>,
  108. Compare,
  109. AllocatorOrContainer> tree_t;
  110. //This is the real tree stored here. It's based on a movable pair
  111. typedef dtl::flat_tree<
  112. dtl::pair<Key, T>,
  113. dtl::select1st<Key>,
  114. Compare,
  115. typename dtl::container_or_allocator_rebind<AllocatorOrContainer, dtl::pair<Key, T> >::type
  116. > impl_tree_t;
  117. impl_tree_t m_flat_tree; // flat tree representing flat_map
  118. typedef typename impl_tree_t::value_type impl_value_type;
  119. typedef typename impl_tree_t::const_iterator impl_const_iterator;
  120. typedef typename impl_tree_t::iterator impl_iterator;
  121. typedef typename impl_tree_t::allocator_type impl_allocator_type;
  122. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  123. typedef std::initializer_list<impl_value_type> impl_initializer_list;
  124. #endif
  125. typedef dtl::flat_tree_value_compare
  126. < Compare
  127. , dtl::select1st<Key>
  128. , std::pair<Key, T> > value_compare_t;
  129. typedef typename tree_t::iterator iterator_t;
  130. typedef typename tree_t::const_iterator const_iterator_t;
  131. typedef typename tree_t::reverse_iterator reverse_iterator_t;
  132. typedef typename tree_t::const_reverse_iterator const_reverse_iterator_t;
  133. public:
  134. typedef typename impl_tree_t::stored_allocator_type impl_stored_allocator_type;
  135. typedef typename impl_tree_t::sequence_type impl_sequence_type;
  136. BOOST_CONTAINER_FORCEINLINE impl_tree_t &tree()
  137. { return m_flat_tree; }
  138. BOOST_CONTAINER_FORCEINLINE const impl_tree_t &tree() const
  139. { return m_flat_tree; }
  140. private:
  141. typedef typename tree_t::get_stored_allocator_const_return_t get_stored_allocator_const_return_t;
  142. typedef typename tree_t::get_stored_allocator_noconst_return_t get_stored_allocator_noconst_return_t;
  143. typedef typename impl_tree_t::get_stored_allocator_const_return_t impl_get_stored_allocator_const_return_t;
  144. typedef typename impl_tree_t::get_stored_allocator_noconst_return_t impl_get_stored_allocator_noconst_return_t;
  145. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  146. public:
  147. //////////////////////////////////////////////
  148. //
  149. // types
  150. //
  151. //////////////////////////////////////////////
  152. typedef Key key_type;
  153. typedef T mapped_type;
  154. typedef Compare key_compare;
  155. typedef std::pair<Key, T> value_type;
  156. typedef typename BOOST_CONTAINER_IMPDEF(tree_t::sequence_type) sequence_type;
  157. typedef typename sequence_type::allocator_type allocator_type;
  158. typedef ::boost::container::allocator_traits<allocator_type> allocator_traits_type;
  159. typedef typename sequence_type::pointer pointer;
  160. typedef typename sequence_type::const_pointer const_pointer;
  161. typedef typename sequence_type::reference reference;
  162. typedef typename sequence_type::const_reference const_reference;
  163. typedef typename sequence_type::size_type size_type;
  164. typedef typename sequence_type::difference_type difference_type;
  165. typedef typename BOOST_CONTAINER_IMPDEF(tree_t::stored_allocator_type) stored_allocator_type;
  166. typedef typename BOOST_CONTAINER_IMPDEF(tree_t::value_compare) value_compare;
  167. typedef typename sequence_type::iterator iterator;
  168. typedef typename sequence_type::const_iterator const_iterator;
  169. typedef typename sequence_type::reverse_iterator reverse_iterator;
  170. typedef typename sequence_type::const_reverse_iterator const_reverse_iterator;
  171. typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type;
  172. //AllocatorOrContainer::value_type must be std::pair<Key, T>
  173. BOOST_STATIC_ASSERT((dtl::is_same<std::pair<Key, T>, value_type>::value));
  174. //////////////////////////////////////////////
  175. //
  176. // construct/copy/destroy
  177. //
  178. //////////////////////////////////////////////
  179. //! <b>Effects</b>: Default constructs an empty flat_map.
  180. //!
  181. //! <b>Complexity</b>: Constant.
  182. BOOST_CONTAINER_FORCEINLINE flat_map() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<AllocatorOrContainer>::value &&
  183. dtl::is_nothrow_default_constructible<Compare>::value)
  184. : m_flat_tree()
  185. {}
  186. //! <b>Effects</b>: Constructs an empty flat_map using the specified allocator.
  187. //!
  188. //! <b>Complexity</b>: Constant.
  189. BOOST_CONTAINER_FORCEINLINE explicit flat_map(const allocator_type& a)
  190. : m_flat_tree(dtl::force<const impl_allocator_type>(a))
  191. {}
  192. //! <b>Effects</b>: Constructs an empty flat_map using the specified
  193. //! comparison object.
  194. //!
  195. //! <b>Complexity</b>: Constant.
  196. BOOST_CONTAINER_FORCEINLINE explicit flat_map(const Compare& comp)
  197. : m_flat_tree(comp)
  198. {}
  199. //! <b>Effects</b>: Constructs an empty flat_map using the specified
  200. //! comparison object and allocator.
  201. //!
  202. //! <b>Complexity</b>: Constant.
  203. BOOST_CONTAINER_FORCEINLINE flat_map(const Compare& comp, const allocator_type& a)
  204. : m_flat_tree(comp, dtl::force<const impl_allocator_type>(a))
  205. {}
  206. //! <b>Effects</b>: Constructs an empty flat_map and
  207. //! and inserts elements from the range [first ,last ).
  208. //!
  209. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  210. //! the predicate and otherwise N logN, where N is last - first.
  211. template <class InputIterator>
  212. BOOST_CONTAINER_FORCEINLINE flat_map(InputIterator first, InputIterator last)
  213. : m_flat_tree(true, first, last)
  214. {}
  215. //! <b>Effects</b>: Constructs an empty flat_map using the specified
  216. //! allocator, and inserts elements from the range [first ,last ).
  217. //!
  218. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  219. //! the predicate and otherwise N logN, where N is last - first.
  220. template <class InputIterator>
  221. BOOST_CONTAINER_FORCEINLINE flat_map(InputIterator first, InputIterator last, const allocator_type& a)
  222. : m_flat_tree(true, first, last, dtl::force<const impl_allocator_type>(a))
  223. {}
  224. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  225. //! and inserts elements from the range [first ,last ).
  226. //!
  227. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  228. //! the predicate and otherwise N logN, where N is last - first.
  229. template <class InputIterator>
  230. BOOST_CONTAINER_FORCEINLINE flat_map(InputIterator first, InputIterator last, const Compare& comp)
  231. : m_flat_tree(true, first, last, comp)
  232. {}
  233. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  234. //! allocator, and inserts elements from the range [first ,last ).
  235. //!
  236. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  237. //! the predicate and otherwise N logN, where N is last - first.
  238. template <class InputIterator>
  239. BOOST_CONTAINER_FORCEINLINE flat_map(InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
  240. : m_flat_tree(true, first, last, comp, dtl::force<const impl_allocator_type>(a))
  241. {}
  242. //! <b>Effects</b>: Constructs an empty flat_map
  243. //! and inserts elements from the ordered range [first ,last). This function
  244. //! is more efficient than the normal range creation for ordered ranges.
  245. //!
  246. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  247. //!
  248. //! <b>Complexity</b>: Linear in N.
  249. //!
  250. //! <b>Note</b>: Non-standard extension.
  251. template <class InputIterator>
  252. BOOST_CONTAINER_FORCEINLINE
  253. flat_map(ordered_unique_range_t, InputIterator first, InputIterator last)
  254. : m_flat_tree(ordered_range, first, last)
  255. {}
  256. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  257. //! inserts elements from the ordered range [first ,last). This function
  258. //! is more efficient than the normal range creation for ordered ranges.
  259. //!
  260. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  261. //!
  262. //! <b>Complexity</b>: Linear in N.
  263. //!
  264. //! <b>Note</b>: Non-standard extension.
  265. template <class InputIterator>
  266. BOOST_CONTAINER_FORCEINLINE
  267. flat_map(ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp)
  268. : m_flat_tree(ordered_range, first, last, comp)
  269. {}
  270. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  271. //! allocator, and inserts elements from the ordered range [first ,last). This function
  272. //! is more efficient than the normal range creation for ordered ranges.
  273. //!
  274. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  275. //!
  276. //! <b>Complexity</b>: Linear in N.
  277. //!
  278. //! <b>Note</b>: Non-standard extension.
  279. template <class InputIterator>
  280. BOOST_CONTAINER_FORCEINLINE
  281. flat_map(ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
  282. : m_flat_tree(ordered_range, first, last, comp, dtl::force<const impl_allocator_type>(a))
  283. {}
  284. //! <b>Effects</b>: Constructs an empty flat_map using the specified allocator and
  285. //! inserts elements from the ordered range [first ,last). This function
  286. //! is more efficient than the normal range creation for ordered ranges.
  287. //!
  288. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  289. //!
  290. //! <b>Complexity</b>: Linear in N.
  291. //!
  292. //! <b>Note</b>: Non-standard extension.
  293. template <class InputIterator>
  294. BOOST_CONTAINER_FORCEINLINE
  295. flat_map(ordered_unique_range_t, InputIterator first, InputIterator last, const allocator_type& a)
  296. : m_flat_tree(ordered_range, first, last, Compare(), a)
  297. {}
  298. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  299. //! <b>Effects</b>: Constructs an empty flat_map and
  300. //! inserts elements from the range [il.begin() ,il.end()).
  301. //!
  302. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  303. //! the predicate and otherwise N logN, where N is last - first.
  304. BOOST_CONTAINER_FORCEINLINE flat_map(std::initializer_list<value_type> il)
  305. : m_flat_tree( true
  306. , dtl::force<impl_initializer_list>(il).begin()
  307. , dtl::force<impl_initializer_list>(il).end())
  308. {}
  309. //! <b>Effects</b>: Constructs an empty flat_map using the specified
  310. //! allocator, and inserts elements from the range [il.begin() ,il.end()).
  311. //!
  312. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  313. //! the predicate and otherwise N logN, where N is last - first.
  314. BOOST_CONTAINER_FORCEINLINE flat_map(std::initializer_list<value_type> il, const allocator_type& a)
  315. : m_flat_tree( true
  316. , dtl::force<impl_initializer_list>(il).begin()
  317. , dtl::force<impl_initializer_list>(il).end()
  318. , dtl::force<const impl_allocator_type>(a))
  319. {}
  320. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  321. //! inserts elements from the range [il.begin() ,il.end()).
  322. //!
  323. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  324. //! the predicate and otherwise N logN, where N is last - first.
  325. BOOST_CONTAINER_FORCEINLINE flat_map(std::initializer_list<value_type> il, const Compare& comp)
  326. : m_flat_tree(true
  327. , dtl::force<impl_initializer_list>(il).begin()
  328. , dtl::force<impl_initializer_list>(il).end()
  329. , comp)
  330. {}
  331. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  332. //! allocator, and inserts elements from the range [il.begin() ,il.end()).
  333. //!
  334. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  335. //! the predicate and otherwise N logN, where N is last - first.
  336. BOOST_CONTAINER_FORCEINLINE flat_map(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
  337. : m_flat_tree(true
  338. , dtl::force<impl_initializer_list>(il).begin()
  339. , dtl::force<impl_initializer_list>(il).end()
  340. , comp
  341. , dtl::force<const impl_allocator_type>(a))
  342. {}
  343. //! <b>Effects</b>: Constructs an empty flat_map using and
  344. //! inserts elements from the ordered unique range [il.begin(), il.end()). This function
  345. //! is more efficient than the normal range creation for ordered ranges.
  346. //!
  347. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  348. //! unique values.
  349. //!
  350. //! <b>Complexity</b>: Linear in N.
  351. //!
  352. //! <b>Note</b>: Non-standard extension.
  353. BOOST_CONTAINER_FORCEINLINE flat_map(ordered_unique_range_t, std::initializer_list<value_type> il)
  354. : m_flat_tree(ordered_unique_range
  355. , dtl::force<impl_initializer_list>(il).begin()
  356. , dtl::force<impl_initializer_list>(il).end())
  357. {}
  358. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  359. //! inserts elements from the ordered unique range [il.begin(), il.end()). This function
  360. //! is more efficient than the normal range creation for ordered ranges.
  361. //!
  362. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  363. //! unique values.
  364. //!
  365. //! <b>Complexity</b>: Linear in N.
  366. //!
  367. //! <b>Note</b>: Non-standard extension.
  368. BOOST_CONTAINER_FORCEINLINE flat_map(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp)
  369. : m_flat_tree(ordered_unique_range
  370. , dtl::force<impl_initializer_list>(il).begin()
  371. , dtl::force<impl_initializer_list>(il).end()
  372. , comp)
  373. {}
  374. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  375. //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
  376. //! is more efficient than the normal range creation for ordered ranges.
  377. //!
  378. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  379. //! unique values.
  380. //!
  381. //! <b>Complexity</b>: Linear in N.
  382. //!
  383. //! <b>Note</b>: Non-standard extension.
  384. BOOST_CONTAINER_FORCEINLINE flat_map(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
  385. : m_flat_tree( ordered_unique_range
  386. , dtl::force<impl_initializer_list>(il).begin()
  387. , dtl::force<impl_initializer_list>(il).end()
  388. , comp
  389. , dtl::force<const impl_allocator_type>(a))
  390. {}
  391. #endif
  392. //! <b>Effects</b>: Copy constructs a flat_map.
  393. //!
  394. //! <b>Complexity</b>: Linear in x.size().
  395. BOOST_CONTAINER_FORCEINLINE flat_map(const flat_map& x)
  396. : m_flat_tree(x.m_flat_tree)
  397. {}
  398. //! <b>Effects</b>: Move constructs a flat_map.
  399. //! Constructs *this using x's resources.
  400. //!
  401. //! <b>Complexity</b>: Constant.
  402. //!
  403. //! <b>Postcondition</b>: x is emptied.
  404. BOOST_CONTAINER_FORCEINLINE flat_map(BOOST_RV_REF(flat_map) x)
  405. BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
  406. : m_flat_tree(boost::move(x.m_flat_tree))
  407. {}
  408. //! <b>Effects</b>: Copy constructs a flat_map using the specified allocator.
  409. //!
  410. //! <b>Complexity</b>: Linear in x.size().
  411. BOOST_CONTAINER_FORCEINLINE flat_map(const flat_map& x, const allocator_type &a)
  412. : m_flat_tree(x.m_flat_tree, dtl::force<const impl_allocator_type>(a))
  413. {}
  414. //! <b>Effects</b>: Move constructs a flat_map using the specified allocator.
  415. //! Constructs *this using x's resources.
  416. //!
  417. //! <b>Complexity</b>: Constant if x.get_allocator() == a, linear otherwise.
  418. BOOST_CONTAINER_FORCEINLINE flat_map(BOOST_RV_REF(flat_map) x, const allocator_type &a)
  419. : m_flat_tree(boost::move(x.m_flat_tree), dtl::force<const impl_allocator_type>(a))
  420. {}
  421. //! <b>Effects</b>: Makes *this a copy of x.
  422. //!
  423. //! <b>Complexity</b>: Linear in x.size().
  424. BOOST_CONTAINER_FORCEINLINE flat_map& operator=(BOOST_COPY_ASSIGN_REF(flat_map) x)
  425. { m_flat_tree = x.m_flat_tree; return *this; }
  426. //! <b>Effects</b>: Move constructs a flat_map.
  427. //! Constructs *this using x's resources.
  428. //!
  429. //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
  430. //! is false and (allocation throws or value_type's move constructor throws)
  431. //!
  432. //! <b>Complexity</b>: Constant if allocator_traits_type::
  433. //! propagate_on_container_move_assignment is true or
  434. //! this->get>allocator() == x.get_allocator(). Linear otherwise.
  435. BOOST_CONTAINER_FORCEINLINE flat_map& operator=(BOOST_RV_REF(flat_map) x)
  436. BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
  437. allocator_traits_type::is_always_equal::value) &&
  438. boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
  439. { m_flat_tree = boost::move(x.m_flat_tree); return *this; }
  440. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  441. //! <b>Effects</b>: Assign elements from il to *this
  442. flat_map& operator=(std::initializer_list<value_type> il)
  443. {
  444. this->clear();
  445. this->insert(il.begin(), il.end());
  446. return *this;
  447. }
  448. #endif
  449. //! <b>Effects</b>: Returns a copy of the allocator that
  450. //! was passed to the object's constructor.
  451. //!
  452. //! <b>Complexity</b>: Constant.
  453. BOOST_CONTAINER_FORCEINLINE allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  454. { return dtl::force_copy<allocator_type>(m_flat_tree.get_allocator()); }
  455. //! <b>Effects</b>: Returns a reference to the internal allocator.
  456. //!
  457. //! <b>Throws</b>: Nothing
  458. //!
  459. //! <b>Complexity</b>: Constant.
  460. //!
  461. //! <b>Note</b>: Non-standard extension.
  462. BOOST_CONTAINER_FORCEINLINE get_stored_allocator_noconst_return_t get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
  463. {
  464. impl_get_stored_allocator_noconst_return_t r = m_flat_tree.get_stored_allocator();
  465. return dtl::force<stored_allocator_type>(r);
  466. }
  467. //! <b>Effects</b>: Returns a reference to the internal allocator.
  468. //!
  469. //! <b>Throws</b>: Nothing
  470. //!
  471. //! <b>Complexity</b>: Constant.
  472. //!
  473. //! <b>Note</b>: Non-standard extension.
  474. BOOST_CONTAINER_FORCEINLINE get_stored_allocator_const_return_t get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  475. {
  476. impl_get_stored_allocator_const_return_t r = m_flat_tree.get_stored_allocator();
  477. return dtl::force<const stored_allocator_type>(r);
  478. }
  479. //////////////////////////////////////////////
  480. //
  481. // iterators
  482. //
  483. //////////////////////////////////////////////
  484. //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
  485. //!
  486. //! <b>Throws</b>: Nothing.
  487. //!
  488. //! <b>Complexity</b>: Constant.
  489. BOOST_CONTAINER_FORCEINLINE iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
  490. { return dtl::force_copy<iterator>(m_flat_tree.begin()); }
  491. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  492. //!
  493. //! <b>Throws</b>: Nothing.
  494. //!
  495. //! <b>Complexity</b>: Constant.
  496. BOOST_CONTAINER_FORCEINLINE const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
  497. { return dtl::force_copy<const_iterator>(m_flat_tree.begin()); }
  498. //! <b>Effects</b>: Returns an iterator to the end of the container.
  499. //!
  500. //! <b>Throws</b>: Nothing.
  501. //!
  502. //! <b>Complexity</b>: Constant.
  503. BOOST_CONTAINER_FORCEINLINE iterator end() BOOST_NOEXCEPT_OR_NOTHROW
  504. { return dtl::force_copy<iterator>(m_flat_tree.end()); }
  505. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  506. //!
  507. //! <b>Throws</b>: Nothing.
  508. //!
  509. //! <b>Complexity</b>: Constant.
  510. BOOST_CONTAINER_FORCEINLINE const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
  511. { return dtl::force_copy<const_iterator>(m_flat_tree.end()); }
  512. //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
  513. //! of the reversed container.
  514. //!
  515. //! <b>Throws</b>: Nothing.
  516. //!
  517. //! <b>Complexity</b>: Constant.
  518. BOOST_CONTAINER_FORCEINLINE reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
  519. { return dtl::force_copy<reverse_iterator>(m_flat_tree.rbegin()); }
  520. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  521. //! of the reversed container.
  522. //!
  523. //! <b>Throws</b>: Nothing.
  524. //!
  525. //! <b>Complexity</b>: Constant.
  526. BOOST_CONTAINER_FORCEINLINE const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  527. { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.rbegin()); }
  528. //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
  529. //! of the reversed container.
  530. //!
  531. //! <b>Throws</b>: Nothing.
  532. //!
  533. //! <b>Complexity</b>: Constant.
  534. BOOST_CONTAINER_FORCEINLINE reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
  535. { return dtl::force_copy<reverse_iterator>(m_flat_tree.rend()); }
  536. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  537. //! of the reversed container.
  538. //!
  539. //! <b>Throws</b>: Nothing.
  540. //!
  541. //! <b>Complexity</b>: Constant.
  542. BOOST_CONTAINER_FORCEINLINE const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
  543. { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.rend()); }
  544. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  545. //!
  546. //! <b>Throws</b>: Nothing.
  547. //!
  548. //! <b>Complexity</b>: Constant.
  549. BOOST_CONTAINER_FORCEINLINE const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  550. { return dtl::force_copy<const_iterator>(m_flat_tree.cbegin()); }
  551. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  552. //!
  553. //! <b>Throws</b>: Nothing.
  554. //!
  555. //! <b>Complexity</b>: Constant.
  556. BOOST_CONTAINER_FORCEINLINE const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
  557. { return dtl::force_copy<const_iterator>(m_flat_tree.cend()); }
  558. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  559. //! of the reversed container.
  560. //!
  561. //! <b>Throws</b>: Nothing.
  562. //!
  563. //! <b>Complexity</b>: Constant.
  564. BOOST_CONTAINER_FORCEINLINE const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  565. { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.crbegin()); }
  566. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  567. //! of the reversed container.
  568. //!
  569. //! <b>Throws</b>: Nothing.
  570. //!
  571. //! <b>Complexity</b>: Constant.
  572. BOOST_CONTAINER_FORCEINLINE const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
  573. { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.crend()); }
  574. //////////////////////////////////////////////
  575. //
  576. // capacity
  577. //
  578. //////////////////////////////////////////////
  579. //! <b>Effects</b>: Returns true if the container contains no elements.
  580. //!
  581. //! <b>Throws</b>: Nothing.
  582. //!
  583. //! <b>Complexity</b>: Constant.
  584. BOOST_CONTAINER_FORCEINLINE bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
  585. { return m_flat_tree.empty(); }
  586. //! <b>Effects</b>: Returns the number of the elements contained in the container.
  587. //!
  588. //! <b>Throws</b>: Nothing.
  589. //!
  590. //! <b>Complexity</b>: Constant.
  591. BOOST_CONTAINER_FORCEINLINE size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
  592. { return m_flat_tree.size(); }
  593. //! <b>Effects</b>: Returns the largest possible size of the container.
  594. //!
  595. //! <b>Throws</b>: Nothing.
  596. //!
  597. //! <b>Complexity</b>: Constant.
  598. BOOST_CONTAINER_FORCEINLINE size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
  599. { return m_flat_tree.max_size(); }
  600. //! <b>Effects</b>: Number of elements for which memory has been allocated.
  601. //! capacity() is always greater than or equal to size().
  602. //!
  603. //! <b>Throws</b>: Nothing.
  604. //!
  605. //! <b>Complexity</b>: Constant.
  606. BOOST_CONTAINER_FORCEINLINE size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW
  607. { return m_flat_tree.capacity(); }
  608. //! <b>Effects</b>: If n is less than or equal to capacity(), or the
  609. //! underlying container has no `reserve` member, this call has no
  610. //! effect. Otherwise, it is a request for allocation of additional memory.
  611. //! If the request is successful, then capacity() is greater than or equal to
  612. //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
  613. //!
  614. //! <b>Throws</b>: If memory allocation allocation throws or T's copy constructor throws.
  615. //!
  616. //! <b>Note</b>: If capacity() is less than "cnt", iterators and references to
  617. //! to values might be invalidated.
  618. BOOST_CONTAINER_FORCEINLINE void reserve(size_type cnt)
  619. { m_flat_tree.reserve(cnt); }
  620. //! <b>Effects</b>: Tries to deallocate the excess of memory created
  621. // with previous allocations. The size of the vector is unchanged
  622. //!
  623. //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
  624. //!
  625. //! <b>Complexity</b>: Linear to size().
  626. BOOST_CONTAINER_FORCEINLINE void shrink_to_fit()
  627. { m_flat_tree.shrink_to_fit(); }
  628. //////////////////////////////////////////////
  629. //
  630. // element access
  631. //
  632. //////////////////////////////////////////////
  633. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  634. //! Effects: If there is no key equivalent to x in the flat_map, inserts
  635. //! value_type(x, T()) into the flat_map.
  636. //!
  637. //! Returns: A reference to the mapped_type corresponding to x in *this.
  638. //!
  639. //! Complexity: Logarithmic.
  640. mapped_type &operator[](const key_type& k);
  641. //! Effects: If there is no key equivalent to x in the flat_map, inserts
  642. //! value_type(move(x), T()) into the flat_map (the key is move-constructed)
  643. //!
  644. //! Returns: A reference to the mapped_type corresponding to x in *this.
  645. //!
  646. //! Complexity: Logarithmic.
  647. mapped_type &operator[](key_type &&k) ;
  648. #elif defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN)
  649. //in compilers like GCC 3.4, we can't catch temporaries
  650. BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](const key_type &k) { return this->priv_subscript(k); }
  651. BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](BOOST_RV_REF(key_type) k) { return this->priv_subscript(::boost::move(k)); }
  652. #else
  653. BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript)
  654. #endif
  655. //! Effects: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
  656. //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
  657. //! as if by insert, constructing it from value_type(k, forward<M>(obj)).
  658. //!
  659. //! No iterators or references are invalidated. If the insertion is successful, pointers and references
  660. //! to the element obtained while it is held in the node handle are invalidated, and pointers and
  661. //! references obtained to that element before it was extracted become valid.
  662. //!
  663. //! Returns: The bool component is true if the insertion took place and false if the assignment
  664. //! took place. The iterator component is pointing at the element that was inserted or updated.
  665. //!
  666. //! Complexity: Logarithmic in the size of the container.
  667. template <class M>
  668. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(const key_type& k, BOOST_FWD_REF(M) obj)
  669. {
  670. return dtl::force_copy< std::pair<iterator, bool> >
  671. (this->m_flat_tree.insert_or_assign
  672. ( impl_const_iterator(), k, ::boost::forward<M>(obj))
  673. );
  674. }
  675. //! Effects: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
  676. //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
  677. //! as if by insert, constructing it from value_type(k, move(obj)).
  678. //!
  679. //! No iterators or references are invalidated. If the insertion is successful, pointers and references
  680. //! to the element obtained while it is held in the node handle are invalidated, and pointers and
  681. //! references obtained to that element before it was extracted become valid.
  682. //!
  683. //! Returns: The bool component is true if the insertion took place and false if the assignment
  684. //! took place. The iterator component is pointing at the element that was inserted or updated.
  685. //!
  686. //! Complexity: Logarithmic in the size of the container.
  687. template <class M>
  688. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
  689. {
  690. return dtl::force_copy< std::pair<iterator, bool> >
  691. (this->m_flat_tree.insert_or_assign
  692. ( impl_const_iterator(), ::boost::move(k), ::boost::forward<M>(obj))
  693. );
  694. }
  695. //! Effects: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
  696. //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
  697. //! as if by insert, constructing it from value_type(k, forward<M>(obj)) and the new element
  698. //! to the container as close as possible to the position just before hint.
  699. //!
  700. //! No iterators or references are invalidated. If the insertion is successful, pointers and references
  701. //! to the element obtained while it is held in the node handle are invalidated, and pointers and
  702. //! references obtained to that element before it was extracted become valid.
  703. //!
  704. //! Returns: The bool component is true if the insertion took place and false if the assignment
  705. //! took place. The iterator component is pointing at the element that was inserted or updated.
  706. //!
  707. //! Complexity: Logarithmic in the size of the container in general, but amortized constant if
  708. //! the new element is inserted just before hint.
  709. template <class M>
  710. BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, const key_type& k, BOOST_FWD_REF(M) obj)
  711. {
  712. return dtl::force_copy<iterator>
  713. (this->m_flat_tree.insert_or_assign
  714. ( dtl::force_copy<impl_const_iterator>(hint)
  715. , k, ::boost::forward<M>(obj)).first
  716. );
  717. }
  718. //! Effects: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
  719. //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
  720. //! as if by insert, constructing it from value_type(k, move(obj)) and the new element
  721. //! to the container as close as possible to the position just before hint.
  722. //!
  723. //! No iterators or references are invalidated. If the insertion is successful, pointers and references
  724. //! to the element obtained while it is held in the node handle are invalidated, and pointers and
  725. //! references obtained to that element before it was extracted become valid.
  726. //!
  727. //! Returns: The bool component is true if the insertion took place and false if the assignment
  728. //! took place. The iterator component is pointing at the element that was inserted or updated.
  729. //!
  730. //! Complexity: Logarithmic in the size of the container in general, but amortized constant if
  731. //! the new element is inserted just before hint.
  732. template <class M>
  733. BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
  734. {
  735. return dtl::force_copy<iterator>
  736. (this->m_flat_tree.insert_or_assign
  737. ( dtl::force_copy<impl_const_iterator>(hint)
  738. , ::boost::move(k), ::boost::forward<M>(obj)).first
  739. );
  740. }
  741. //! @copydoc ::boost::container::flat_set::nth(size_type)
  742. BOOST_CONTAINER_FORCEINLINE iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
  743. { return dtl::force_copy<iterator>(m_flat_tree.nth(n)); }
  744. //! @copydoc ::boost::container::flat_set::nth(size_type) const
  745. BOOST_CONTAINER_FORCEINLINE const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
  746. { return dtl::force_copy<iterator>(m_flat_tree.nth(n)); }
  747. //! @copydoc ::boost::container::flat_set::index_of(iterator)
  748. BOOST_CONTAINER_FORCEINLINE size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
  749. { return m_flat_tree.index_of(dtl::force_copy<impl_iterator>(p)); }
  750. //! @copydoc ::boost::container::flat_set::index_of(const_iterator) const
  751. BOOST_CONTAINER_FORCEINLINE size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
  752. { return m_flat_tree.index_of(dtl::force_copy<impl_const_iterator>(p)); }
  753. //! Returns: A reference to the element whose key is equivalent to x.
  754. //!
  755. //! Throws: An exception object of type out_of_range if no such element is present.
  756. //!
  757. //! Complexity: logarithmic.
  758. T& at(const key_type& k)
  759. {
  760. iterator i = this->find(k);
  761. if(i == this->end()){
  762. throw_out_of_range("flat_map::at key not found");
  763. }
  764. return i->second;
  765. }
  766. //! Returns: A reference to the element whose key is equivalent to x.
  767. //!
  768. //! Throws: An exception object of type out_of_range if no such element is present.
  769. //!
  770. //! Complexity: logarithmic.
  771. const T& at(const key_type& k) const
  772. {
  773. const_iterator i = this->find(k);
  774. if(i == this->end()){
  775. throw_out_of_range("flat_map::at key not found");
  776. }
  777. return i->second;
  778. }
  779. //////////////////////////////////////////////
  780. //
  781. // modifiers
  782. //
  783. //////////////////////////////////////////////
  784. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  785. //! <b>Effects</b>: Inserts an object x of type T constructed with
  786. //! std::forward<Args>(args)... if and only if there is no element in the container
  787. //! with key equivalent to the key of x.
  788. //!
  789. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  790. //! if the insertion takes place, and the iterator component of the pair
  791. //! points to the element with key equivalent to the key of x.
  792. //!
  793. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  794. //! to the elements with bigger keys than x.
  795. //!
  796. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  797. template <class... Args>
  798. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_FWD_REF(Args)... args)
  799. { return dtl::force_copy< std::pair<iterator, bool> >(m_flat_tree.emplace_unique(boost::forward<Args>(args)...)); }
  800. //! <b>Effects</b>: Inserts an object of type T constructed with
  801. //! std::forward<Args>(args)... in the container if and only if there is
  802. //! no element in the container with key equivalent to the key of x.
  803. //! p is a hint pointing to where the insert should start to search.
  804. //!
  805. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  806. //! to the key of x.
  807. //!
  808. //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
  809. //! right before p) plus insertion linear to the elements with bigger keys than x.
  810. //!
  811. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  812. template <class... Args>
  813. BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
  814. {
  815. return dtl::force_copy<iterator>
  816. (m_flat_tree.emplace_hint_unique( dtl::force_copy<impl_const_iterator>(hint)
  817. , boost::forward<Args>(args)...));
  818. }
  819. //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
  820. //! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
  821. //!
  822. //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
  823. //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
  824. //! forward_as_tuple(forward<Args>(args)...).
  825. //!
  826. //! <b>Returns</b>: The bool component of the returned pair is true if and only if the
  827. //! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
  828. //!
  829. //! <b>Complexity</b>: Logarithmic.
  830. template <class... Args>
  831. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k, BOOST_FWD_REF(Args)... args)
  832. {
  833. return dtl::force_copy< std::pair<iterator, bool> >(
  834. m_flat_tree.try_emplace(impl_const_iterator(), k, boost::forward<Args>(args)...));
  835. }
  836. //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
  837. //! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
  838. //!
  839. //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
  840. //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
  841. //! forward_as_tuple(forward<Args>(args)...).
  842. //!
  843. //! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
  844. //!
  845. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
  846. //! is inserted right before p.
  847. template <class... Args>
  848. BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k, BOOST_FWD_REF(Args)... args)
  849. {
  850. return dtl::force_copy<iterator>(m_flat_tree.try_emplace
  851. (dtl::force_copy<impl_const_iterator>(hint), k, boost::forward<Args>(args)...).first);
  852. }
  853. //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
  854. //! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
  855. //!
  856. //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
  857. //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
  858. //! forward_as_tuple(forward<Args>(args)...).
  859. //!
  860. //! <b>Returns</b>: The bool component of the returned pair is true if and only if the
  861. //! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
  862. //!
  863. //! <b>Complexity</b>: Logarithmic.
  864. template <class... Args>
  865. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
  866. {
  867. return dtl::force_copy< std::pair<iterator, bool> >
  868. (m_flat_tree.try_emplace(impl_const_iterator(), boost::move(k), boost::forward<Args>(args)...));
  869. }
  870. //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
  871. //! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
  872. //!
  873. //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
  874. //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
  875. //! forward_as_tuple(forward<Args>(args)...).
  876. //!
  877. //! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
  878. //!
  879. //! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
  880. //! is inserted right before p.
  881. template <class... Args>
  882. BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
  883. {
  884. return dtl::force_copy<iterator>
  885. (m_flat_tree.try_emplace(dtl::force_copy
  886. <impl_const_iterator>(hint), boost::move(k), boost::forward<Args>(args)...).first);
  887. }
  888. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  889. #define BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE(N) \
  890. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  891. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_MOVE_UREF##N)\
  892. {\
  893. return dtl::force_copy< std::pair<iterator, bool> >\
  894. (m_flat_tree.emplace_unique(BOOST_MOVE_FWD##N));\
  895. }\
  896. \
  897. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  898. BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  899. {\
  900. return dtl::force_copy<iterator>(m_flat_tree.emplace_hint_unique\
  901. (dtl::force_copy<impl_const_iterator>(hint) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
  902. }\
  903. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  904. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  905. {\
  906. return dtl::force_copy< std::pair<iterator, bool> >\
  907. (m_flat_tree.try_emplace(impl_const_iterator(), k BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
  908. }\
  909. \
  910. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  911. BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  912. { return dtl::force_copy<iterator>(m_flat_tree.try_emplace\
  913. (dtl::force_copy<impl_const_iterator>(hint), k BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first); }\
  914. \
  915. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  916. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  917. {\
  918. return dtl::force_copy< std::pair<iterator, bool> >\
  919. (m_flat_tree.try_emplace(impl_const_iterator(), boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
  920. }\
  921. \
  922. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  923. BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  924. { return dtl::force_copy<iterator>(m_flat_tree.try_emplace\
  925. (dtl::force_copy<impl_const_iterator>(hint), boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first); }\
  926. //
  927. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE)
  928. #undef BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE
  929. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  930. //! <b>Effects</b>: Inserts x if and only if there is no element in the container
  931. //! with key equivalent to the key of x.
  932. //!
  933. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  934. //! if the insertion takes place, and the iterator component of the pair
  935. //! points to the element with key equivalent to the key of x.
  936. //!
  937. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  938. //! to the elements with bigger keys than x.
  939. //!
  940. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  941. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(const value_type& x)
  942. { return dtl::force_copy<std::pair<iterator,bool> >(
  943. m_flat_tree.insert_unique(dtl::force<const impl_value_type>(x))); }
  944. //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
  945. //! only if there is no element in the container with key equivalent to the key of x.
  946. //!
  947. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  948. //! if the insertion takes place, and the iterator component of the pair
  949. //! points to the element with key equivalent to the key of x.
  950. //!
  951. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  952. //! to the elements with bigger keys than x.
  953. //!
  954. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  955. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(value_type) x)
  956. { return dtl::force_copy<std::pair<iterator,bool> >(
  957. m_flat_tree.insert_unique(boost::move(dtl::force<impl_value_type>(x)))); }
  958. //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
  959. //! only if there is no element in the container with key equivalent to the key of x.
  960. //!
  961. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  962. //! if the insertion takes place, and the iterator component of the pair
  963. //! points to the element with key equivalent to the key of x.
  964. //!
  965. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  966. //! to the elements with bigger keys than x.
  967. //!
  968. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  969. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(movable_value_type) x)
  970. {
  971. return dtl::force_copy<std::pair<iterator,bool> >
  972. (m_flat_tree.insert_unique(boost::move(x)));
  973. }
  974. //! <b>Effects</b>: Inserts a copy of x in the container if and only if there is
  975. //! no element in the container with key equivalent to the key of x.
  976. //! p is a hint pointing to where the insert should start to search.
  977. //!
  978. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  979. //! to the key of x.
  980. //!
  981. //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
  982. //! right before p) plus insertion linear to the elements with bigger keys than x.
  983. //!
  984. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  985. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
  986. {
  987. return dtl::force_copy<iterator>(
  988. m_flat_tree.insert_unique( dtl::force_copy<impl_const_iterator>(p)
  989. , dtl::force<const impl_value_type>(x)));
  990. }
  991. //! <b>Effects</b>: Inserts an element move constructed from x in the container.
  992. //! p is a hint pointing to where the insert should start to search.
  993. //!
  994. //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
  995. //!
  996. //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
  997. //! right before p) plus insertion linear to the elements with bigger keys than x.
  998. //!
  999. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1000. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
  1001. {
  1002. return dtl::force_copy<iterator>
  1003. (m_flat_tree.insert_unique( dtl::force_copy<impl_const_iterator>(p)
  1004. , boost::move(dtl::force<impl_value_type>(x))));
  1005. }
  1006. //! <b>Effects</b>: Inserts an element move constructed from x in the container.
  1007. //! p is a hint pointing to where the insert should start to search.
  1008. //!
  1009. //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
  1010. //!
  1011. //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
  1012. //! right before p) plus insertion linear to the elements with bigger keys than x.
  1013. //!
  1014. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1015. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
  1016. {
  1017. return dtl::force_copy<iterator>(
  1018. m_flat_tree.insert_unique(dtl::force_copy<impl_const_iterator>(p), boost::move(x)));
  1019. }
  1020. //! <b>Requires</b>: first, last are not iterators into *this.
  1021. //!
  1022. //! <b>Effects</b>: inserts each element from the range [first,last) if and only
  1023. //! if there is no element with key equivalent to the key of that element.
  1024. //!
  1025. //! <b>Complexity</b>: N log(size()+N).
  1026. //!
  1027. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1028. template <class InputIterator>
  1029. BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
  1030. { m_flat_tree.insert_unique(first, last); }
  1031. //! <b>Requires</b>: first, last are not iterators into *this.
  1032. //!
  1033. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
  1034. //! unique values.
  1035. //!
  1036. //! <b>Effects</b>: inserts each element from the range [first,last) if and only
  1037. //! if there is no element with key equivalent to the key of that element. This
  1038. //! function is more efficient than the normal range creation for ordered ranges.
  1039. //!
  1040. //! <b>Complexity</b>: Linear.
  1041. //!
  1042. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1043. //!
  1044. //! <b>Note</b>: Non-standard extension.
  1045. template <class InputIterator>
  1046. BOOST_CONTAINER_FORCEINLINE void insert(ordered_unique_range_t, InputIterator first, InputIterator last)
  1047. { m_flat_tree.insert_unique(ordered_unique_range, first, last); }
  1048. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1049. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
  1050. //! if there is no element with key equivalent to the key of that element.
  1051. //!
  1052. //! <b>Complexity</b>: N log(N).
  1053. //!
  1054. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1055. BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
  1056. {
  1057. m_flat_tree.insert_unique( dtl::force<impl_initializer_list>(il).begin()
  1058. , dtl::force<impl_initializer_list>(il).end());
  1059. }
  1060. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  1061. //! unique values.
  1062. //!
  1063. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
  1064. //! if there is no element with key equivalent to the key of that element. This
  1065. //! function is more efficient than the normal range creation for ordered ranges.
  1066. //!
  1067. //! <b>Complexity</b>: Linear.
  1068. //!
  1069. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1070. //!
  1071. //! <b>Note</b>: Non-standard extension.
  1072. BOOST_CONTAINER_FORCEINLINE void insert(ordered_unique_range_t, std::initializer_list<value_type> il)
  1073. {
  1074. m_flat_tree.insert_unique(ordered_unique_range
  1075. , dtl::force<impl_initializer_list>(il).begin()
  1076. , dtl::force<impl_initializer_list>(il).end());
  1077. }
  1078. #endif
  1079. //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
  1080. //!
  1081. //! <b>Effects</b>: Attempts to extract each element in source and insert it into a using
  1082. //! the comparison object of *this. If there is an element in a with key equivalent to the
  1083. //! key of an element from source, then that element is not extracted from source.
  1084. //!
  1085. //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
  1086. //! to those same elements but as members of *this. Iterators referring to the transferred
  1087. //! elements will continue to refer to their elements, but they now behave as iterators into *this,
  1088. //! not into source.
  1089. //!
  1090. //! <b>Throws</b>: Nothing unless the comparison object throws.
  1091. //!
  1092. //! <b>Complexity</b>: N log(size() + N) (N has the value source.size())
  1093. template<class C2>
  1094. BOOST_CONTAINER_FORCEINLINE void merge(flat_map<Key, T, C2, AllocatorOrContainer>& source)
  1095. { m_flat_tree.merge_unique(source.tree()); }
  1096. //! @copydoc ::boost::container::flat_map::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
  1097. template<class C2>
  1098. BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_map<Key, T, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
  1099. { return this->merge(static_cast<flat_map<Key, T, C2, AllocatorOrContainer>&>(source)); }
  1100. //! @copydoc ::boost::container::flat_map::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
  1101. template<class C2>
  1102. BOOST_CONTAINER_FORCEINLINE void merge(flat_multimap<Key, T, C2, AllocatorOrContainer>& source)
  1103. { m_flat_tree.merge_unique(source.tree()); }
  1104. //! @copydoc ::boost::container::flat_map::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
  1105. template<class C2>
  1106. BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_multimap<Key, T, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
  1107. { return this->merge(static_cast<flat_multimap<Key, T, C2, AllocatorOrContainer>&>(source)); }
  1108. //! <b>Effects</b>: Erases the element pointed to by p.
  1109. //!
  1110. //! <b>Returns</b>: Returns an iterator pointing to the element immediately
  1111. //! following q prior to the element being erased. If no such element exists,
  1112. //! returns end().
  1113. //!
  1114. //! <b>Complexity</b>: Linear to the elements with keys bigger than p
  1115. //!
  1116. //! <b>Note</b>: Invalidates elements with keys
  1117. //! not less than the erased element.
  1118. BOOST_CONTAINER_FORCEINLINE iterator erase(const_iterator p)
  1119. {
  1120. return dtl::force_copy<iterator>
  1121. (m_flat_tree.erase(dtl::force_copy<impl_const_iterator>(p)));
  1122. }
  1123. //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
  1124. //!
  1125. //! <b>Returns</b>: Returns the number of erased elements.
  1126. //!
  1127. //! <b>Complexity</b>: Logarithmic search time plus erasure time
  1128. //! linear to the elements with bigger keys.
  1129. BOOST_CONTAINER_FORCEINLINE size_type erase(const key_type& x)
  1130. { return m_flat_tree.erase(x); }
  1131. //! <b>Effects</b>: Erases all the elements in the range [first, last).
  1132. //!
  1133. //! <b>Returns</b>: Returns last.
  1134. //!
  1135. //! <b>Complexity</b>: size()*N where N is the distance from first to last.
  1136. //!
  1137. //! <b>Complexity</b>: Logarithmic search time plus erasure time
  1138. //! linear to the elements with bigger keys.
  1139. BOOST_CONTAINER_FORCEINLINE iterator erase(const_iterator first, const_iterator last)
  1140. {
  1141. return dtl::force_copy<iterator>(
  1142. m_flat_tree.erase( dtl::force_copy<impl_const_iterator>(first)
  1143. , dtl::force_copy<impl_const_iterator>(last)));
  1144. }
  1145. //! <b>Effects</b>: Swaps the contents of *this and x.
  1146. //!
  1147. //! <b>Throws</b>: Nothing.
  1148. //!
  1149. //! <b>Complexity</b>: Constant.
  1150. BOOST_CONTAINER_FORCEINLINE void swap(flat_map& x)
  1151. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  1152. && boost::container::dtl::is_nothrow_swappable<Compare>::value )
  1153. { m_flat_tree.swap(x.m_flat_tree); }
  1154. //! <b>Effects</b>: erase(begin(),end()).
  1155. //!
  1156. //! <b>Postcondition</b>: size() == 0.
  1157. //!
  1158. //! <b>Complexity</b>: linear in size().
  1159. BOOST_CONTAINER_FORCEINLINE void clear() BOOST_NOEXCEPT_OR_NOTHROW
  1160. { m_flat_tree.clear(); }
  1161. //////////////////////////////////////////////
  1162. //
  1163. // observers
  1164. //
  1165. //////////////////////////////////////////////
  1166. //! <b>Effects</b>: Returns the comparison object out
  1167. //! of which a was constructed.
  1168. //!
  1169. //! <b>Complexity</b>: Constant.
  1170. BOOST_CONTAINER_FORCEINLINE key_compare key_comp() const
  1171. { return dtl::force_copy<key_compare>(m_flat_tree.key_comp()); }
  1172. //! <b>Effects</b>: Returns an object of value_compare constructed out
  1173. //! of the comparison object.
  1174. //!
  1175. //! <b>Complexity</b>: Constant.
  1176. BOOST_CONTAINER_FORCEINLINE value_compare value_comp() const
  1177. { return value_compare(dtl::force_copy<key_compare>(m_flat_tree.key_comp())); }
  1178. //////////////////////////////////////////////
  1179. //
  1180. // map operations
  1181. //
  1182. //////////////////////////////////////////////
  1183. //! <b>Returns</b>: An iterator pointing to an element with the key
  1184. //! equivalent to x, or end() if such an element is not found.
  1185. //!
  1186. //! <b>Complexity</b>: Logarithmic.
  1187. BOOST_CONTAINER_FORCEINLINE iterator find(const key_type& x)
  1188. { return dtl::force_copy<iterator>(m_flat_tree.find(x)); }
  1189. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  1190. //! equivalent to x, or end() if such an element is not found.
  1191. //!
  1192. //! <b>Complexity</b>: Logarithmic.
  1193. BOOST_CONTAINER_FORCEINLINE const_iterator find(const key_type& x) const
  1194. { return dtl::force_copy<const_iterator>(m_flat_tree.find(x)); }
  1195. //! <b>Requires</b>: This overload is available only if
  1196. //! key_compare::is_transparent exists.
  1197. //!
  1198. //! <b>Returns</b>: An iterator pointing to an element with the key
  1199. //! equivalent to x, or end() if such an element is not found.
  1200. //!
  1201. //! <b>Complexity</b>: Logarithmic.
  1202. template<class K>
  1203. BOOST_CONTAINER_FORCEINLINE iterator find(const K& x)
  1204. { return dtl::force_copy<iterator>(m_flat_tree.find(x)); }
  1205. //! <b>Requires</b>: This overload is available only if
  1206. //! key_compare::is_transparent exists.
  1207. //!
  1208. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  1209. //! equivalent to x, or end() if such an element is not found.
  1210. //!
  1211. //! <b>Complexity</b>: Logarithmic.
  1212. template<class K>
  1213. BOOST_CONTAINER_FORCEINLINE const_iterator find(const K& x) const
  1214. { return dtl::force_copy<const_iterator>(m_flat_tree.find(x)); }
  1215. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1216. //!
  1217. //! <b>Complexity</b>: log(size())+count(k)
  1218. BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const
  1219. { return static_cast<size_type>(m_flat_tree.find(x) != m_flat_tree.end()); }
  1220. //! <b>Requires</b>: This overload is available only if
  1221. //! key_compare::is_transparent exists.
  1222. //!
  1223. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1224. //!
  1225. //! <b>Complexity</b>: log(size())+count(k)
  1226. template<class K>
  1227. BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
  1228. //Don't use find() != end optimization here as transparent comparators with key K might
  1229. //return a different range than key_type (which can only return a single element range)
  1230. { return m_flat_tree.count(x); }
  1231. //! <b>Returns</b>: Returns true if there is an element with key
  1232. //! equivalent to key in the container, otherwise false.
  1233. //!
  1234. //! <b>Complexity</b>: log(size()).
  1235. bool contains(const key_type& x) const
  1236. { return m_flat_tree.find(x) != m_flat_tree.end(); }
  1237. //! <b>Requires</b>: This overload is available only if
  1238. //! key_compare::is_transparent exists.
  1239. //!
  1240. //! <b>Returns</b>: Returns true if there is an element with key
  1241. //! equivalent to key in the container, otherwise false.
  1242. //!
  1243. //! <b>Complexity</b>: log(size()).
  1244. template<typename K>
  1245. bool contains(const K& x) const
  1246. { return m_flat_tree.find(x) != m_flat_tree.end(); }
  1247. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1248. //! than x, or end() if such an element is not found.
  1249. //!
  1250. //! <b>Complexity</b>: Logarithmic.
  1251. BOOST_CONTAINER_FORCEINLINE iterator lower_bound(const key_type& x)
  1252. { return dtl::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
  1253. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1254. //! less than x, or end() if such an element is not found.
  1255. //!
  1256. //! <b>Complexity</b>: Logarithmic.
  1257. BOOST_CONTAINER_FORCEINLINE const_iterator lower_bound(const key_type& x) const
  1258. { return dtl::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
  1259. //! <b>Requires</b>: This overload is available only if
  1260. //! key_compare::is_transparent exists.
  1261. //!
  1262. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1263. //! than x, or end() if such an element is not found.
  1264. //!
  1265. //! <b>Complexity</b>: Logarithmic.
  1266. template<class K>
  1267. BOOST_CONTAINER_FORCEINLINE iterator lower_bound(const K& x)
  1268. { return dtl::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
  1269. //! <b>Requires</b>: This overload is available only if
  1270. //! key_compare::is_transparent exists.
  1271. //!
  1272. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  1273. //! less than x, or end() if such an element is not found.
  1274. //!
  1275. //! <b>Complexity</b>: Logarithmic.
  1276. template<class K>
  1277. BOOST_CONTAINER_FORCEINLINE const_iterator lower_bound(const K& x) const
  1278. { return dtl::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
  1279. //! <b>Returns</b>: An iterator pointing to the first element with key greater
  1280. //! than x, or end() if such an element is not found.
  1281. //!
  1282. //! <b>Complexity</b>: Logarithmic.
  1283. BOOST_CONTAINER_FORCEINLINE iterator upper_bound(const key_type& x)
  1284. { return dtl::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
  1285. //! <b>Returns</b>: A const iterator pointing to the first element with key
  1286. //! greater than x, or end() if such an element is not found.
  1287. //!
  1288. //! <b>Complexity</b>: Logarithmic.
  1289. BOOST_CONTAINER_FORCEINLINE const_iterator upper_bound(const key_type& x) const
  1290. { return dtl::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
  1291. //! <b>Requires</b>: This overload is available only if
  1292. //! key_compare::is_transparent exists.
  1293. //!
  1294. //! <b>Returns</b>: An iterator pointing to the first element with key greater
  1295. //! than x, or end() if such an element is not found.
  1296. //!
  1297. //! <b>Complexity</b>: Logarithmic.
  1298. template<class K>
  1299. BOOST_CONTAINER_FORCEINLINE iterator upper_bound(const K& x)
  1300. { return dtl::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
  1301. //! <b>Requires</b>: This overload is available only if
  1302. //! key_compare::is_transparent exists.
  1303. //!
  1304. //! <b>Returns</b>: A const iterator pointing to the first element with key
  1305. //! greater than x, or end() if such an element is not found.
  1306. //!
  1307. //! <b>Complexity</b>: Logarithmic.
  1308. template<class K>
  1309. BOOST_CONTAINER_FORCEINLINE const_iterator upper_bound(const K& x) const
  1310. { return dtl::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
  1311. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1312. //!
  1313. //! <b>Complexity</b>: Logarithmic.
  1314. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const key_type& x)
  1315. { return dtl::force_copy<std::pair<iterator,iterator> >(m_flat_tree.lower_bound_range(x)); }
  1316. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1317. //!
  1318. //! <b>Complexity</b>: Logarithmic.
  1319. BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const
  1320. { return dtl::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.lower_bound_range(x)); }
  1321. //! <b>Requires</b>: This overload is available only if
  1322. //! key_compare::is_transparent exists.
  1323. //!
  1324. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1325. //!
  1326. //! <b>Complexity</b>: Logarithmic.
  1327. template<class K>
  1328. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const K& x)
  1329. //Don't use lower_bound_range optimization here as transparent comparators with key K might
  1330. //return a different range than key_type (which can only return a single element range)
  1331. { return dtl::force_copy<std::pair<iterator,iterator> >(m_flat_tree.equal_range(x)); }
  1332. //! <b>Requires</b>: This overload is available only if
  1333. //! key_compare::is_transparent exists.
  1334. //!
  1335. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1336. //!
  1337. //! <b>Complexity</b>: Logarithmic.
  1338. template<class K>
  1339. BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const K& x) const
  1340. //Don't use lower_bound_range optimization here as transparent comparators with key K might
  1341. //return a different range than key_type (which can only return a single element range)
  1342. { return dtl::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.equal_range(x)); }
  1343. //! <b>Effects</b>: Extracts the internal sequence container.
  1344. //!
  1345. //! <b>Complexity</b>: Same as the move constructor of sequence_type, usually constant.
  1346. //!
  1347. //! <b>Postcondition</b>: this->empty()
  1348. //!
  1349. //! <b>Throws</b>: If secuence_type's move constructor throws
  1350. BOOST_CONTAINER_FORCEINLINE sequence_type extract_sequence()
  1351. {
  1352. return boost::move(dtl::force<sequence_type>(m_flat_tree.get_sequence_ref()));
  1353. }
  1354. //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
  1355. //! one passed externally using the move assignment. Erases non-unique elements.
  1356. //!
  1357. //! <b>Complexity</b>: Assuming O(1) move assignment, O(NlogN) with N = seq.size()
  1358. //!
  1359. //! <b>Throws</b>: If the comparison or the move constructor throws
  1360. BOOST_CONTAINER_FORCEINLINE void adopt_sequence(BOOST_RV_REF(sequence_type) seq)
  1361. { this->m_flat_tree.adopt_sequence_unique(boost::move(dtl::force<impl_sequence_type>(seq))); }
  1362. //! <b>Requires</b>: seq shall be ordered according to this->compare()
  1363. //! and shall contain unique elements.
  1364. //!
  1365. //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
  1366. //! one passed externally using the move assignment.
  1367. //!
  1368. //! <b>Complexity</b>: Assuming O(1) move assignment, O(1)
  1369. //!
  1370. //! <b>Throws</b>: If the move assignment throws
  1371. BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_unique_range_t, BOOST_RV_REF(sequence_type) seq)
  1372. { this->m_flat_tree.adopt_sequence_unique(ordered_unique_range_t(), boost::move(dtl::force<impl_sequence_type>(seq))); }
  1373. //! <b>Effects</b>: Returns true if x and y are equal
  1374. //!
  1375. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1376. BOOST_CONTAINER_FORCEINLINE friend bool operator==(const flat_map& x, const flat_map& y)
  1377. { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
  1378. //! <b>Effects</b>: Returns true if x and y are unequal
  1379. //!
  1380. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1381. BOOST_CONTAINER_FORCEINLINE friend bool operator!=(const flat_map& x, const flat_map& y)
  1382. { return !(x == y); }
  1383. //! <b>Effects</b>: Returns true if x is less than y
  1384. //!
  1385. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1386. BOOST_CONTAINER_FORCEINLINE friend bool operator<(const flat_map& x, const flat_map& y)
  1387. { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  1388. //! <b>Effects</b>: Returns true if x is greater than y
  1389. //!
  1390. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1391. BOOST_CONTAINER_FORCEINLINE friend bool operator>(const flat_map& x, const flat_map& y)
  1392. { return y < x; }
  1393. //! <b>Effects</b>: Returns true if x is equal or less than y
  1394. //!
  1395. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1396. BOOST_CONTAINER_FORCEINLINE friend bool operator<=(const flat_map& x, const flat_map& y)
  1397. { return !(y < x); }
  1398. //! <b>Effects</b>: Returns true if x is equal or greater than y
  1399. //!
  1400. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1401. BOOST_CONTAINER_FORCEINLINE friend bool operator>=(const flat_map& x, const flat_map& y)
  1402. { return !(x < y); }
  1403. //! <b>Effects</b>: x.swap(y)
  1404. //!
  1405. //! <b>Complexity</b>: Constant.
  1406. BOOST_CONTAINER_FORCEINLINE friend void swap(flat_map& x, flat_map& y)
  1407. { x.swap(y); }
  1408. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1409. private:
  1410. mapped_type &priv_subscript(const key_type& k)
  1411. {
  1412. iterator i = lower_bound(k);
  1413. // i->first is greater than or equivalent to k.
  1414. if (i == end() || key_comp()(k, (*i).first)){
  1415. dtl::value_init<mapped_type> m;
  1416. i = insert(i, impl_value_type(k, ::boost::move(m.m_t)));
  1417. }
  1418. return (*i).second;
  1419. }
  1420. mapped_type &priv_subscript(BOOST_RV_REF(key_type) mk)
  1421. {
  1422. key_type &k = mk;
  1423. iterator i = lower_bound(k);
  1424. // i->first is greater than or equivalent to k.
  1425. if (i == end() || key_comp()(k, (*i).first)){
  1426. dtl::value_init<mapped_type> m;
  1427. i = insert(i, impl_value_type(boost::move(k), ::boost::move(m.m_t)));
  1428. }
  1429. return (*i).second;
  1430. }
  1431. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1432. };
  1433. #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
  1434. template <typename InputIterator>
  1435. flat_map(InputIterator, InputIterator) ->
  1436. flat_map< it_based_non_const_first_type_t<InputIterator>
  1437. , it_based_second_type_t<InputIterator>>;
  1438. template < typename InputIterator, typename AllocatorOrCompare>
  1439. flat_map(InputIterator, InputIterator, AllocatorOrCompare const&) ->
  1440. flat_map< it_based_non_const_first_type_t<InputIterator>
  1441. , it_based_second_type_t<InputIterator>
  1442. , typename dtl::if_c< // Compare
  1443. dtl::is_allocator<AllocatorOrCompare>::value
  1444. , std::less<it_based_non_const_first_type_t<InputIterator>>
  1445. , AllocatorOrCompare
  1446. >::type
  1447. , typename dtl::if_c< // Allocator
  1448. dtl::is_allocator<AllocatorOrCompare>::value
  1449. , AllocatorOrCompare
  1450. , new_allocator<std::pair<it_based_non_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
  1451. >::type
  1452. >;
  1453. template < typename InputIterator, typename Compare, typename Allocator
  1454. , typename = dtl::require_nonallocator_t<Compare>
  1455. , typename = dtl::require_allocator_t<Allocator>>
  1456. flat_map(InputIterator, InputIterator, Compare const&, Allocator const&) ->
  1457. flat_map< it_based_non_const_first_type_t<InputIterator>
  1458. , it_based_second_type_t<InputIterator>
  1459. , Compare
  1460. , Allocator>;
  1461. template <typename InputIterator>
  1462. flat_map(ordered_unique_range_t, InputIterator, InputIterator) ->
  1463. flat_map< it_based_non_const_first_type_t<InputIterator>
  1464. , it_based_second_type_t<InputIterator>>;
  1465. template < typename InputIterator, typename AllocatorOrCompare>
  1466. flat_map(ordered_unique_range_t, InputIterator, InputIterator, AllocatorOrCompare const&) ->
  1467. flat_map< it_based_non_const_first_type_t<InputIterator>
  1468. , it_based_second_type_t<InputIterator>
  1469. , typename dtl::if_c< // Compare
  1470. dtl::is_allocator<AllocatorOrCompare>::value
  1471. , std::less<it_based_non_const_first_type_t<InputIterator>>
  1472. , AllocatorOrCompare
  1473. >::type
  1474. , typename dtl::if_c< // Allocator
  1475. dtl::is_allocator<AllocatorOrCompare>::value
  1476. , AllocatorOrCompare
  1477. , new_allocator<std::pair<it_based_non_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
  1478. >::type
  1479. >;
  1480. template < typename InputIterator, typename Compare, typename Allocator
  1481. , typename = dtl::require_nonallocator_t<Compare>
  1482. , typename = dtl::require_allocator_t<Allocator>>
  1483. flat_map(ordered_unique_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
  1484. flat_map< it_based_non_const_first_type_t<InputIterator>
  1485. , it_based_second_type_t<InputIterator>
  1486. , Compare
  1487. , Allocator>;
  1488. #endif
  1489. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1490. } //namespace container {
  1491. //!has_trivial_destructor_after_move<> == true_type
  1492. //!specialization for optimizations
  1493. template <class Key, class T, class Compare, class AllocatorOrContainer>
  1494. struct has_trivial_destructor_after_move<boost::container::flat_map<Key, T, Compare, AllocatorOrContainer> >
  1495. {
  1496. typedef ::boost::container::dtl::pair<Key, T> value_t;
  1497. typedef typename ::boost::container::dtl::container_or_allocator_rebind<AllocatorOrContainer, value_t>::type alloc_or_cont_t;
  1498. typedef ::boost::container::dtl::flat_tree<value_t,::boost::container::dtl::select1st<Key>, Compare, alloc_or_cont_t> tree;
  1499. static const bool value = ::boost::has_trivial_destructor_after_move<tree>::value;
  1500. };
  1501. namespace container {
  1502. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1503. //! A flat_multimap is a kind of associative container that supports equivalent keys
  1504. //! (possibly containing multiple copies of the same key value) and provides for
  1505. //! fast retrieval of values of another type T based on the keys.
  1506. //!
  1507. //! A flat_multimap satisfies all of the requirements of a container and of a reversible
  1508. //! container and of an associative container. For a
  1509. //! flat_multimap<Key,T> the key_type is Key and the value_type is std::pair<Key,T>
  1510. //! (unlike std::multimap<Key, T> which value_type is std::pair<<b>const</b> Key, T>).
  1511. //!
  1512. //! flat_multimap is similar to std::multimap but it's implemented by as an ordered sequence container.
  1513. //! The underlying sequence container is by default <i>vector</i> but it can also work
  1514. //! user-provided vector-like SequenceContainers (like <i>static_vector</i> or <i>small_vector</i>).
  1515. //!
  1516. //! Using vector-like sequence containers means that inserting a new element into a flat_multimap might invalidate
  1517. //! previous iterators and references (unless that sequence container is <i>stable_vector</i> or a similar
  1518. //! container that offers stable pointers and references). Similarly, erasing an element might invalidate
  1519. //! iterators and references pointing to elements that come after (their keys are bigger) the erased element.
  1520. //!
  1521. //! This container provides random-access iterators.
  1522. //!
  1523. //! \tparam Key is the key_type of the map
  1524. //! \tparam Value is the <code>mapped_type</code>
  1525. //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
  1526. //! \tparam AllocatorOrContainer is either:
  1527. //! - The allocator to allocate <code>value_type</code>s (e.g. <i>allocator< std::pair<Key, T> > </i>).
  1528. //! (in this case <i>sequence_type</i> will be vector<value_type, AllocatorOrContainer>)
  1529. //! - The SequenceContainer to be used as the underlying <i>sequence_type</i>. It must be a vector-like
  1530. //! sequence container with random-access iterators.
  1531. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  1532. template <class Key, class T, class Compare = std::less<Key>, class AllocatorOrContainer = new_allocator< std::pair< Key, T> > >
  1533. #else
  1534. template <class Key, class T, class Compare, class AllocatorOrContainer>
  1535. #endif
  1536. class flat_multimap
  1537. {
  1538. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1539. private:
  1540. BOOST_COPYABLE_AND_MOVABLE(flat_multimap)
  1541. typedef dtl::flat_tree<
  1542. std::pair<Key, T>,
  1543. dtl::select1st<Key>,
  1544. Compare,
  1545. AllocatorOrContainer> tree_t;
  1546. //This is the real tree stored here. It's based on a movable pair
  1547. typedef dtl::flat_tree<
  1548. dtl::pair<Key, T>,
  1549. dtl::select1st<Key>,
  1550. Compare,
  1551. typename dtl::container_or_allocator_rebind<AllocatorOrContainer, dtl::pair<Key, T> >::type
  1552. > impl_tree_t;
  1553. impl_tree_t m_flat_tree; // flat tree representing flat_map
  1554. typedef typename impl_tree_t::value_type impl_value_type;
  1555. typedef typename impl_tree_t::const_iterator impl_const_iterator;
  1556. typedef typename impl_tree_t::iterator impl_iterator;
  1557. typedef typename impl_tree_t::allocator_type impl_allocator_type;
  1558. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1559. typedef std::initializer_list<impl_value_type> impl_initializer_list;
  1560. #endif
  1561. typedef dtl::flat_tree_value_compare
  1562. < Compare
  1563. , dtl::select1st<Key>
  1564. , std::pair<Key, T> > value_compare_t;
  1565. typedef typename tree_t::iterator iterator_t;
  1566. typedef typename tree_t::const_iterator const_iterator_t;
  1567. typedef typename tree_t::reverse_iterator reverse_iterator_t;
  1568. typedef typename tree_t::const_reverse_iterator const_reverse_iterator_t;
  1569. public:
  1570. typedef typename impl_tree_t::stored_allocator_type impl_stored_allocator_type;
  1571. typedef typename impl_tree_t::sequence_type impl_sequence_type;
  1572. BOOST_CONTAINER_FORCEINLINE impl_tree_t &tree()
  1573. { return m_flat_tree; }
  1574. BOOST_CONTAINER_FORCEINLINE const impl_tree_t &tree() const
  1575. { return m_flat_tree; }
  1576. private:
  1577. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1578. public:
  1579. //////////////////////////////////////////////
  1580. //
  1581. // types
  1582. //
  1583. //////////////////////////////////////////////
  1584. typedef Key key_type;
  1585. typedef T mapped_type;
  1586. typedef Compare key_compare;
  1587. typedef std::pair<Key, T> value_type;
  1588. typedef typename BOOST_CONTAINER_IMPDEF(tree_t::sequence_type) sequence_type;
  1589. typedef typename sequence_type::allocator_type allocator_type;
  1590. typedef ::boost::container::allocator_traits<allocator_type> allocator_traits_type;
  1591. typedef typename sequence_type::pointer pointer;
  1592. typedef typename sequence_type::const_pointer const_pointer;
  1593. typedef typename sequence_type::reference reference;
  1594. typedef typename sequence_type::const_reference const_reference;
  1595. typedef typename sequence_type::size_type size_type;
  1596. typedef typename sequence_type::difference_type difference_type;
  1597. typedef typename BOOST_CONTAINER_IMPDEF(tree_t::stored_allocator_type) stored_allocator_type;
  1598. typedef typename BOOST_CONTAINER_IMPDEF(tree_t::value_compare) value_compare;
  1599. typedef typename sequence_type::iterator iterator;
  1600. typedef typename sequence_type::const_iterator const_iterator;
  1601. typedef typename sequence_type::reverse_iterator reverse_iterator;
  1602. typedef typename sequence_type::const_reverse_iterator const_reverse_iterator;
  1603. typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type;
  1604. //AllocatorOrContainer::value_type must be std::pair<Key, T>
  1605. BOOST_STATIC_ASSERT((dtl::is_same<std::pair<Key, T>, value_type>::value));
  1606. //////////////////////////////////////////////
  1607. //
  1608. // construct/copy/destroy
  1609. //
  1610. //////////////////////////////////////////////
  1611. //! <b>Effects</b>: Default constructs an empty flat_map.
  1612. //!
  1613. //! <b>Complexity</b>: Constant.
  1614. BOOST_CONTAINER_FORCEINLINE flat_multimap()
  1615. BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<AllocatorOrContainer>::value &&
  1616. dtl::is_nothrow_default_constructible<Compare>::value)
  1617. : m_flat_tree()
  1618. {}
  1619. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified allocator.
  1620. //!
  1621. //! <b>Complexity</b>: Constant.
  1622. BOOST_CONTAINER_FORCEINLINE explicit flat_multimap(const allocator_type& a)
  1623. : m_flat_tree(dtl::force<const impl_allocator_type>(a))
  1624. {}
  1625. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison
  1626. //! object .
  1627. //!
  1628. //! <b>Complexity</b>: Constant.
  1629. BOOST_CONTAINER_FORCEINLINE explicit flat_multimap(const Compare& comp)
  1630. : m_flat_tree(comp)
  1631. {}
  1632. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison
  1633. //! object and allocator.
  1634. //!
  1635. //! <b>Complexity</b>: Constant.
  1636. BOOST_CONTAINER_FORCEINLINE
  1637. flat_multimap(const Compare& comp, const allocator_type& a)
  1638. : m_flat_tree(comp, dtl::force<const impl_allocator_type>(a))
  1639. {}
  1640. //! <b>Effects</b>: Constructs an empty flat_multimap
  1641. //! and inserts elements from the range [first ,last ).
  1642. //!
  1643. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1644. //! the predicate and otherwise N logN, where N is last - first.
  1645. template <class InputIterator>
  1646. BOOST_CONTAINER_FORCEINLINE
  1647. flat_multimap(InputIterator first, InputIterator last)
  1648. : m_flat_tree(false, first, last)
  1649. {}
  1650. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified
  1651. //! allocator, and inserts elements from the range [first ,last ).
  1652. //!
  1653. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1654. //! the predicate and otherwise N logN, where N is last - first.
  1655. template <class InputIterator>
  1656. BOOST_CONTAINER_FORCEINLINE
  1657. flat_multimap(InputIterator first, InputIterator last, const allocator_type& a)
  1658. : m_flat_tree(false, first, last, dtl::force<const impl_allocator_type>(a))
  1659. {}
  1660. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object
  1661. //! and inserts elements from the range [first ,last ).
  1662. //!
  1663. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1664. //! the predicate and otherwise N logN, where N is last - first.
  1665. template <class InputIterator>
  1666. BOOST_CONTAINER_FORCEINLINE
  1667. flat_multimap(InputIterator first, InputIterator last, const Compare& comp)
  1668. : m_flat_tree(false, first, last, comp)
  1669. {}
  1670. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object
  1671. //! and allocator, and inserts elements from the range [first ,last ).
  1672. //!
  1673. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1674. //! the predicate and otherwise N logN, where N is last - first.
  1675. template <class InputIterator>
  1676. BOOST_CONTAINER_FORCEINLINE
  1677. flat_multimap(InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
  1678. : m_flat_tree(false, first, last, comp, dtl::force<const impl_allocator_type>(a))
  1679. {}
  1680. //! <b>Effects</b>: Constructs an empty flat_multimap
  1681. //! and inserts elements from the ordered range [first ,last). This function
  1682. //! is more efficient than the normal range creation for ordered ranges.
  1683. //!
  1684. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1685. //!
  1686. //! <b>Complexity</b>: Linear in N.
  1687. //!
  1688. //! <b>Note</b>: Non-standard extension.
  1689. template <class InputIterator>
  1690. BOOST_CONTAINER_FORCEINLINE
  1691. flat_multimap(ordered_range_t, InputIterator first, InputIterator last)
  1692. : m_flat_tree(ordered_range, first, last)
  1693. {}
  1694. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
  1695. //! inserts elements from the ordered range [first ,last). This function
  1696. //! is more efficient than the normal range creation for ordered ranges.
  1697. //!
  1698. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1699. //!
  1700. //! <b>Complexity</b>: Linear in N.
  1701. //!
  1702. //! <b>Note</b>: Non-standard extension.
  1703. template <class InputIterator>
  1704. BOOST_CONTAINER_FORCEINLINE
  1705. flat_multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp)
  1706. : m_flat_tree(ordered_range, first, last, comp)
  1707. {}
  1708. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
  1709. //! allocator, and inserts elements from the ordered range [first ,last). This function
  1710. //! is more efficient than the normal range creation for ordered ranges.
  1711. //!
  1712. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1713. //!
  1714. //! <b>Complexity</b>: Linear in N.
  1715. //!
  1716. //! <b>Note</b>: Non-standard extension.
  1717. template <class InputIterator>
  1718. BOOST_CONTAINER_FORCEINLINE
  1719. flat_multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
  1720. : m_flat_tree(ordered_range, first, last, comp, a)
  1721. {}
  1722. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
  1723. //! inserts elements from the ordered range [first ,last). This function
  1724. //! is more efficient than the normal range creation for ordered ranges.
  1725. //!
  1726. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1727. //!
  1728. //! <b>Complexity</b>: Linear in N.
  1729. //!
  1730. //! <b>Note</b>: Non-standard extension.
  1731. template <class InputIterator>
  1732. BOOST_CONTAINER_FORCEINLINE
  1733. flat_multimap(ordered_range_t, InputIterator first, InputIterator last, const allocator_type &a)
  1734. : m_flat_tree(ordered_range, first, last, Compare(), a)
  1735. {}
  1736. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1737. //! <b>Effects</b>: Constructs an empty flat_map and
  1738. //! inserts elements from the range [il.begin(), il.end()).
  1739. //!
  1740. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  1741. //! the predicate and otherwise N logN, where N is last - first.
  1742. BOOST_CONTAINER_FORCEINLINE
  1743. flat_multimap(std::initializer_list<value_type> il)
  1744. : m_flat_tree( false
  1745. , dtl::force<impl_initializer_list>(il).begin()
  1746. , dtl::force<impl_initializer_list>(il).end())
  1747. {}
  1748. //! <b>Effects</b>: Constructs an empty flat_map using the specified
  1749. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  1750. //!
  1751. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  1752. //! the predicate and otherwise N logN, where N is last - first.
  1753. BOOST_CONTAINER_FORCEINLINE
  1754. flat_multimap(std::initializer_list<value_type> il, const allocator_type& a)
  1755. : m_flat_tree(false
  1756. , dtl::force<impl_initializer_list>(il).begin()
  1757. , dtl::force<impl_initializer_list>(il).end()
  1758. , dtl::force<const impl_allocator_type>(a))
  1759. {}
  1760. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  1761. //! inserts elements from the range [il.begin(), il.end()).
  1762. //!
  1763. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  1764. //! the predicate and otherwise N logN, where N is last - first.
  1765. BOOST_CONTAINER_FORCEINLINE
  1766. flat_multimap(std::initializer_list<value_type> il, const Compare& comp)
  1767. : m_flat_tree(false
  1768. , dtl::force<impl_initializer_list>(il).begin()
  1769. , dtl::force<impl_initializer_list>(il).end(), comp)
  1770. {}
  1771. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  1772. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  1773. //!
  1774. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  1775. //! the predicate and otherwise N logN, where N is last - first.
  1776. BOOST_CONTAINER_FORCEINLINE
  1777. flat_multimap(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
  1778. : m_flat_tree( false
  1779. , dtl::force<impl_initializer_list>(il).begin()
  1780. , dtl::force<impl_initializer_list>(il).end()
  1781. , comp, dtl::force<const impl_allocator_type>(a))
  1782. {}
  1783. //! <b>Effects</b>: Constructs an empty flat_multimap and
  1784. //! inserts elements from the ordered range [il.begin(), il.end()). This function
  1785. //! is more efficient than the normal range creation for ordered ranges.
  1786. //!
  1787. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1788. //!
  1789. //! <b>Complexity</b>: Linear in N.
  1790. //!
  1791. //! <b>Note</b>: Non-standard extension.
  1792. BOOST_CONTAINER_FORCEINLINE
  1793. flat_multimap(ordered_range_t, std::initializer_list<value_type> il)
  1794. : m_flat_tree( ordered_range
  1795. , dtl::force<impl_initializer_list>(il).begin()
  1796. , dtl::force<impl_initializer_list>(il).end())
  1797. {}
  1798. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
  1799. //! inserts elements from the ordered range [il.begin(), il.end()). This function
  1800. //! is more efficient than the normal range creation for ordered ranges.
  1801. //!
  1802. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1803. //!
  1804. //! <b>Complexity</b>: Linear in N.
  1805. //!
  1806. //! <b>Note</b>: Non-standard extension.
  1807. BOOST_CONTAINER_FORCEINLINE
  1808. flat_multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp)
  1809. : m_flat_tree( ordered_range
  1810. , dtl::force<impl_initializer_list>(il).begin()
  1811. , dtl::force<impl_initializer_list>(il).end(), comp)
  1812. {}
  1813. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
  1814. //! allocator, and inserts elements from the ordered range [il.begin(), il.end()). This function
  1815. //! is more efficient than the normal range creation for ordered ranges.
  1816. //!
  1817. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1818. //!
  1819. //! <b>Complexity</b>: Linear in N.
  1820. //!
  1821. //! <b>Note</b>: Non-standard extension.
  1822. BOOST_CONTAINER_FORCEINLINE
  1823. flat_multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
  1824. : m_flat_tree( ordered_range
  1825. , dtl::force<impl_initializer_list>(il).begin()
  1826. , dtl::force<impl_initializer_list>(il).end()
  1827. , comp, dtl::force<const impl_allocator_type>(a))
  1828. {}
  1829. #endif
  1830. //! <b>Effects</b>: Copy constructs a flat_multimap.
  1831. //!
  1832. //! <b>Complexity</b>: Linear in x.size().
  1833. BOOST_CONTAINER_FORCEINLINE
  1834. flat_multimap(const flat_multimap& x)
  1835. : m_flat_tree(x.m_flat_tree)
  1836. {}
  1837. //! <b>Effects</b>: Move constructs a flat_multimap. Constructs *this using x's resources.
  1838. //!
  1839. //! <b>Complexity</b>: Constant.
  1840. //!
  1841. //! <b>Postcondition</b>: x is emptied.
  1842. BOOST_CONTAINER_FORCEINLINE
  1843. flat_multimap(BOOST_RV_REF(flat_multimap) x)
  1844. BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
  1845. : m_flat_tree(boost::move(x.m_flat_tree))
  1846. {}
  1847. //! <b>Effects</b>: Copy constructs a flat_multimap using the specified allocator.
  1848. //!
  1849. //! <b>Complexity</b>: Linear in x.size().
  1850. BOOST_CONTAINER_FORCEINLINE
  1851. flat_multimap(const flat_multimap& x, const allocator_type &a)
  1852. : m_flat_tree(x.m_flat_tree, dtl::force<const impl_allocator_type>(a))
  1853. {}
  1854. //! <b>Effects</b>: Move constructs a flat_multimap using the specified allocator.
  1855. //! Constructs *this using x's resources.
  1856. //!
  1857. //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
  1858. BOOST_CONTAINER_FORCEINLINE
  1859. flat_multimap(BOOST_RV_REF(flat_multimap) x, const allocator_type &a)
  1860. : m_flat_tree(boost::move(x.m_flat_tree), dtl::force<const impl_allocator_type>(a))
  1861. {}
  1862. //! <b>Effects</b>: Makes *this a copy of x.
  1863. //!
  1864. //! <b>Complexity</b>: Linear in x.size().
  1865. BOOST_CONTAINER_FORCEINLINE
  1866. flat_multimap& operator=(BOOST_COPY_ASSIGN_REF(flat_multimap) x)
  1867. { m_flat_tree = x.m_flat_tree; return *this; }
  1868. //! <b>Effects</b>: this->swap(x.get()).
  1869. //!
  1870. //! <b>Complexity</b>: Constant.
  1871. BOOST_CONTAINER_FORCEINLINE
  1872. flat_multimap& operator=(BOOST_RV_REF(flat_multimap) x)
  1873. BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
  1874. allocator_traits_type::is_always_equal::value) &&
  1875. boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
  1876. { m_flat_tree = boost::move(x.m_flat_tree); return *this; }
  1877. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1878. //! <b>Effects</b>: Assign content of il to *this
  1879. //!
  1880. //! <b>Complexity</b>: Linear in il.size().
  1881. BOOST_CONTAINER_FORCEINLINE
  1882. flat_multimap& operator=(std::initializer_list<value_type> il)
  1883. {
  1884. this->clear();
  1885. this->insert(il.begin(), il.end());
  1886. return *this;
  1887. }
  1888. #endif
  1889. //! <b>Effects</b>: Returns a copy of the allocator that
  1890. //! was passed to the object's constructor.
  1891. //!
  1892. //! <b>Complexity</b>: Constant.
  1893. BOOST_CONTAINER_FORCEINLINE
  1894. allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  1895. { return dtl::force_copy<allocator_type>(m_flat_tree.get_allocator()); }
  1896. //! <b>Effects</b>: Returns a reference to the internal allocator.
  1897. //!
  1898. //! <b>Throws</b>: Nothing
  1899. //!
  1900. //! <b>Complexity</b>: Constant.
  1901. //!
  1902. //! <b>Note</b>: Non-standard extension.
  1903. BOOST_CONTAINER_FORCEINLINE
  1904. stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
  1905. { return dtl::force<stored_allocator_type>(m_flat_tree.get_stored_allocator()); }
  1906. //! <b>Effects</b>: Returns a reference to the internal allocator.
  1907. //!
  1908. //! <b>Throws</b>: Nothing
  1909. //!
  1910. //! <b>Complexity</b>: Constant.
  1911. //!
  1912. //! <b>Note</b>: Non-standard extension.
  1913. BOOST_CONTAINER_FORCEINLINE
  1914. const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  1915. { return dtl::force<const stored_allocator_type>(m_flat_tree.get_stored_allocator()); }
  1916. //////////////////////////////////////////////
  1917. //
  1918. // iterators
  1919. //
  1920. //////////////////////////////////////////////
  1921. //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
  1922. //!
  1923. //! <b>Throws</b>: Nothing.
  1924. //!
  1925. //! <b>Complexity</b>: Constant.
  1926. BOOST_CONTAINER_FORCEINLINE
  1927. iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
  1928. { return dtl::force_copy<iterator>(m_flat_tree.begin()); }
  1929. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  1930. //!
  1931. //! <b>Throws</b>: Nothing.
  1932. //!
  1933. //! <b>Complexity</b>: Constant.
  1934. BOOST_CONTAINER_FORCEINLINE
  1935. const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
  1936. { return dtl::force_copy<const_iterator>(m_flat_tree.begin()); }
  1937. //! <b>Effects</b>: Returns an iterator to the end of the container.
  1938. //!
  1939. //! <b>Throws</b>: Nothing.
  1940. //!
  1941. //! <b>Complexity</b>: Constant.
  1942. BOOST_CONTAINER_FORCEINLINE
  1943. iterator end() BOOST_NOEXCEPT_OR_NOTHROW
  1944. { return dtl::force_copy<iterator>(m_flat_tree.end()); }
  1945. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  1946. //!
  1947. //! <b>Throws</b>: Nothing.
  1948. //!
  1949. //! <b>Complexity</b>: Constant.
  1950. BOOST_CONTAINER_FORCEINLINE
  1951. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
  1952. { return dtl::force_copy<const_iterator>(m_flat_tree.end()); }
  1953. //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
  1954. //! of the reversed container.
  1955. //!
  1956. //! <b>Throws</b>: Nothing.
  1957. //!
  1958. //! <b>Complexity</b>: Constant.
  1959. BOOST_CONTAINER_FORCEINLINE
  1960. reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
  1961. { return dtl::force_copy<reverse_iterator>(m_flat_tree.rbegin()); }
  1962. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  1963. //! of the reversed container.
  1964. //!
  1965. //! <b>Throws</b>: Nothing.
  1966. //!
  1967. //! <b>Complexity</b>: Constant.
  1968. BOOST_CONTAINER_FORCEINLINE
  1969. const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  1970. { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.rbegin()); }
  1971. //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
  1972. //! of the reversed container.
  1973. //!
  1974. //! <b>Throws</b>: Nothing.
  1975. //!
  1976. //! <b>Complexity</b>: Constant.
  1977. BOOST_CONTAINER_FORCEINLINE
  1978. reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
  1979. { return dtl::force_copy<reverse_iterator>(m_flat_tree.rend()); }
  1980. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  1981. //! of the reversed container.
  1982. //!
  1983. //! <b>Throws</b>: Nothing.
  1984. //!
  1985. //! <b>Complexity</b>: Constant.
  1986. BOOST_CONTAINER_FORCEINLINE
  1987. const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
  1988. { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.rend()); }
  1989. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  1990. //!
  1991. //! <b>Throws</b>: Nothing.
  1992. //!
  1993. //! <b>Complexity</b>: Constant.
  1994. BOOST_CONTAINER_FORCEINLINE
  1995. const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  1996. { return dtl::force_copy<const_iterator>(m_flat_tree.cbegin()); }
  1997. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  1998. //!
  1999. //! <b>Throws</b>: Nothing.
  2000. //!
  2001. //! <b>Complexity</b>: Constant.
  2002. BOOST_CONTAINER_FORCEINLINE
  2003. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
  2004. { return dtl::force_copy<const_iterator>(m_flat_tree.cend()); }
  2005. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  2006. //! of the reversed container.
  2007. //!
  2008. //! <b>Throws</b>: Nothing.
  2009. //!
  2010. //! <b>Complexity</b>: Constant.
  2011. BOOST_CONTAINER_FORCEINLINE
  2012. const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  2013. { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.crbegin()); }
  2014. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  2015. //! of the reversed container.
  2016. //!
  2017. //! <b>Throws</b>: Nothing.
  2018. //!
  2019. //! <b>Complexity</b>: Constant.
  2020. BOOST_CONTAINER_FORCEINLINE
  2021. const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
  2022. { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.crend()); }
  2023. //////////////////////////////////////////////
  2024. //
  2025. // capacity
  2026. //
  2027. //////////////////////////////////////////////
  2028. //! <b>Effects</b>: Returns true if the container contains no elements.
  2029. //!
  2030. //! <b>Throws</b>: Nothing.
  2031. //!
  2032. //! <b>Complexity</b>: Constant.
  2033. BOOST_CONTAINER_FORCEINLINE
  2034. bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
  2035. { return m_flat_tree.empty(); }
  2036. //! <b>Effects</b>: Returns the number of the elements contained in the container.
  2037. //!
  2038. //! <b>Throws</b>: Nothing.
  2039. //!
  2040. //! <b>Complexity</b>: Constant.
  2041. BOOST_CONTAINER_FORCEINLINE
  2042. size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
  2043. { return m_flat_tree.size(); }
  2044. //! <b>Effects</b>: Returns the largest possible size of the container.
  2045. //!
  2046. //! <b>Throws</b>: Nothing.
  2047. //!
  2048. //! <b>Complexity</b>: Constant.
  2049. BOOST_CONTAINER_FORCEINLINE
  2050. size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
  2051. { return m_flat_tree.max_size(); }
  2052. //! <b>Effects</b>: Number of elements for which memory has been allocated.
  2053. //! capacity() is always greater than or equal to size().
  2054. //!
  2055. //! <b>Throws</b>: Nothing.
  2056. //!
  2057. //! <b>Complexity</b>: Constant.
  2058. BOOST_CONTAINER_FORCEINLINE
  2059. size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW
  2060. { return m_flat_tree.capacity(); }
  2061. //! <b>Effects</b>: If n is less than or equal to capacity(), or the
  2062. //! underlying container has no `reserve` member, this call has no
  2063. //! effect. Otherwise, it is a request for allocation of additional memory.
  2064. //! If the request is successful, then capacity() is greater than or equal to
  2065. //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
  2066. //!
  2067. //! <b>Throws</b>: If memory allocation allocation throws or T's copy constructor throws.
  2068. //!
  2069. //! <b>Note</b>: If capacity() is less than "cnt", iterators and references to
  2070. //! to values might be invalidated.
  2071. BOOST_CONTAINER_FORCEINLINE
  2072. void reserve(size_type cnt)
  2073. { m_flat_tree.reserve(cnt); }
  2074. //! <b>Effects</b>: Tries to deallocate the excess of memory created
  2075. // with previous allocations. The size of the vector is unchanged
  2076. //!
  2077. //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
  2078. //!
  2079. //! <b>Complexity</b>: Linear to size().
  2080. BOOST_CONTAINER_FORCEINLINE
  2081. void shrink_to_fit()
  2082. { m_flat_tree.shrink_to_fit(); }
  2083. //! @copydoc ::boost::container::flat_set::nth(size_type)
  2084. BOOST_CONTAINER_FORCEINLINE
  2085. iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
  2086. { return dtl::force_copy<iterator>(m_flat_tree.nth(n)); }
  2087. //! @copydoc ::boost::container::flat_set::nth(size_type) const
  2088. BOOST_CONTAINER_FORCEINLINE
  2089. const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
  2090. { return dtl::force_copy<iterator>(m_flat_tree.nth(n)); }
  2091. //! @copydoc ::boost::container::flat_set::index_of(iterator)
  2092. BOOST_CONTAINER_FORCEINLINE
  2093. size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
  2094. { return m_flat_tree.index_of(dtl::force_copy<impl_iterator>(p)); }
  2095. //! @copydoc ::boost::container::flat_set::index_of(const_iterator) const
  2096. BOOST_CONTAINER_FORCEINLINE
  2097. size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
  2098. { return m_flat_tree.index_of(dtl::force_copy<impl_const_iterator>(p)); }
  2099. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  2100. //! <b>Effects</b>: Inserts an object of type T constructed with
  2101. //! std::forward<Args>(args)... and returns the iterator pointing to the
  2102. //! newly inserted element.
  2103. //!
  2104. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  2105. //! to the elements with bigger keys than x.
  2106. //!
  2107. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2108. template <class... Args>
  2109. BOOST_CONTAINER_FORCEINLINE
  2110. iterator emplace(BOOST_FWD_REF(Args)... args)
  2111. { return dtl::force_copy<iterator>(m_flat_tree.emplace_equal(boost::forward<Args>(args)...)); }
  2112. //! <b>Effects</b>: Inserts an object of type T constructed with
  2113. //! std::forward<Args>(args)... in the container.
  2114. //! p is a hint pointing to where the insert should start to search.
  2115. //!
  2116. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  2117. //! to the key of x.
  2118. //!
  2119. //! <b>Complexity</b>: Logarithmic search time (constant time if the value
  2120. //! is to be inserted before p) plus linear insertion
  2121. //! to the elements with bigger keys than x.
  2122. //!
  2123. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2124. template <class... Args>
  2125. BOOST_CONTAINER_FORCEINLINE
  2126. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
  2127. {
  2128. return dtl::force_copy<iterator>(m_flat_tree.emplace_hint_equal
  2129. (dtl::force_copy<impl_const_iterator>(hint), boost::forward<Args>(args)...));
  2130. }
  2131. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  2132. #define BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE(N) \
  2133. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  2134. BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_MOVE_UREF##N)\
  2135. { return dtl::force_copy<iterator>(m_flat_tree.emplace_equal(BOOST_MOVE_FWD##N)); }\
  2136. \
  2137. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  2138. BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  2139. {\
  2140. return dtl::force_copy<iterator>(m_flat_tree.emplace_hint_equal\
  2141. (dtl::force_copy<impl_const_iterator>(hint) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
  2142. }\
  2143. //
  2144. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE)
  2145. #undef BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE
  2146. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  2147. //! <b>Effects</b>: Inserts x and returns the iterator pointing to the
  2148. //! newly inserted element.
  2149. //!
  2150. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  2151. //! to the elements with bigger keys than x.
  2152. //!
  2153. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2154. BOOST_CONTAINER_FORCEINLINE iterator insert(const value_type& x)
  2155. {
  2156. return dtl::force_copy<iterator>(
  2157. m_flat_tree.insert_equal(dtl::force<const impl_value_type>(x)));
  2158. }
  2159. //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
  2160. //! the iterator pointing to the newly inserted element.
  2161. //!
  2162. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  2163. //! to the elements with bigger keys than x.
  2164. //!
  2165. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2166. BOOST_CONTAINER_FORCEINLINE iterator insert(BOOST_RV_REF(value_type) x)
  2167. { return dtl::force_copy<iterator>(m_flat_tree.insert_equal(boost::move(x))); }
  2168. //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
  2169. //! the iterator pointing to the newly inserted element.
  2170. //!
  2171. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  2172. //! to the elements with bigger keys than x.
  2173. //!
  2174. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2175. BOOST_CONTAINER_FORCEINLINE iterator insert(BOOST_RV_REF(impl_value_type) x)
  2176. { return dtl::force_copy<iterator>(m_flat_tree.insert_equal(boost::move(x))); }
  2177. //! <b>Effects</b>: Inserts a copy of x in the container.
  2178. //! p is a hint pointing to where the insert should start to search.
  2179. //!
  2180. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  2181. //! to the key of x.
  2182. //!
  2183. //! <b>Complexity</b>: Logarithmic search time (constant time if the value
  2184. //! is to be inserted before p) plus linear insertion
  2185. //! to the elements with bigger keys than x.
  2186. //!
  2187. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2188. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
  2189. {
  2190. return dtl::force_copy<iterator>
  2191. (m_flat_tree.insert_equal( dtl::force_copy<impl_const_iterator>(p)
  2192. , dtl::force<const impl_value_type>(x)));
  2193. }
  2194. //! <b>Effects</b>: Inserts a value move constructed from x in the container.
  2195. //! p is a hint pointing to where the insert should start to search.
  2196. //!
  2197. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  2198. //! to the key of x.
  2199. //!
  2200. //! <b>Complexity</b>: Logarithmic search time (constant time if the value
  2201. //! is to be inserted before p) plus linear insertion
  2202. //! to the elements with bigger keys than x.
  2203. //!
  2204. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2205. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
  2206. {
  2207. return dtl::force_copy<iterator>
  2208. (m_flat_tree.insert_equal(dtl::force_copy<impl_const_iterator>(p)
  2209. , boost::move(x)));
  2210. }
  2211. //! <b>Effects</b>: Inserts a value move constructed from x in the container.
  2212. //! p is a hint pointing to where the insert should start to search.
  2213. //!
  2214. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  2215. //! to the key of x.
  2216. //!
  2217. //! <b>Complexity</b>: Logarithmic search time (constant time if the value
  2218. //! is to be inserted before p) plus linear insertion
  2219. //! to the elements with bigger keys than x.
  2220. //!
  2221. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2222. BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(impl_value_type) x)
  2223. {
  2224. return dtl::force_copy<iterator>(
  2225. m_flat_tree.insert_equal(dtl::force_copy<impl_const_iterator>(p), boost::move(x)));
  2226. }
  2227. //! <b>Requires</b>: first, last are not iterators into *this.
  2228. //!
  2229. //! <b>Effects</b>: inserts each element from the range [first,last) .
  2230. //!
  2231. //! <b>Complexity</b>: N log(N).
  2232. //!
  2233. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2234. template <class InputIterator>
  2235. BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
  2236. { m_flat_tree.insert_equal(first, last); }
  2237. //! <b>Requires</b>: first, last are not iterators into *this.
  2238. //!
  2239. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  2240. //!
  2241. //! <b>Effects</b>: inserts each element from the range [first,last) if and only
  2242. //! if there is no element with key equivalent to the key of that element. This
  2243. //! function is more efficient than the normal range creation for ordered ranges.
  2244. //!
  2245. //! <b>Complexity</b>: Linear.
  2246. //!
  2247. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2248. //!
  2249. //! <b>Note</b>: Non-standard extension.
  2250. template <class InputIterator>
  2251. BOOST_CONTAINER_FORCEINLINE void insert(ordered_range_t, InputIterator first, InputIterator last)
  2252. { m_flat_tree.insert_equal(ordered_range, first, last); }
  2253. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  2254. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) .
  2255. //!
  2256. //! <b>Complexity</b>: N log(N).
  2257. //!
  2258. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2259. BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
  2260. {
  2261. m_flat_tree.insert_equal( dtl::force<impl_initializer_list>(il).begin()
  2262. , dtl::force<impl_initializer_list>(il).end());
  2263. }
  2264. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  2265. //!
  2266. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
  2267. //! if there is no element with key equivalent to the key of that element. This
  2268. //! function is more efficient than the normal range creation for ordered ranges.
  2269. //!
  2270. //! <b>Complexity</b>: Linear.
  2271. //!
  2272. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  2273. //!
  2274. //! <b>Note</b>: Non-standard extension.
  2275. BOOST_CONTAINER_FORCEINLINE void insert(ordered_range_t, std::initializer_list<value_type> il)
  2276. {
  2277. m_flat_tree.insert_equal( ordered_range
  2278. , dtl::force<impl_initializer_list>(il).begin()
  2279. , dtl::force<impl_initializer_list>(il).end());
  2280. }
  2281. #endif
  2282. //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
  2283. //!
  2284. //! <b>Effects</b>: Extracts each element in source and insert it into a using
  2285. //! the comparison object of *this.
  2286. //!
  2287. //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
  2288. //! to those same elements but as members of *this. Iterators referring to the transferred
  2289. //! elements will continue to refer to their elements, but they now behave as iterators into *this,
  2290. //! not into source.
  2291. //!
  2292. //! <b>Throws</b>: Nothing unless the comparison object throws.
  2293. //!
  2294. //! <b>Complexity</b>: N log(size() + N) (N has the value source.size())
  2295. template<class C2>
  2296. BOOST_CONTAINER_FORCEINLINE void merge(flat_multimap<Key, T, C2, AllocatorOrContainer>& source)
  2297. { m_flat_tree.merge_equal(source.tree()); }
  2298. //! @copydoc ::boost::container::flat_multimap::merge(flat_multimap<Key, T, C2, AllocatorOrContainer>&)
  2299. template<class C2>
  2300. BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_multimap<Key, T, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
  2301. { return this->merge(static_cast<flat_multimap<Key, T, C2, AllocatorOrContainer>&>(source)); }
  2302. //! @copydoc ::boost::container::flat_multimap::merge(flat_multimap<Key, T, C2, AllocatorOrContainer>&)
  2303. template<class C2>
  2304. BOOST_CONTAINER_FORCEINLINE void merge(flat_map<Key, T, C2, AllocatorOrContainer>& source)
  2305. { m_flat_tree.merge_equal(source.tree()); }
  2306. //! @copydoc ::boost::container::flat_multimap::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
  2307. template<class C2>
  2308. BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_map<Key, T, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
  2309. { return this->merge(static_cast<flat_map<Key, T, C2, AllocatorOrContainer>&>(source)); }
  2310. //! <b>Effects</b>: Erases the element pointed to by p.
  2311. //!
  2312. //! <b>Returns</b>: Returns an iterator pointing to the element immediately
  2313. //! following q prior to the element being erased. If no such element exists,
  2314. //! returns end().
  2315. //!
  2316. //! <b>Complexity</b>: Linear to the elements with keys bigger than p
  2317. //!
  2318. //! <b>Note</b>: Invalidates elements with keys
  2319. //! not less than the erased element.
  2320. BOOST_CONTAINER_FORCEINLINE iterator erase(const_iterator p)
  2321. {
  2322. return dtl::force_copy<iterator>(
  2323. m_flat_tree.erase(dtl::force_copy<impl_const_iterator>(p)));
  2324. }
  2325. //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
  2326. //!
  2327. //! <b>Returns</b>: Returns the number of erased elements.
  2328. //!
  2329. //! <b>Complexity</b>: Logarithmic search time plus erasure time
  2330. //! linear to the elements with bigger keys.
  2331. BOOST_CONTAINER_FORCEINLINE size_type erase(const key_type& x)
  2332. { return m_flat_tree.erase(x); }
  2333. //! <b>Effects</b>: Erases all the elements in the range [first, last).
  2334. //!
  2335. //! <b>Returns</b>: Returns last.
  2336. //!
  2337. //! <b>Complexity</b>: size()*N where N is the distance from first to last.
  2338. //!
  2339. //! <b>Complexity</b>: Logarithmic search time plus erasure time
  2340. //! linear to the elements with bigger keys.
  2341. BOOST_CONTAINER_FORCEINLINE iterator erase(const_iterator first, const_iterator last)
  2342. {
  2343. return dtl::force_copy<iterator>
  2344. (m_flat_tree.erase( dtl::force_copy<impl_const_iterator>(first)
  2345. , dtl::force_copy<impl_const_iterator>(last)));
  2346. }
  2347. //! <b>Effects</b>: Swaps the contents of *this and x.
  2348. //!
  2349. //! <b>Throws</b>: Nothing.
  2350. //!
  2351. //! <b>Complexity</b>: Constant.
  2352. BOOST_CONTAINER_FORCEINLINE void swap(flat_multimap& x)
  2353. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  2354. && boost::container::dtl::is_nothrow_swappable<Compare>::value )
  2355. { m_flat_tree.swap(x.m_flat_tree); }
  2356. //! <b>Effects</b>: erase(begin(),end()).
  2357. //!
  2358. //! <b>Postcondition</b>: size() == 0.
  2359. //!
  2360. //! <b>Complexity</b>: linear in size().
  2361. BOOST_CONTAINER_FORCEINLINE void clear() BOOST_NOEXCEPT_OR_NOTHROW
  2362. { m_flat_tree.clear(); }
  2363. //////////////////////////////////////////////
  2364. //
  2365. // observers
  2366. //
  2367. //////////////////////////////////////////////
  2368. //! <b>Effects</b>: Returns the comparison object out
  2369. //! of which a was constructed.
  2370. //!
  2371. //! <b>Complexity</b>: Constant.
  2372. BOOST_CONTAINER_FORCEINLINE key_compare key_comp() const
  2373. { return dtl::force_copy<key_compare>(m_flat_tree.key_comp()); }
  2374. //! <b>Effects</b>: Returns an object of value_compare constructed out
  2375. //! of the comparison object.
  2376. //!
  2377. //! <b>Complexity</b>: Constant.
  2378. BOOST_CONTAINER_FORCEINLINE value_compare value_comp() const
  2379. { return value_compare(dtl::force_copy<key_compare>(m_flat_tree.key_comp())); }
  2380. //////////////////////////////////////////////
  2381. //
  2382. // map operations
  2383. //
  2384. //////////////////////////////////////////////
  2385. //! <b>Returns</b>: An iterator pointing to an element with the key
  2386. //! equivalent to x, or end() if such an element is not found.
  2387. //!
  2388. //! <b>Complexity</b>: Logarithmic.
  2389. BOOST_CONTAINER_FORCEINLINE iterator find(const key_type& x)
  2390. { return dtl::force_copy<iterator>(m_flat_tree.find(x)); }
  2391. //! <b>Returns</b>: An const_iterator pointing to an element with the key
  2392. //! equivalent to x, or end() if such an element is not found.
  2393. //!
  2394. //! <b>Complexity</b>: Logarithmic.
  2395. BOOST_CONTAINER_FORCEINLINE const_iterator find(const key_type& x) const
  2396. { return dtl::force_copy<const_iterator>(m_flat_tree.find(x)); }
  2397. //! <b>Requires</b>: This overload is available only if
  2398. //! key_compare::is_transparent exists.
  2399. //!
  2400. //! <b>Returns</b>: An iterator pointing to an element with the key
  2401. //! equivalent to x, or end() if such an element is not found.
  2402. //!
  2403. //! <b>Complexity</b>: Logarithmic.
  2404. template<class K>
  2405. BOOST_CONTAINER_FORCEINLINE iterator find(const K& x)
  2406. { return dtl::force_copy<iterator>(m_flat_tree.find(x)); }
  2407. //! <b>Requires</b>: This overload is available only if
  2408. //! key_compare::is_transparent exists.
  2409. //!
  2410. //! <b>Returns</b>: An const_iterator pointing to an element with the key
  2411. //! equivalent to x, or end() if such an element is not found.
  2412. //!
  2413. //! <b>Complexity</b>: Logarithmic.
  2414. template<class K>
  2415. BOOST_CONTAINER_FORCEINLINE const_iterator find(const K& x) const
  2416. { return dtl::force_copy<const_iterator>(m_flat_tree.find(x)); }
  2417. //! <b>Returns</b>: The number of elements with key equivalent to x.
  2418. //!
  2419. //! <b>Complexity</b>: log(size())+count(k)
  2420. BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const
  2421. { return m_flat_tree.count(x); }
  2422. //! <b>Requires</b>: This overload is available only if
  2423. //! key_compare::is_transparent exists.
  2424. //!
  2425. //! <b>Returns</b>: The number of elements with key equivalent to x.
  2426. //!
  2427. //! <b>Complexity</b>: log(size())+count(k)
  2428. template<class K>
  2429. BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
  2430. { return m_flat_tree.count(x); }
  2431. //! <b>Returns</b>: Returns true if there is an element with key
  2432. //! equivalent to key in the container, otherwise false.
  2433. //!
  2434. //! <b>Complexity</b>: log(size()).
  2435. bool contains(const key_type& x) const
  2436. { return m_flat_tree.find(x) != m_flat_tree.end(); }
  2437. //! <b>Requires</b>: This overload is available only if
  2438. //! key_compare::is_transparent exists.
  2439. //!
  2440. //! <b>Returns</b>: Returns true if there is an element with key
  2441. //! equivalent to key in the container, otherwise false.
  2442. //!
  2443. //! <b>Complexity</b>: log(size()).
  2444. template<typename K>
  2445. bool contains(const K& x) const
  2446. { return m_flat_tree.find(x) != m_flat_tree.end(); }
  2447. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  2448. //! than x, or end() if such an element is not found.
  2449. //!
  2450. //! <b>Complexity</b>: Logarithmic
  2451. BOOST_CONTAINER_FORCEINLINE iterator lower_bound(const key_type& x)
  2452. { return dtl::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
  2453. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  2454. //! than x, or end() if such an element is not found.
  2455. //!
  2456. //! <b>Complexity</b>: Logarithmic
  2457. BOOST_CONTAINER_FORCEINLINE const_iterator lower_bound(const key_type& x) const
  2458. { return dtl::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
  2459. //! <b>Requires</b>: This overload is available only if
  2460. //! key_compare::is_transparent exists.
  2461. //!
  2462. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  2463. //! than x, or end() if such an element is not found.
  2464. //!
  2465. //! <b>Complexity</b>: Logarithmic
  2466. template<class K>
  2467. BOOST_CONTAINER_FORCEINLINE iterator lower_bound(const K& x)
  2468. { return dtl::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
  2469. //! <b>Requires</b>: This overload is available only if
  2470. //! key_compare::is_transparent exists.
  2471. //!
  2472. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  2473. //! than x, or end() if such an element is not found.
  2474. //!
  2475. //! <b>Complexity</b>: Logarithmic
  2476. template<class K>
  2477. BOOST_CONTAINER_FORCEINLINE const_iterator lower_bound(const K& x) const
  2478. { return dtl::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
  2479. //! <b>Returns</b>: An iterator pointing to the first element with key greater
  2480. //! than x, or end() if such an element is not found.
  2481. //!
  2482. //! <b>Complexity</b>: Logarithmic
  2483. BOOST_CONTAINER_FORCEINLINE iterator upper_bound(const key_type& x)
  2484. {return dtl::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
  2485. //! <b>Returns</b>: A const iterator pointing to the first element with key
  2486. //! greater than x, or end() if such an element is not found.
  2487. //!
  2488. //! <b>Complexity</b>: Logarithmic
  2489. BOOST_CONTAINER_FORCEINLINE const_iterator upper_bound(const key_type& x) const
  2490. { return dtl::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
  2491. //! <b>Requires</b>: This overload is available only if
  2492. //! key_compare::is_transparent exists.
  2493. //!
  2494. //! <b>Returns</b>: An iterator pointing to the first element with key greater
  2495. //! than x, or end() if such an element is not found.
  2496. //!
  2497. //! <b>Complexity</b>: Logarithmic
  2498. template<class K>
  2499. BOOST_CONTAINER_FORCEINLINE iterator upper_bound(const K& x)
  2500. {return dtl::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
  2501. //! <b>Requires</b>: This overload is available only if
  2502. //! key_compare::is_transparent exists.
  2503. //!
  2504. //! <b>Returns</b>: A const iterator pointing to the first element with key
  2505. //! greater than x, or end() if such an element is not found.
  2506. //!
  2507. //! <b>Complexity</b>: Logarithmic
  2508. template<class K>
  2509. BOOST_CONTAINER_FORCEINLINE const_iterator upper_bound(const K& x) const
  2510. { return dtl::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
  2511. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  2512. //!
  2513. //! <b>Complexity</b>: Logarithmic
  2514. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const key_type& x)
  2515. { return dtl::force_copy<std::pair<iterator,iterator> >(m_flat_tree.equal_range(x)); }
  2516. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  2517. //!
  2518. //! <b>Complexity</b>: Logarithmic
  2519. BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const
  2520. { return dtl::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.equal_range(x)); }
  2521. //! <b>Requires</b>: This overload is available only if
  2522. //! key_compare::is_transparent exists.
  2523. //!
  2524. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  2525. //!
  2526. //! <b>Complexity</b>: Logarithmic
  2527. template<class K>
  2528. BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const K& x)
  2529. { return dtl::force_copy<std::pair<iterator,iterator> >(m_flat_tree.equal_range(x)); }
  2530. //! <b>Requires</b>: This overload is available only if
  2531. //! key_compare::is_transparent exists.
  2532. //!
  2533. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  2534. //!
  2535. //! <b>Complexity</b>: Logarithmic
  2536. template<class K>
  2537. BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const K& x) const
  2538. { return dtl::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.equal_range(x)); }
  2539. //! <b>Effects</b>: Extracts the internal sequence container.
  2540. //!
  2541. //! <b>Complexity</b>: Same as the move constructor of sequence_type, usually constant.
  2542. //!
  2543. //! <b>Postcondition</b>: this->empty()
  2544. //!
  2545. //! <b>Throws</b>: If secuence_type's move constructor throws
  2546. BOOST_CONTAINER_FORCEINLINE sequence_type extract_sequence()
  2547. {
  2548. return boost::move(dtl::force<sequence_type>(m_flat_tree.get_sequence_ref()));
  2549. }
  2550. //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
  2551. //! one passed externally using the move assignment.
  2552. //!
  2553. //! <b>Complexity</b>: Assuming O(1) move assignment, O(NlogN) with N = seq.size()
  2554. //!
  2555. //! <b>Throws</b>: If the comparison or the move constructor throws
  2556. BOOST_CONTAINER_FORCEINLINE void adopt_sequence(BOOST_RV_REF(sequence_type) seq)
  2557. { this->m_flat_tree.adopt_sequence_equal(boost::move(dtl::force<impl_sequence_type>(seq))); }
  2558. //! <b>Requires</b>: seq shall be ordered according to this->compare().
  2559. //!
  2560. //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
  2561. //! one passed externally using the move assignment.
  2562. //!
  2563. //! <b>Complexity</b>: Assuming O(1) move assignment, O(1)
  2564. //!
  2565. //! <b>Throws</b>: If the move assignment throws
  2566. BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_range_t, BOOST_RV_REF(sequence_type) seq)
  2567. { this->m_flat_tree.adopt_sequence_equal(ordered_range_t(), boost::move(dtl::force<impl_sequence_type>(seq))); }
  2568. //! <b>Effects</b>: Returns true if x and y are equal
  2569. //!
  2570. //! <b>Complexity</b>: Linear to the number of elements in the container.
  2571. BOOST_CONTAINER_FORCEINLINE friend bool operator==(const flat_multimap& x, const flat_multimap& y)
  2572. { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
  2573. //! <b>Effects</b>: Returns true if x and y are unequal
  2574. //!
  2575. //! <b>Complexity</b>: Linear to the number of elements in the container.
  2576. BOOST_CONTAINER_FORCEINLINE friend bool operator!=(const flat_multimap& x, const flat_multimap& y)
  2577. { return !(x == y); }
  2578. //! <b>Effects</b>: Returns true if x is less than y
  2579. //!
  2580. //! <b>Complexity</b>: Linear to the number of elements in the container.
  2581. BOOST_CONTAINER_FORCEINLINE friend bool operator<(const flat_multimap& x, const flat_multimap& y)
  2582. { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  2583. //! <b>Effects</b>: Returns true if x is greater than y
  2584. //!
  2585. //! <b>Complexity</b>: Linear to the number of elements in the container.
  2586. BOOST_CONTAINER_FORCEINLINE friend bool operator>(const flat_multimap& x, const flat_multimap& y)
  2587. { return y < x; }
  2588. //! <b>Effects</b>: Returns true if x is equal or less than y
  2589. //!
  2590. //! <b>Complexity</b>: Linear to the number of elements in the container.
  2591. BOOST_CONTAINER_FORCEINLINE friend bool operator<=(const flat_multimap& x, const flat_multimap& y)
  2592. { return !(y < x); }
  2593. //! <b>Effects</b>: Returns true if x is equal or greater than y
  2594. //!
  2595. //! <b>Complexity</b>: Linear to the number of elements in the container.
  2596. BOOST_CONTAINER_FORCEINLINE friend bool operator>=(const flat_multimap& x, const flat_multimap& y)
  2597. { return !(x < y); }
  2598. //! <b>Effects</b>: x.swap(y)
  2599. //!
  2600. //! <b>Complexity</b>: Constant.
  2601. BOOST_CONTAINER_FORCEINLINE friend void swap(flat_multimap& x, flat_multimap& y)
  2602. { x.swap(y); }
  2603. };
  2604. #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
  2605. template <typename InputIterator>
  2606. flat_multimap(InputIterator, InputIterator) ->
  2607. flat_multimap< it_based_non_const_first_type_t<InputIterator>
  2608. , it_based_second_type_t<InputIterator>>;
  2609. template < typename InputIterator, typename AllocatorOrCompare>
  2610. flat_multimap(InputIterator, InputIterator, AllocatorOrCompare const&) ->
  2611. flat_multimap< it_based_non_const_first_type_t<InputIterator>
  2612. , it_based_second_type_t<InputIterator>
  2613. , typename dtl::if_c< // Compare
  2614. dtl::is_allocator<AllocatorOrCompare>::value
  2615. , std::less<it_based_non_const_first_type_t<InputIterator>>
  2616. , AllocatorOrCompare
  2617. >::type
  2618. , typename dtl::if_c< // Allocator
  2619. dtl::is_allocator<AllocatorOrCompare>::value
  2620. , AllocatorOrCompare
  2621. , new_allocator<std::pair<it_based_non_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
  2622. >::type
  2623. >;
  2624. template < typename InputIterator, typename Compare, typename Allocator
  2625. , typename = dtl::require_nonallocator_t<Compare>
  2626. , typename = dtl::require_allocator_t<Allocator>>
  2627. flat_multimap(InputIterator, InputIterator, Compare const&, Allocator const&) ->
  2628. flat_multimap< it_based_non_const_first_type_t<InputIterator>
  2629. , it_based_second_type_t<InputIterator>
  2630. , Compare
  2631. , Allocator>;
  2632. template <typename InputIterator>
  2633. flat_multimap(ordered_range_t, InputIterator, InputIterator) ->
  2634. flat_multimap< it_based_non_const_first_type_t<InputIterator>
  2635. , it_based_second_type_t<InputIterator>>;
  2636. template < typename InputIterator, typename AllocatorOrCompare>
  2637. flat_multimap(ordered_range_t, InputIterator, InputIterator, AllocatorOrCompare const&) ->
  2638. flat_multimap< it_based_non_const_first_type_t<InputIterator>
  2639. , it_based_second_type_t<InputIterator>
  2640. , typename dtl::if_c< // Compare
  2641. dtl::is_allocator<AllocatorOrCompare>::value
  2642. , std::less<it_based_non_const_first_type_t<InputIterator>>
  2643. , AllocatorOrCompare
  2644. >::type
  2645. , typename dtl::if_c< // Allocator
  2646. dtl::is_allocator<AllocatorOrCompare>::value
  2647. , AllocatorOrCompare
  2648. , new_allocator<std::pair<it_based_non_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
  2649. >::type
  2650. >;
  2651. template < typename InputIterator, typename Compare, typename Allocator
  2652. , typename = dtl::require_nonallocator_t<Compare>
  2653. , typename = dtl::require_allocator_t<Allocator>>
  2654. flat_multimap(ordered_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
  2655. flat_multimap< it_based_non_const_first_type_t<InputIterator>
  2656. , it_based_second_type_t<InputIterator>
  2657. , Compare
  2658. , Allocator>;
  2659. #endif
  2660. }}
  2661. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  2662. namespace boost {
  2663. //!has_trivial_destructor_after_move<> == true_type
  2664. //!specialization for optimizations
  2665. template <class Key, class T, class Compare, class AllocatorOrContainer>
  2666. struct has_trivial_destructor_after_move< boost::container::flat_multimap<Key, T, Compare, AllocatorOrContainer> >
  2667. {
  2668. typedef ::boost::container::dtl::pair<Key, T> value_t;
  2669. typedef typename ::boost::container::dtl::container_or_allocator_rebind<AllocatorOrContainer, value_t>::type alloc_or_cont_t;
  2670. typedef ::boost::container::dtl::flat_tree<value_t,::boost::container::dtl::select1st<Key>, Compare, alloc_or_cont_t> tree;
  2671. static const bool value = ::boost::has_trivial_destructor_after_move<tree>::value;
  2672. };
  2673. } //namespace boost {
  2674. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  2675. #include <boost/container/detail/config_end.hpp>
  2676. #endif // BOOST_CONTAINER_FLAT_MAP_HPP