flat_map.hpp 136 KB

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