flat_map.hpp 129 KB

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