flat_map.hpp 136 KB

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