flat_map.hpp 136 KB

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