flat_map.hpp 132 KB

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