flat_map.hpp 132 KB

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