flat_map.hpp 135 KB

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