flat_map.hpp 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  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. // move
  31. #include <boost/move/utility_core.hpp>
  32. #include <boost/move/traits.hpp>
  33. // move/detail
  34. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  35. #include <boost/move/detail/fwd_macros.hpp>
  36. #endif
  37. #include <boost/move/detail/move_helpers.hpp>
  38. // intrusive
  39. #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
  40. #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal
  41. //others
  42. #include <boost/core/no_exceptions_support.hpp>
  43. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  44. #include <initializer_list>
  45. #endif
  46. namespace boost {
  47. namespace container {
  48. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  49. namespace container_detail{
  50. template<class D, class S>
  51. static D &force(const S &s)
  52. { return *const_cast<D*>((reinterpret_cast<const D*>(&s))); }
  53. template<class D, class S>
  54. static D force_copy(S s)
  55. {
  56. D *vp = reinterpret_cast<D *>(&s);
  57. return D(*vp);
  58. }
  59. } //namespace container_detail{
  60. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  61. //! A flat_map is a kind of associative container that supports unique keys (contains at
  62. //! most one of each key value) and provides for fast retrieval of values of another
  63. //! type T based on the keys. The flat_map class supports random-access iterators.
  64. //!
  65. //! A flat_map satisfies all of the requirements of a container and of a reversible
  66. //! container and of an associative container. A flat_map also provides
  67. //! most operations described for unique keys. For a
  68. //! flat_map<Key,T> the key_type is Key and the value_type is std::pair<Key,T>
  69. //! (unlike std::map<Key, T> which value_type is std::pair<<b>const</b> Key, T>).
  70. //!
  71. //! Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
  72. //!
  73. //! Allocator is the allocator to allocate the value_types
  74. //! (e.g. <i>allocator< std::pair<Key, T> ></i>).
  75. //!
  76. //! flat_map is similar to std::map but it's implemented like an ordered vector.
  77. //! This means that inserting a new element into a flat_map invalidates
  78. //! previous iterators and references
  79. //!
  80. //! Erasing an element invalidates iterators and references
  81. //! pointing to elements that come after (their keys are bigger) the erased element.
  82. //!
  83. //! This container provides random-access iterators.
  84. //!
  85. //! \tparam Key is the key_type of the map
  86. //! \tparam Value is the <code>mapped_type</code>
  87. //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
  88. //! \tparam Allocator is the allocator to allocate the <code>value_type</code>s
  89. //! (e.g. <i>allocator< std::pair<Key, T> > </i>).
  90. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  91. template <class Key, class T, class Compare = std::less<Key>, class Allocator = new_allocator< std::pair< Key, T> > >
  92. #else
  93. template <class Key, class T, class Compare, class Allocator>
  94. #endif
  95. class flat_map
  96. {
  97. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  98. private:
  99. BOOST_COPYABLE_AND_MOVABLE(flat_map)
  100. //This is the tree that we should store if pair was movable
  101. typedef container_detail::flat_tree<Key,
  102. std::pair<Key, T>,
  103. container_detail::select1st< std::pair<Key, T> >,
  104. Compare,
  105. Allocator> tree_t;
  106. //This is the real tree stored here. It's based on a movable pair
  107. typedef container_detail::flat_tree<Key,
  108. container_detail::pair<Key, T>,
  109. container_detail::select1st<container_detail::pair<Key, T> >,
  110. Compare,
  111. typename allocator_traits<Allocator>::template portable_rebind_alloc
  112. <container_detail::pair<Key, T> >::type> impl_tree_t;
  113. impl_tree_t m_flat_tree; // flat tree representing flat_map
  114. typedef typename impl_tree_t::value_type impl_value_type;
  115. typedef typename impl_tree_t::const_iterator impl_const_iterator;
  116. typedef typename impl_tree_t::iterator impl_iterator;
  117. typedef typename impl_tree_t::allocator_type impl_allocator_type;
  118. typedef container_detail::flat_tree_value_compare
  119. < Compare
  120. , container_detail::select1st< std::pair<Key, T> >
  121. , std::pair<Key, T> > value_compare_impl;
  122. typedef typename container_detail::get_flat_tree_iterators
  123. <typename allocator_traits<Allocator>::pointer>::iterator iterator_impl;
  124. typedef typename container_detail::get_flat_tree_iterators
  125. <typename allocator_traits<Allocator>::pointer>::const_iterator const_iterator_impl;
  126. typedef typename container_detail::get_flat_tree_iterators
  127. <typename allocator_traits<Allocator>::pointer>::reverse_iterator reverse_iterator_impl;
  128. typedef typename container_detail::get_flat_tree_iterators
  129. <typename allocator_traits<Allocator>::pointer>::const_reverse_iterator const_reverse_iterator_impl;
  130. public:
  131. typedef typename impl_tree_t::stored_allocator_type impl_stored_allocator_type;
  132. private:
  133. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  134. public:
  135. //////////////////////////////////////////////
  136. //
  137. // types
  138. //
  139. //////////////////////////////////////////////
  140. typedef Key key_type;
  141. typedef T mapped_type;
  142. typedef std::pair<Key, T> value_type;
  143. typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
  144. typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
  145. typedef typename boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
  146. typedef typename boost::container::allocator_traits<Allocator>::reference reference;
  147. typedef typename boost::container::allocator_traits<Allocator>::const_reference const_reference;
  148. typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
  149. typedef typename boost::container::allocator_traits<Allocator>::difference_type difference_type;
  150. typedef Allocator allocator_type;
  151. typedef BOOST_CONTAINER_IMPDEF(Allocator) stored_allocator_type;
  152. typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
  153. typedef Compare key_compare;
  154. typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator;
  155. typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator;
  156. typedef BOOST_CONTAINER_IMPDEF(reverse_iterator_impl) reverse_iterator;
  157. typedef BOOST_CONTAINER_IMPDEF(const_reverse_iterator_impl) const_reverse_iterator;
  158. typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type;
  159. public:
  160. //////////////////////////////////////////////
  161. //
  162. // construct/copy/destroy
  163. //
  164. //////////////////////////////////////////////
  165. //! <b>Effects</b>: Default constructs an empty flat_map.
  166. //!
  167. //! <b>Complexity</b>: Constant.
  168. flat_map()
  169. : m_flat_tree()
  170. {
  171. //A type must be std::pair<Key, T>
  172. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  173. }
  174. //! <b>Effects</b>: Constructs an empty flat_map using the specified
  175. //! comparison object and allocator.
  176. //!
  177. //! <b>Complexity</b>: Constant.
  178. explicit flat_map(const Compare& comp, const allocator_type& a = allocator_type())
  179. : m_flat_tree(comp, container_detail::force<impl_allocator_type>(a))
  180. {
  181. //A type must be std::pair<Key, T>
  182. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  183. }
  184. //! <b>Effects</b>: Constructs an empty flat_map using the specified allocator.
  185. //!
  186. //! <b>Complexity</b>: Constant.
  187. explicit flat_map(const allocator_type& a)
  188. : m_flat_tree(container_detail::force<impl_allocator_type>(a))
  189. {
  190. //A type must be std::pair<Key, T>
  191. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  192. }
  193. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  194. //! allocator, and inserts elements from the range [first ,last ).
  195. //!
  196. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  197. //! comp and otherwise N logN, where N is last - first.
  198. template <class InputIterator>
  199. flat_map(InputIterator first, InputIterator last, const Compare& comp = Compare(),
  200. const allocator_type& a = allocator_type())
  201. : m_flat_tree(true, first, last, comp, container_detail::force<impl_allocator_type>(a))
  202. {
  203. //A type must be std::pair<Key, T>
  204. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  205. }
  206. //! <b>Effects</b>: Constructs an empty flat_map using the specified
  207. //! allocator, 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. //! comp and otherwise N logN, where N is last - first.
  211. template <class InputIterator>
  212. flat_map(InputIterator first, InputIterator last, const allocator_type& a)
  213. : m_flat_tree(true, first, last, Compare(), container_detail::force<impl_allocator_type>(a))
  214. {
  215. //A type must be std::pair<Key, T>
  216. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  217. }
  218. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  219. //! allocator, and inserts elements from the ordered unique range [first ,last). This function
  220. //! is more efficient than the normal range creation for ordered ranges.
  221. //!
  222. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
  223. //! unique values.
  224. //!
  225. //! <b>Complexity</b>: Linear in N.
  226. //!
  227. //! <b>Note</b>: Non-standard extension.
  228. template <class InputIterator>
  229. flat_map( ordered_unique_range_t, InputIterator first, InputIterator last
  230. , const Compare& comp = Compare(), const allocator_type& a = allocator_type())
  231. : m_flat_tree(ordered_range, first, last, comp, a)
  232. {
  233. //A type must be std::pair<Key, T>
  234. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  235. }
  236. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  237. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  238. //! allocator, and inserts elements from the range [il.begin() ,il.end()).
  239. //!
  240. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  241. //! comp and otherwise N logN, where N is last - first.
  242. flat_map(std::initializer_list<value_type> il, const Compare& comp = Compare(),
  243. const allocator_type& a = allocator_type())
  244. : m_flat_tree(true, il.begin(), il.end(), comp, container_detail::force<impl_allocator_type>(a))
  245. {
  246. //A type must be std::pair<Key, T>
  247. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  248. }
  249. //! <b>Effects</b>: Constructs an empty flat_map using the specified
  250. //! allocator, and inserts elements from the range [il.begin() ,il.end()).
  251. //!
  252. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  253. //! comp and otherwise N logN, where N is last - first.
  254. flat_map(std::initializer_list<value_type> il, const allocator_type& a)
  255. : m_flat_tree(true, il.begin(), il.end(), Compare(), container_detail::force<impl_allocator_type>(a))
  256. {
  257. //A type must be std::pair<Key, T>
  258. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  259. }
  260. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  261. //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
  262. //! is more efficient than the normal range creation for ordered ranges.
  263. //!
  264. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  265. //! unique values.
  266. //!
  267. //! <b>Complexity</b>: Linear in N.
  268. //!
  269. //! <b>Note</b>: Non-standard extension.
  270. flat_map(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(),
  271. const allocator_type& a = allocator_type())
  272. : m_flat_tree(ordered_range, il.begin(), il.end(), comp, a)
  273. {
  274. //A type must be std::pair<Key, T>
  275. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  276. }
  277. #endif
  278. //! <b>Effects</b>: Copy constructs a flat_map.
  279. //!
  280. //! <b>Complexity</b>: Linear in x.size().
  281. flat_map(const flat_map& x)
  282. : m_flat_tree(x.m_flat_tree)
  283. {
  284. //A type must be std::pair<Key, T>
  285. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  286. }
  287. //! <b>Effects</b>: Move constructs a flat_map.
  288. //! Constructs *this using x's resources.
  289. //!
  290. //! <b>Complexity</b>: Constant.
  291. //!
  292. //! <b>Postcondition</b>: x is emptied.
  293. flat_map(BOOST_RV_REF(flat_map) x)
  294. : m_flat_tree(boost::move(x.m_flat_tree))
  295. {
  296. //A type must be std::pair<Key, T>
  297. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  298. }
  299. //! <b>Effects</b>: Copy constructs a flat_map using the specified allocator.
  300. //!
  301. //! <b>Complexity</b>: Linear in x.size().
  302. flat_map(const flat_map& x, const allocator_type &a)
  303. : m_flat_tree(x.m_flat_tree, a)
  304. {
  305. //A type must be std::pair<Key, T>
  306. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  307. }
  308. //! <b>Effects</b>: Move constructs a flat_map using the specified allocator.
  309. //! Constructs *this using x's resources.
  310. //!
  311. //! <b>Complexity</b>: Constant if x.get_allocator() == a, linear otherwise.
  312. flat_map(BOOST_RV_REF(flat_map) x, const allocator_type &a)
  313. : m_flat_tree(boost::move(x.m_flat_tree), a)
  314. {
  315. //A type must be std::pair<Key, T>
  316. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  317. }
  318. //! <b>Effects</b>: Makes *this a copy of x.
  319. //!
  320. //! <b>Complexity</b>: Linear in x.size().
  321. flat_map& operator=(BOOST_COPY_ASSIGN_REF(flat_map) x)
  322. { m_flat_tree = x.m_flat_tree; return *this; }
  323. //! <b>Effects</b>: Move constructs a flat_map.
  324. //! Constructs *this using x's resources.
  325. //!
  326. //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
  327. //! is false and (allocation throws or value_type's move constructor throws)
  328. //!
  329. //! <b>Complexity</b>: Constant if allocator_traits_type::
  330. //! propagate_on_container_move_assignment is true or
  331. //! this->get>allocator() == x.get_allocator(). Linear otherwise.
  332. flat_map& operator=(BOOST_RV_REF(flat_map) x)
  333. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  334. && boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
  335. { m_flat_tree = boost::move(x.m_flat_tree); return *this; }
  336. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  337. //! <b>Effects</b>: Assign elements from il to *this
  338. flat_map& operator=(std::initializer_list<value_type> il)
  339. {
  340. this->clear();
  341. this->insert(il.begin(), il.end());
  342. return *this;
  343. }
  344. #endif
  345. //! <b>Effects</b>: Returns a copy of the allocator that
  346. //! was passed to the object's constructor.
  347. //!
  348. //! <b>Complexity</b>: Constant.
  349. allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  350. { return container_detail::force_copy<allocator_type>(m_flat_tree.get_allocator()); }
  351. //! <b>Effects</b>: Returns a reference to the internal allocator.
  352. //!
  353. //! <b>Throws</b>: Nothing
  354. //!
  355. //! <b>Complexity</b>: Constant.
  356. //!
  357. //! <b>Note</b>: Non-standard extension.
  358. stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
  359. { return container_detail::force<stored_allocator_type>(m_flat_tree.get_stored_allocator()); }
  360. //! <b>Effects</b>: Returns a reference to the internal allocator.
  361. //!
  362. //! <b>Throws</b>: Nothing
  363. //!
  364. //! <b>Complexity</b>: Constant.
  365. //!
  366. //! <b>Note</b>: Non-standard extension.
  367. const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  368. { return container_detail::force<stored_allocator_type>(m_flat_tree.get_stored_allocator()); }
  369. //////////////////////////////////////////////
  370. //
  371. // iterators
  372. //
  373. //////////////////////////////////////////////
  374. //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
  375. //!
  376. //! <b>Throws</b>: Nothing.
  377. //!
  378. //! <b>Complexity</b>: Constant.
  379. iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
  380. { return container_detail::force_copy<iterator>(m_flat_tree.begin()); }
  381. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  382. //!
  383. //! <b>Throws</b>: Nothing.
  384. //!
  385. //! <b>Complexity</b>: Constant.
  386. const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
  387. { return container_detail::force_copy<const_iterator>(m_flat_tree.begin()); }
  388. //! <b>Effects</b>: Returns an iterator to the end of the container.
  389. //!
  390. //! <b>Throws</b>: Nothing.
  391. //!
  392. //! <b>Complexity</b>: Constant.
  393. iterator end() BOOST_NOEXCEPT_OR_NOTHROW
  394. { return container_detail::force_copy<iterator>(m_flat_tree.end()); }
  395. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  396. //!
  397. //! <b>Throws</b>: Nothing.
  398. //!
  399. //! <b>Complexity</b>: Constant.
  400. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
  401. { return container_detail::force_copy<const_iterator>(m_flat_tree.end()); }
  402. //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
  403. //! of the reversed container.
  404. //!
  405. //! <b>Throws</b>: Nothing.
  406. //!
  407. //! <b>Complexity</b>: Constant.
  408. reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
  409. { return container_detail::force_copy<reverse_iterator>(m_flat_tree.rbegin()); }
  410. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  411. //! of the reversed container.
  412. //!
  413. //! <b>Throws</b>: Nothing.
  414. //!
  415. //! <b>Complexity</b>: Constant.
  416. const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  417. { return container_detail::force_copy<const_reverse_iterator>(m_flat_tree.rbegin()); }
  418. //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
  419. //! of the reversed container.
  420. //!
  421. //! <b>Throws</b>: Nothing.
  422. //!
  423. //! <b>Complexity</b>: Constant.
  424. reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
  425. { return container_detail::force_copy<reverse_iterator>(m_flat_tree.rend()); }
  426. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  427. //! of the reversed container.
  428. //!
  429. //! <b>Throws</b>: Nothing.
  430. //!
  431. //! <b>Complexity</b>: Constant.
  432. const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
  433. { return container_detail::force_copy<const_reverse_iterator>(m_flat_tree.rend()); }
  434. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  435. //!
  436. //! <b>Throws</b>: Nothing.
  437. //!
  438. //! <b>Complexity</b>: Constant.
  439. const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  440. { return container_detail::force_copy<const_iterator>(m_flat_tree.cbegin()); }
  441. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  442. //!
  443. //! <b>Throws</b>: Nothing.
  444. //!
  445. //! <b>Complexity</b>: Constant.
  446. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
  447. { return container_detail::force_copy<const_iterator>(m_flat_tree.cend()); }
  448. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  449. //! of the reversed container.
  450. //!
  451. //! <b>Throws</b>: Nothing.
  452. //!
  453. //! <b>Complexity</b>: Constant.
  454. const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  455. { return container_detail::force_copy<const_reverse_iterator>(m_flat_tree.crbegin()); }
  456. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  457. //! of the reversed container.
  458. //!
  459. //! <b>Throws</b>: Nothing.
  460. //!
  461. //! <b>Complexity</b>: Constant.
  462. const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
  463. { return container_detail::force_copy<const_reverse_iterator>(m_flat_tree.crend()); }
  464. //////////////////////////////////////////////
  465. //
  466. // capacity
  467. //
  468. //////////////////////////////////////////////
  469. //! <b>Effects</b>: Returns true if the container contains no elements.
  470. //!
  471. //! <b>Throws</b>: Nothing.
  472. //!
  473. //! <b>Complexity</b>: Constant.
  474. bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
  475. { return m_flat_tree.empty(); }
  476. //! <b>Effects</b>: Returns the number of the elements contained in the container.
  477. //!
  478. //! <b>Throws</b>: Nothing.
  479. //!
  480. //! <b>Complexity</b>: Constant.
  481. size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
  482. { return m_flat_tree.size(); }
  483. //! <b>Effects</b>: Returns the largest possible size of the container.
  484. //!
  485. //! <b>Throws</b>: Nothing.
  486. //!
  487. //! <b>Complexity</b>: Constant.
  488. size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
  489. { return m_flat_tree.max_size(); }
  490. //! <b>Effects</b>: Number of elements for which memory has been allocated.
  491. //! capacity() is always greater than or equal to size().
  492. //!
  493. //! <b>Throws</b>: Nothing.
  494. //!
  495. //! <b>Complexity</b>: Constant.
  496. size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW
  497. { return m_flat_tree.capacity(); }
  498. //! <b>Effects</b>: If n is less than or equal to capacity(), this call has no
  499. //! effect. Otherwise, it is a request for allocation of additional memory.
  500. //! If the request is successful, then capacity() is greater than or equal to
  501. //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
  502. //!
  503. //! <b>Throws</b>: If memory allocation allocation throws or T's copy constructor throws.
  504. //!
  505. //! <b>Note</b>: If capacity() is less than "cnt", iterators and references to
  506. //! to values might be invalidated.
  507. void reserve(size_type cnt)
  508. { m_flat_tree.reserve(cnt); }
  509. //! <b>Effects</b>: Tries to deallocate the excess of memory created
  510. // with previous allocations. The size of the vector is unchanged
  511. //!
  512. //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
  513. //!
  514. //! <b>Complexity</b>: Linear to size().
  515. void shrink_to_fit()
  516. { m_flat_tree.shrink_to_fit(); }
  517. //////////////////////////////////////////////
  518. //
  519. // element access
  520. //
  521. //////////////////////////////////////////////
  522. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  523. //! Effects: If there is no key equivalent to x in the flat_map, inserts
  524. //! value_type(x, T()) into the flat_map.
  525. //!
  526. //! Returns: A reference to the mapped_type corresponding to x in *this.
  527. //!
  528. //! Complexity: Logarithmic.
  529. mapped_type &operator[](const key_type& k);
  530. //! Effects: If there is no key equivalent to x in the flat_map, inserts
  531. //! value_type(move(x), T()) into the flat_map (the key is move-constructed)
  532. //!
  533. //! Returns: A reference to the mapped_type corresponding to x in *this.
  534. //!
  535. //! Complexity: Logarithmic.
  536. mapped_type &operator[](key_type &&k) ;
  537. #elif defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN)
  538. //in compilers like GCC 3.4, we can't catch temporaries
  539. mapped_type& operator[](const key_type &k) { return this->priv_subscript(k); }
  540. mapped_type& operator[](BOOST_RV_REF(key_type) k) { return this->priv_subscript(::boost::move(k)); }
  541. #else
  542. BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript)
  543. #endif
  544. //! @copydoc ::boost::container::flat_set::nth(size_type)
  545. iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
  546. { return container_detail::force_copy<iterator>(m_flat_tree.nth(n)); }
  547. //! @copydoc ::boost::container::flat_set::nth(size_type) const
  548. const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
  549. { return container_detail::force_copy<iterator>(m_flat_tree.nth(n)); }
  550. //! @copydoc ::boost::container::flat_set::index_of(iterator)
  551. size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
  552. { return m_flat_tree.index_of(container_detail::force_copy<impl_iterator>(p)); }
  553. //! @copydoc ::boost::container::flat_set::index_of(const_iterator) const
  554. size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
  555. { return m_flat_tree.index_of(container_detail::force_copy<impl_const_iterator>(p)); }
  556. //! Returns: A reference to the element whose key is equivalent to x.
  557. //!
  558. //! Throws: An exception object of type out_of_range if no such element is present.
  559. //!
  560. //! Complexity: logarithmic.
  561. T& at(const key_type& k)
  562. {
  563. iterator i = this->find(k);
  564. if(i == this->end()){
  565. throw_out_of_range("flat_map::at key not found");
  566. }
  567. return i->second;
  568. }
  569. //! Returns: A reference to the element whose key is equivalent to x.
  570. //!
  571. //! Throws: An exception object of type out_of_range if no such element is present.
  572. //!
  573. //! Complexity: logarithmic.
  574. const T& at(const key_type& k) const
  575. {
  576. const_iterator i = this->find(k);
  577. if(i == this->end()){
  578. throw_out_of_range("flat_map::at key not found");
  579. }
  580. return i->second;
  581. }
  582. //////////////////////////////////////////////
  583. //
  584. // modifiers
  585. //
  586. //////////////////////////////////////////////
  587. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  588. //! <b>Effects</b>: Inserts an object x of type T constructed with
  589. //! std::forward<Args>(args)... if and only if there is no element in the container
  590. //! with key equivalent to the key of x.
  591. //!
  592. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  593. //! if the insertion takes place, and the iterator component of the pair
  594. //! points to the element with key equivalent to the key of x.
  595. //!
  596. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  597. //! to the elements with bigger keys than x.
  598. //!
  599. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  600. template <class... Args>
  601. std::pair<iterator,bool> emplace(BOOST_FWD_REF(Args)... args)
  602. { return container_detail::force_copy< std::pair<iterator, bool> >(m_flat_tree.emplace_unique(boost::forward<Args>(args)...)); }
  603. //! <b>Effects</b>: Inserts an object of type T constructed with
  604. //! std::forward<Args>(args)... in the container if and only if there is
  605. //! no element in the container with key equivalent to the key of x.
  606. //! p is a hint pointing to where the insert should start to search.
  607. //!
  608. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  609. //! to the key of x.
  610. //!
  611. //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
  612. //! right before p) plus insertion linear to the elements with bigger keys than x.
  613. //!
  614. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  615. template <class... Args>
  616. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
  617. {
  618. return container_detail::force_copy<iterator>
  619. (m_flat_tree.emplace_hint_unique( container_detail::force_copy<impl_const_iterator>(hint)
  620. , boost::forward<Args>(args)...));
  621. }
  622. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  623. #define BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE(N) \
  624. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  625. std::pair<iterator,bool> emplace(BOOST_MOVE_UREF##N)\
  626. {\
  627. return container_detail::force_copy< std::pair<iterator, bool> >\
  628. (m_flat_tree.emplace_unique(BOOST_MOVE_FWD##N));\
  629. }\
  630. \
  631. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  632. iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  633. {\
  634. return container_detail::force_copy<iterator>(m_flat_tree.emplace_hint_unique\
  635. (container_detail::force_copy<impl_const_iterator>(hint) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
  636. }\
  637. //
  638. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE)
  639. #undef BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE
  640. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  641. //! <b>Effects</b>: Inserts x if and only if there is no element in the container
  642. //! with key equivalent to the key of x.
  643. //!
  644. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  645. //! if the insertion takes place, and the iterator component of the pair
  646. //! points to the element with key equivalent to the key of x.
  647. //!
  648. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  649. //! to the elements with bigger keys than x.
  650. //!
  651. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  652. std::pair<iterator,bool> insert(const value_type& x)
  653. { return container_detail::force_copy<std::pair<iterator,bool> >(
  654. m_flat_tree.insert_unique(container_detail::force<impl_value_type>(x))); }
  655. //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
  656. //! only if there is no element in the container with key equivalent to the key of x.
  657. //!
  658. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  659. //! if the insertion takes place, and the iterator component of the pair
  660. //! points to the element with key equivalent to the key of x.
  661. //!
  662. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  663. //! to the elements with bigger keys than x.
  664. //!
  665. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  666. std::pair<iterator,bool> insert(BOOST_RV_REF(value_type) x)
  667. { return container_detail::force_copy<std::pair<iterator,bool> >(
  668. m_flat_tree.insert_unique(boost::move(container_detail::force<impl_value_type>(x)))); }
  669. //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
  670. //! only if there is no element in the container with key equivalent to the key of x.
  671. //!
  672. //! <b>Returns</b>: The bool component of the returned pair is true if and only
  673. //! if the insertion takes place, and the iterator component of the pair
  674. //! points to the element with key equivalent to the key of x.
  675. //!
  676. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  677. //! to the elements with bigger keys than x.
  678. //!
  679. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  680. std::pair<iterator,bool> insert(BOOST_RV_REF(movable_value_type) x)
  681. {
  682. return container_detail::force_copy<std::pair<iterator,bool> >
  683. (m_flat_tree.insert_unique(boost::move(x)));
  684. }
  685. //! <b>Effects</b>: Inserts a copy of x in the container if and only if there is
  686. //! no element in the container with key equivalent to the key of x.
  687. //! p is a hint pointing to where the insert should start to search.
  688. //!
  689. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  690. //! to the key of x.
  691. //!
  692. //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
  693. //! right before p) plus insertion linear to the elements with bigger keys than x.
  694. //!
  695. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  696. iterator insert(const_iterator p, const value_type& x)
  697. {
  698. return container_detail::force_copy<iterator>(
  699. m_flat_tree.insert_unique( container_detail::force_copy<impl_const_iterator>(p)
  700. , container_detail::force<impl_value_type>(x)));
  701. }
  702. //! <b>Effects</b>: Inserts an element move constructed from x in the container.
  703. //! p is a hint pointing to where the insert should start to search.
  704. //!
  705. //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
  706. //!
  707. //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
  708. //! right before p) plus insertion linear to the elements with bigger keys than x.
  709. //!
  710. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  711. iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
  712. {
  713. return container_detail::force_copy<iterator>
  714. (m_flat_tree.insert_unique( container_detail::force_copy<impl_const_iterator>(p)
  715. , boost::move(container_detail::force<impl_value_type>(x))));
  716. }
  717. //! <b>Effects</b>: Inserts an element move constructed from x in the container.
  718. //! p is a hint pointing to where the insert should start to search.
  719. //!
  720. //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
  721. //!
  722. //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
  723. //! right before p) plus insertion linear to the elements with bigger keys than x.
  724. //!
  725. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  726. iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
  727. {
  728. return container_detail::force_copy<iterator>(
  729. m_flat_tree.insert_unique(container_detail::force_copy<impl_const_iterator>(p), boost::move(x)));
  730. }
  731. //! <b>Requires</b>: first, last are not iterators into *this.
  732. //!
  733. //! <b>Effects</b>: inserts each element from the range [first,last) if and only
  734. //! if there is no element with key equivalent to the key of that element.
  735. //!
  736. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  737. //! search time plus N*size() insertion time.
  738. //!
  739. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  740. template <class InputIterator>
  741. void insert(InputIterator first, InputIterator last)
  742. { m_flat_tree.insert_unique(first, last); }
  743. //! <b>Requires</b>: first, last are not iterators into *this.
  744. //!
  745. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
  746. //! unique values.
  747. //!
  748. //! <b>Effects</b>: inserts each element from the range [first,last) if and only
  749. //! if there is no element with key equivalent to the key of that element. This
  750. //! function is more efficient than the normal range creation for ordered ranges.
  751. //!
  752. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  753. //! search time plus N*size() insertion time.
  754. //!
  755. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  756. //!
  757. //! <b>Note</b>: Non-standard extension.
  758. template <class InputIterator>
  759. void insert(ordered_unique_range_t, InputIterator first, InputIterator last)
  760. { m_flat_tree.insert_unique(ordered_unique_range, first, last); }
  761. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  762. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
  763. //! if there is no element with key equivalent to the key of that element.
  764. //!
  765. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.first() to il.end())
  766. //! search time plus N*size() insertion time.
  767. //!
  768. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  769. void insert(std::initializer_list<value_type> il)
  770. { m_flat_tree.insert_unique(il.begin(), il.end()); }
  771. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
  772. //! unique values.
  773. //!
  774. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
  775. //! if there is no element with key equivalent to the key of that element. This
  776. //! function is more efficient than the normal range creation for ordered ranges.
  777. //!
  778. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  779. //! search time plus N*size() insertion time.
  780. //!
  781. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  782. //!
  783. //! <b>Note</b>: Non-standard extension.
  784. void insert(ordered_unique_range_t, std::initializer_list<value_type> il)
  785. { m_flat_tree.insert_unique(ordered_unique_range, il.begin(), il.end()); }
  786. #endif
  787. //! <b>Effects</b>: Erases the element pointed to by p.
  788. //!
  789. //! <b>Returns</b>: Returns an iterator pointing to the element immediately
  790. //! following q prior to the element being erased. If no such element exists,
  791. //! returns end().
  792. //!
  793. //! <b>Complexity</b>: Linear to the elements with keys bigger than p
  794. //!
  795. //! <b>Note</b>: Invalidates elements with keys
  796. //! not less than the erased element.
  797. iterator erase(const_iterator p)
  798. {
  799. return container_detail::force_copy<iterator>
  800. (m_flat_tree.erase(container_detail::force_copy<impl_const_iterator>(p)));
  801. }
  802. //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
  803. //!
  804. //! <b>Returns</b>: Returns the number of erased elements.
  805. //!
  806. //! <b>Complexity</b>: Logarithmic search time plus erasure time
  807. //! linear to the elements with bigger keys.
  808. size_type erase(const key_type& x)
  809. { return m_flat_tree.erase(x); }
  810. //! <b>Effects</b>: Erases all the elements in the range [first, last).
  811. //!
  812. //! <b>Returns</b>: Returns last.
  813. //!
  814. //! <b>Complexity</b>: size()*N where N is the distance from first to last.
  815. //!
  816. //! <b>Complexity</b>: Logarithmic search time plus erasure time
  817. //! linear to the elements with bigger keys.
  818. iterator erase(const_iterator first, const_iterator last)
  819. {
  820. return container_detail::force_copy<iterator>(
  821. m_flat_tree.erase( container_detail::force_copy<impl_const_iterator>(first)
  822. , container_detail::force_copy<impl_const_iterator>(last)));
  823. }
  824. //! <b>Effects</b>: Swaps the contents of *this and x.
  825. //!
  826. //! <b>Throws</b>: Nothing.
  827. //!
  828. //! <b>Complexity</b>: Constant.
  829. void swap(flat_map& x)
  830. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  831. && boost::container::container_detail::is_nothrow_swappable<Compare>::value )
  832. { m_flat_tree.swap(x.m_flat_tree); }
  833. //! <b>Effects</b>: erase(a.begin(),a.end()).
  834. //!
  835. //! <b>Postcondition</b>: size() == 0.
  836. //!
  837. //! <b>Complexity</b>: linear in size().
  838. void clear() BOOST_NOEXCEPT_OR_NOTHROW
  839. { m_flat_tree.clear(); }
  840. //////////////////////////////////////////////
  841. //
  842. // observers
  843. //
  844. //////////////////////////////////////////////
  845. //! <b>Effects</b>: Returns the comparison object out
  846. //! of which a was constructed.
  847. //!
  848. //! <b>Complexity</b>: Constant.
  849. key_compare key_comp() const
  850. { return container_detail::force_copy<key_compare>(m_flat_tree.key_comp()); }
  851. //! <b>Effects</b>: Returns an object of value_compare constructed out
  852. //! of the comparison object.
  853. //!
  854. //! <b>Complexity</b>: Constant.
  855. value_compare value_comp() const
  856. { return value_compare(container_detail::force_copy<key_compare>(m_flat_tree.key_comp())); }
  857. //////////////////////////////////////////////
  858. //
  859. // map operations
  860. //
  861. //////////////////////////////////////////////
  862. //! <b>Returns</b>: An iterator pointing to an element with the key
  863. //! equivalent to x, or end() if such an element is not found.
  864. //!
  865. //! <b>Complexity</b>: Logarithmic.
  866. iterator find(const key_type& x)
  867. { return container_detail::force_copy<iterator>(m_flat_tree.find(x)); }
  868. //! <b>Returns</b>: A const_iterator pointing to an element with the key
  869. //! equivalent to x, or end() if such an element is not found.
  870. //!
  871. //! <b>Complexity</b>: Logarithmic.
  872. const_iterator find(const key_type& x) const
  873. { return container_detail::force_copy<const_iterator>(m_flat_tree.find(x)); }
  874. //! <b>Returns</b>: The number of elements with key equivalent to x.
  875. //!
  876. //! <b>Complexity</b>: log(size())+count(k)
  877. size_type count(const key_type& x) const
  878. { return static_cast<size_type>(m_flat_tree.find(x) != m_flat_tree.end()); }
  879. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  880. //! than k, or a.end() if such an element is not found.
  881. //!
  882. //! <b>Complexity</b>: Logarithmic.
  883. iterator lower_bound(const key_type& x)
  884. { return container_detail::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
  885. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  886. //! less than k, or a.end() if such an element is not found.
  887. //!
  888. //! <b>Complexity</b>: Logarithmic.
  889. const_iterator lower_bound(const key_type& x) const
  890. { return container_detail::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
  891. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  892. //! than x, or end() if such an element is not found.
  893. //!
  894. //! <b>Complexity</b>: Logarithmic.
  895. iterator upper_bound(const key_type& x)
  896. { return container_detail::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
  897. //! <b>Returns</b>: A const iterator pointing to the first element with key not
  898. //! less than x, or end() if such an element is not found.
  899. //!
  900. //! <b>Complexity</b>: Logarithmic.
  901. const_iterator upper_bound(const key_type& x) const
  902. { return container_detail::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
  903. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  904. //!
  905. //! <b>Complexity</b>: Logarithmic.
  906. std::pair<iterator,iterator> equal_range(const key_type& x)
  907. { return container_detail::force_copy<std::pair<iterator,iterator> >(m_flat_tree.lower_bound_range(x)); }
  908. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  909. //!
  910. //! <b>Complexity</b>: Logarithmic.
  911. std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const
  912. { return container_detail::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.lower_bound_range(x)); }
  913. //! <b>Effects</b>: Returns true if x and y are equal
  914. //!
  915. //! <b>Complexity</b>: Linear to the number of elements in the container.
  916. friend bool operator==(const flat_map& x, const flat_map& y)
  917. { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
  918. //! <b>Effects</b>: Returns true if x and y are unequal
  919. //!
  920. //! <b>Complexity</b>: Linear to the number of elements in the container.
  921. friend bool operator!=(const flat_map& x, const flat_map& y)
  922. { return !(x == y); }
  923. //! <b>Effects</b>: Returns true if x is less than y
  924. //!
  925. //! <b>Complexity</b>: Linear to the number of elements in the container.
  926. friend bool operator<(const flat_map& x, const flat_map& y)
  927. { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  928. //! <b>Effects</b>: Returns true if x is greater than y
  929. //!
  930. //! <b>Complexity</b>: Linear to the number of elements in the container.
  931. friend bool operator>(const flat_map& x, const flat_map& y)
  932. { return y < x; }
  933. //! <b>Effects</b>: Returns true if x is equal or less than y
  934. //!
  935. //! <b>Complexity</b>: Linear to the number of elements in the container.
  936. friend bool operator<=(const flat_map& x, const flat_map& y)
  937. { return !(y < x); }
  938. //! <b>Effects</b>: Returns true if x is equal or greater than y
  939. //!
  940. //! <b>Complexity</b>: Linear to the number of elements in the container.
  941. friend bool operator>=(const flat_map& x, const flat_map& y)
  942. { return !(x < y); }
  943. //! <b>Effects</b>: x.swap(y)
  944. //!
  945. //! <b>Complexity</b>: Constant.
  946. friend void swap(flat_map& x, flat_map& y)
  947. { x.swap(y); }
  948. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  949. private:
  950. mapped_type &priv_subscript(const key_type& k)
  951. {
  952. iterator i = lower_bound(k);
  953. // i->first is greater than or equivalent to k.
  954. if (i == end() || key_comp()(k, (*i).first)){
  955. container_detail::value_init<mapped_type> m;
  956. i = insert(i, impl_value_type(k, ::boost::move(m.m_t)));
  957. }
  958. return (*i).second;
  959. }
  960. mapped_type &priv_subscript(BOOST_RV_REF(key_type) mk)
  961. {
  962. key_type &k = mk;
  963. iterator i = lower_bound(k);
  964. // i->first is greater than or equivalent to k.
  965. if (i == end() || key_comp()(k, (*i).first)){
  966. container_detail::value_init<mapped_type> m;
  967. i = insert(i, impl_value_type(boost::move(k), ::boost::move(m.m_t)));
  968. }
  969. return (*i).second;
  970. }
  971. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  972. };
  973. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  974. } //namespace container {
  975. //!has_trivial_destructor_after_move<> == true_type
  976. //!specialization for optimizations
  977. template <class Key, class T, class Compare, class Allocator>
  978. struct has_trivial_destructor_after_move<boost::container::flat_map<Key, T, Compare, Allocator> >
  979. {
  980. typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
  981. static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
  982. ::boost::has_trivial_destructor_after_move<pointer>::value &&
  983. ::boost::has_trivial_destructor_after_move<Compare>::value;
  984. };
  985. namespace container {
  986. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  987. //! A flat_multimap is a kind of associative container that supports equivalent keys
  988. //! (possibly containing multiple copies of the same key value) and provides for
  989. //! fast retrieval of values of another type T based on the keys. The flat_multimap
  990. //! class supports random-access iterators.
  991. //!
  992. //! A flat_multimap satisfies all of the requirements of a container and of a reversible
  993. //! container and of an associative container. For a
  994. //! flat_multimap<Key,T> the key_type is Key and the value_type is std::pair<Key,T>
  995. //! (unlike std::multimap<Key, T> which value_type is std::pair<<b>const</b> Key, T>).
  996. //!
  997. //! Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
  998. //!
  999. //! Allocator is the allocator to allocate the value_types
  1000. //! (e.g. <i>allocator< std::pair<Key, T> ></i>).
  1001. //!
  1002. //! flat_multimap is similar to std::multimap but it's implemented like an ordered vector.
  1003. //! This means that inserting a new element into a flat_map invalidates
  1004. //! previous iterators and references
  1005. //!
  1006. //! Erasing an element invalidates iterators and references
  1007. //! pointing to elements that come after (their keys are bigger) the erased element.
  1008. //!
  1009. //! This container provides random-access iterators.
  1010. //!
  1011. //! \tparam Key is the key_type of the map
  1012. //! \tparam Value is the <code>mapped_type</code>
  1013. //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
  1014. //! \tparam Allocator is the allocator to allocate the <code>value_type</code>s
  1015. //! (e.g. <i>allocator< std::pair<Key, T> > </i>).
  1016. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  1017. template <class Key, class T, class Compare = std::less<Key>, class Allocator = new_allocator< std::pair< Key, T> > >
  1018. #else
  1019. template <class Key, class T, class Compare, class Allocator>
  1020. #endif
  1021. class flat_multimap
  1022. {
  1023. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1024. private:
  1025. BOOST_COPYABLE_AND_MOVABLE(flat_multimap)
  1026. typedef container_detail::flat_tree<Key,
  1027. std::pair<Key, T>,
  1028. container_detail::select1st< std::pair<Key, T> >,
  1029. Compare,
  1030. Allocator> tree_t;
  1031. //This is the real tree stored here. It's based on a movable pair
  1032. typedef container_detail::flat_tree<Key,
  1033. container_detail::pair<Key, T>,
  1034. container_detail::select1st<container_detail::pair<Key, T> >,
  1035. Compare,
  1036. typename allocator_traits<Allocator>::template portable_rebind_alloc
  1037. <container_detail::pair<Key, T> >::type> impl_tree_t;
  1038. impl_tree_t m_flat_tree; // flat tree representing flat_map
  1039. typedef typename impl_tree_t::value_type impl_value_type;
  1040. typedef typename impl_tree_t::const_iterator impl_const_iterator;
  1041. typedef typename impl_tree_t::iterator impl_iterator;
  1042. typedef typename impl_tree_t::allocator_type impl_allocator_type;
  1043. typedef container_detail::flat_tree_value_compare
  1044. < Compare
  1045. , container_detail::select1st< std::pair<Key, T> >
  1046. , std::pair<Key, T> > value_compare_impl;
  1047. typedef typename container_detail::get_flat_tree_iterators
  1048. <typename allocator_traits<Allocator>::pointer>::iterator iterator_impl;
  1049. typedef typename container_detail::get_flat_tree_iterators
  1050. <typename allocator_traits<Allocator>::pointer>::const_iterator const_iterator_impl;
  1051. typedef typename container_detail::get_flat_tree_iterators
  1052. <typename allocator_traits<Allocator>::pointer>::reverse_iterator reverse_iterator_impl;
  1053. typedef typename container_detail::get_flat_tree_iterators
  1054. <typename allocator_traits<Allocator>::pointer>::const_reverse_iterator const_reverse_iterator_impl;
  1055. public:
  1056. typedef typename impl_tree_t::stored_allocator_type impl_stored_allocator_type;
  1057. private:
  1058. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1059. public:
  1060. //////////////////////////////////////////////
  1061. //
  1062. // types
  1063. //
  1064. //////////////////////////////////////////////
  1065. typedef Key key_type;
  1066. typedef T mapped_type;
  1067. typedef std::pair<Key, T> value_type;
  1068. typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
  1069. typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
  1070. typedef typename boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
  1071. typedef typename boost::container::allocator_traits<Allocator>::reference reference;
  1072. typedef typename boost::container::allocator_traits<Allocator>::const_reference const_reference;
  1073. typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
  1074. typedef typename boost::container::allocator_traits<Allocator>::difference_type difference_type;
  1075. typedef Allocator allocator_type;
  1076. typedef BOOST_CONTAINER_IMPDEF(Allocator) stored_allocator_type;
  1077. typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
  1078. typedef Compare key_compare;
  1079. typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator;
  1080. typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator;
  1081. typedef BOOST_CONTAINER_IMPDEF(reverse_iterator_impl) reverse_iterator;
  1082. typedef BOOST_CONTAINER_IMPDEF(const_reverse_iterator_impl) const_reverse_iterator;
  1083. typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type;
  1084. //////////////////////////////////////////////
  1085. //
  1086. // construct/copy/destroy
  1087. //
  1088. //////////////////////////////////////////////
  1089. //! <b>Effects</b>: Default constructs an empty flat_map.
  1090. //!
  1091. //! <b>Complexity</b>: Constant.
  1092. flat_multimap()
  1093. : m_flat_tree()
  1094. {
  1095. //A type must be std::pair<Key, T>
  1096. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1097. }
  1098. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison
  1099. //! object and allocator.
  1100. //!
  1101. //! <b>Complexity</b>: Constant.
  1102. explicit flat_multimap(const Compare& comp,
  1103. const allocator_type& a = allocator_type())
  1104. : m_flat_tree(comp, container_detail::force<impl_allocator_type>(a))
  1105. {
  1106. //A type must be std::pair<Key, T>
  1107. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1108. }
  1109. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified allocator.
  1110. //!
  1111. //! <b>Complexity</b>: Constant.
  1112. explicit flat_multimap(const allocator_type& a)
  1113. : m_flat_tree(container_detail::force<impl_allocator_type>(a))
  1114. {
  1115. //A type must be std::pair<Key, T>
  1116. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1117. }
  1118. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object
  1119. //! and allocator, and inserts elements from the range [first ,last ).
  1120. //!
  1121. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1122. //! comp and otherwise N logN, where N is last - first.
  1123. template <class InputIterator>
  1124. flat_multimap(InputIterator first, InputIterator last,
  1125. const Compare& comp = Compare(),
  1126. const allocator_type& a = allocator_type())
  1127. : m_flat_tree(false, first, last, comp, container_detail::force<impl_allocator_type>(a))
  1128. {
  1129. //A type must be std::pair<Key, T>
  1130. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1131. }
  1132. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified
  1133. //! allocator, and inserts elements from the range [first ,last ).
  1134. //!
  1135. //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
  1136. //! comp and otherwise N logN, where N is last - first.
  1137. template <class InputIterator>
  1138. flat_multimap(InputIterator first, InputIterator last, const allocator_type& a)
  1139. : m_flat_tree(false, first, last, Compare(), container_detail::force<impl_allocator_type>(a))
  1140. {
  1141. //A type must be std::pair<Key, T>
  1142. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1143. }
  1144. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
  1145. //! allocator, and inserts elements from the ordered range [first ,last). This function
  1146. //! is more efficient than the normal range creation for ordered ranges.
  1147. //!
  1148. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1149. //!
  1150. //! <b>Complexity</b>: Linear in N.
  1151. //!
  1152. //! <b>Note</b>: Non-standard extension.
  1153. template <class InputIterator>
  1154. flat_multimap(ordered_range_t, InputIterator first, InputIterator last,
  1155. const Compare& comp = Compare(),
  1156. const allocator_type& a = allocator_type())
  1157. : m_flat_tree(ordered_range, first, last, comp, a)
  1158. {
  1159. //A type must be std::pair<Key, T>
  1160. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1161. }
  1162. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1163. //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
  1164. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  1165. //!
  1166. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  1167. //! comp and otherwise N logN, where N is last - first.
  1168. flat_multimap(std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
  1169. : m_flat_tree(false, il.begin(), il.end(), comp, container_detail::force<impl_allocator_type>(a))
  1170. {
  1171. //A type must be std::pair<Key, T>
  1172. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1173. }
  1174. //! <b>Effects</b>: Constructs an empty flat_map using the specified
  1175. //! allocator, and inserts elements from the range [il.begin(), il.end()).
  1176. //!
  1177. //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
  1178. //! comp and otherwise N logN, where N is last - first.
  1179. flat_multimap(std::initializer_list<value_type> il, const allocator_type& a)
  1180. : m_flat_tree(false, il.begin(), il.end(), Compare(), container_detail::force<impl_allocator_type>(a))
  1181. {
  1182. //A type must be std::pair<Key, T>
  1183. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1184. }
  1185. //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
  1186. //! allocator, and inserts elements from the ordered range [il.begin(), il.end()). This function
  1187. //! is more efficient than the normal range creation for ordered ranges.
  1188. //!
  1189. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1190. //!
  1191. //! <b>Complexity</b>: Linear in N.
  1192. //!
  1193. //! <b>Note</b>: Non-standard extension.
  1194. flat_multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(),
  1195. const allocator_type& a = allocator_type())
  1196. : m_flat_tree(ordered_range, il.begin(), il.end(), comp, a)
  1197. {
  1198. //A type must be std::pair<Key, T>
  1199. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1200. }
  1201. #endif
  1202. //! <b>Effects</b>: Copy constructs a flat_multimap.
  1203. //!
  1204. //! <b>Complexity</b>: Linear in x.size().
  1205. flat_multimap(const flat_multimap& x)
  1206. : m_flat_tree(x.m_flat_tree)
  1207. {
  1208. //A type must be std::pair<Key, T>
  1209. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1210. }
  1211. //! <b>Effects</b>: Move constructs a flat_multimap. Constructs *this using x's resources.
  1212. //!
  1213. //! <b>Complexity</b>: Constant.
  1214. //!
  1215. //! <b>Postcondition</b>: x is emptied.
  1216. flat_multimap(BOOST_RV_REF(flat_multimap) x)
  1217. : m_flat_tree(boost::move(x.m_flat_tree))
  1218. {
  1219. //A type must be std::pair<Key, T>
  1220. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1221. }
  1222. //! <b>Effects</b>: Copy constructs a flat_multimap using the specified allocator.
  1223. //!
  1224. //! <b>Complexity</b>: Linear in x.size().
  1225. flat_multimap(const flat_multimap& x, const allocator_type &a)
  1226. : m_flat_tree(x.m_flat_tree, a)
  1227. {
  1228. //A type must be std::pair<Key, T>
  1229. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1230. }
  1231. //! <b>Effects</b>: Move constructs a flat_multimap using the specified allocator.
  1232. //! Constructs *this using x's resources.
  1233. //!
  1234. //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
  1235. flat_multimap(BOOST_RV_REF(flat_multimap) x, const allocator_type &a)
  1236. : m_flat_tree(boost::move(x.m_flat_tree), a)
  1237. {
  1238. //A type must be std::pair<Key, T>
  1239. BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<Key, T>, typename Allocator::value_type>::value));
  1240. }
  1241. //! <b>Effects</b>: Makes *this a copy of x.
  1242. //!
  1243. //! <b>Complexity</b>: Linear in x.size().
  1244. flat_multimap& operator=(BOOST_COPY_ASSIGN_REF(flat_multimap) x)
  1245. { m_flat_tree = x.m_flat_tree; return *this; }
  1246. //! <b>Effects</b>: this->swap(x.get()).
  1247. //!
  1248. //! <b>Complexity</b>: Constant.
  1249. flat_multimap& operator=(BOOST_RV_REF(flat_multimap) x)
  1250. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  1251. && boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
  1252. { m_flat_tree = boost::move(x.m_flat_tree); return *this; }
  1253. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1254. //! <b>Effects</b>: Assign content of il to *this
  1255. //!
  1256. //! <b>Complexity</b>: Linear in il.size().
  1257. flat_multimap& operator=(std::initializer_list<value_type> il)
  1258. {
  1259. this->clear();
  1260. this->insert(il.begin(), il.end());
  1261. return *this;
  1262. }
  1263. #endif
  1264. //! <b>Effects</b>: Returns a copy of the allocator that
  1265. //! was passed to the object's constructor.
  1266. //!
  1267. //! <b>Complexity</b>: Constant.
  1268. allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  1269. { return container_detail::force_copy<allocator_type>(m_flat_tree.get_allocator()); }
  1270. //! <b>Effects</b>: Returns a reference to the internal allocator.
  1271. //!
  1272. //! <b>Throws</b>: Nothing
  1273. //!
  1274. //! <b>Complexity</b>: Constant.
  1275. //!
  1276. //! <b>Note</b>: Non-standard extension.
  1277. stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
  1278. { return container_detail::force<stored_allocator_type>(m_flat_tree.get_stored_allocator()); }
  1279. //! <b>Effects</b>: Returns a reference to the internal allocator.
  1280. //!
  1281. //! <b>Throws</b>: Nothing
  1282. //!
  1283. //! <b>Complexity</b>: Constant.
  1284. //!
  1285. //! <b>Note</b>: Non-standard extension.
  1286. const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  1287. { return container_detail::force<stored_allocator_type>(m_flat_tree.get_stored_allocator()); }
  1288. //////////////////////////////////////////////
  1289. //
  1290. // iterators
  1291. //
  1292. //////////////////////////////////////////////
  1293. //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
  1294. //!
  1295. //! <b>Throws</b>: Nothing.
  1296. //!
  1297. //! <b>Complexity</b>: Constant.
  1298. iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
  1299. { return container_detail::force_copy<iterator>(m_flat_tree.begin()); }
  1300. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  1301. //!
  1302. //! <b>Throws</b>: Nothing.
  1303. //!
  1304. //! <b>Complexity</b>: Constant.
  1305. const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
  1306. { return container_detail::force_copy<const_iterator>(m_flat_tree.begin()); }
  1307. //! <b>Effects</b>: Returns an iterator to the end of the container.
  1308. //!
  1309. //! <b>Throws</b>: Nothing.
  1310. //!
  1311. //! <b>Complexity</b>: Constant.
  1312. iterator end() BOOST_NOEXCEPT_OR_NOTHROW
  1313. { return container_detail::force_copy<iterator>(m_flat_tree.end()); }
  1314. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  1315. //!
  1316. //! <b>Throws</b>: Nothing.
  1317. //!
  1318. //! <b>Complexity</b>: Constant.
  1319. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
  1320. { return container_detail::force_copy<const_iterator>(m_flat_tree.end()); }
  1321. //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
  1322. //! of the reversed container.
  1323. //!
  1324. //! <b>Throws</b>: Nothing.
  1325. //!
  1326. //! <b>Complexity</b>: Constant.
  1327. reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
  1328. { return container_detail::force_copy<reverse_iterator>(m_flat_tree.rbegin()); }
  1329. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  1330. //! of the reversed container.
  1331. //!
  1332. //! <b>Throws</b>: Nothing.
  1333. //!
  1334. //! <b>Complexity</b>: Constant.
  1335. const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  1336. { return container_detail::force_copy<const_reverse_iterator>(m_flat_tree.rbegin()); }
  1337. //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
  1338. //! of the reversed container.
  1339. //!
  1340. //! <b>Throws</b>: Nothing.
  1341. //!
  1342. //! <b>Complexity</b>: Constant.
  1343. reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
  1344. { return container_detail::force_copy<reverse_iterator>(m_flat_tree.rend()); }
  1345. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  1346. //! of the reversed container.
  1347. //!
  1348. //! <b>Throws</b>: Nothing.
  1349. //!
  1350. //! <b>Complexity</b>: Constant.
  1351. const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
  1352. { return container_detail::force_copy<const_reverse_iterator>(m_flat_tree.rend()); }
  1353. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  1354. //!
  1355. //! <b>Throws</b>: Nothing.
  1356. //!
  1357. //! <b>Complexity</b>: Constant.
  1358. const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  1359. { return container_detail::force_copy<const_iterator>(m_flat_tree.cbegin()); }
  1360. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  1361. //!
  1362. //! <b>Throws</b>: Nothing.
  1363. //!
  1364. //! <b>Complexity</b>: Constant.
  1365. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
  1366. { return container_detail::force_copy<const_iterator>(m_flat_tree.cend()); }
  1367. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  1368. //! of the reversed container.
  1369. //!
  1370. //! <b>Throws</b>: Nothing.
  1371. //!
  1372. //! <b>Complexity</b>: Constant.
  1373. const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  1374. { return container_detail::force_copy<const_reverse_iterator>(m_flat_tree.crbegin()); }
  1375. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  1376. //! of the reversed container.
  1377. //!
  1378. //! <b>Throws</b>: Nothing.
  1379. //!
  1380. //! <b>Complexity</b>: Constant.
  1381. const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
  1382. { return container_detail::force_copy<const_reverse_iterator>(m_flat_tree.crend()); }
  1383. //////////////////////////////////////////////
  1384. //
  1385. // capacity
  1386. //
  1387. //////////////////////////////////////////////
  1388. //! <b>Effects</b>: Returns true if the container contains no elements.
  1389. //!
  1390. //! <b>Throws</b>: Nothing.
  1391. //!
  1392. //! <b>Complexity</b>: Constant.
  1393. bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
  1394. { return m_flat_tree.empty(); }
  1395. //! <b>Effects</b>: Returns the number of the elements contained in the container.
  1396. //!
  1397. //! <b>Throws</b>: Nothing.
  1398. //!
  1399. //! <b>Complexity</b>: Constant.
  1400. size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
  1401. { return m_flat_tree.size(); }
  1402. //! <b>Effects</b>: Returns the largest possible size of the container.
  1403. //!
  1404. //! <b>Throws</b>: Nothing.
  1405. //!
  1406. //! <b>Complexity</b>: Constant.
  1407. size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
  1408. { return m_flat_tree.max_size(); }
  1409. //! <b>Effects</b>: Number of elements for which memory has been allocated.
  1410. //! capacity() is always greater than or equal to size().
  1411. //!
  1412. //! <b>Throws</b>: Nothing.
  1413. //!
  1414. //! <b>Complexity</b>: Constant.
  1415. size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW
  1416. { return m_flat_tree.capacity(); }
  1417. //! <b>Effects</b>: If n is less than or equal to capacity(), this call has no
  1418. //! effect. Otherwise, it is a request for allocation of additional memory.
  1419. //! If the request is successful, then capacity() is greater than or equal to
  1420. //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
  1421. //!
  1422. //! <b>Throws</b>: If memory allocation allocation throws or T's copy constructor throws.
  1423. //!
  1424. //! <b>Note</b>: If capacity() is less than "cnt", iterators and references to
  1425. //! to values might be invalidated.
  1426. void reserve(size_type cnt)
  1427. { m_flat_tree.reserve(cnt); }
  1428. //! <b>Effects</b>: Tries to deallocate the excess of memory created
  1429. // with previous allocations. The size of the vector is unchanged
  1430. //!
  1431. //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
  1432. //!
  1433. //! <b>Complexity</b>: Linear to size().
  1434. void shrink_to_fit()
  1435. { m_flat_tree.shrink_to_fit(); }
  1436. //! @copydoc ::boost::container::flat_set::nth(size_type)
  1437. iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
  1438. { return container_detail::force_copy<iterator>(m_flat_tree.nth(n)); }
  1439. //! @copydoc ::boost::container::flat_set::nth(size_type) const
  1440. const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
  1441. { return container_detail::force_copy<iterator>(m_flat_tree.nth(n)); }
  1442. //! @copydoc ::boost::container::flat_set::index_of(iterator)
  1443. size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
  1444. { return m_flat_tree.index_of(container_detail::force_copy<impl_iterator>(p)); }
  1445. //! @copydoc ::boost::container::flat_set::index_of(const_iterator) const
  1446. size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
  1447. { return m_flat_tree.index_of(container_detail::force_copy<impl_const_iterator>(p)); }
  1448. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1449. //! <b>Effects</b>: Inserts an object of type T constructed with
  1450. //! std::forward<Args>(args)... and returns the iterator pointing to the
  1451. //! newly inserted element.
  1452. //!
  1453. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  1454. //! to the elements with bigger keys than x.
  1455. //!
  1456. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1457. template <class... Args>
  1458. iterator emplace(BOOST_FWD_REF(Args)... args)
  1459. { return container_detail::force_copy<iterator>(m_flat_tree.emplace_equal(boost::forward<Args>(args)...)); }
  1460. //! <b>Effects</b>: Inserts an object of type T constructed with
  1461. //! std::forward<Args>(args)... in the container.
  1462. //! p is a hint pointing to where the insert should start to search.
  1463. //!
  1464. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1465. //! to the key of x.
  1466. //!
  1467. //! <b>Complexity</b>: Logarithmic search time (constant time if the value
  1468. //! is to be inserted before p) plus linear insertion
  1469. //! to the elements with bigger keys than x.
  1470. //!
  1471. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1472. template <class... Args>
  1473. iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
  1474. {
  1475. return container_detail::force_copy<iterator>(m_flat_tree.emplace_hint_equal
  1476. (container_detail::force_copy<impl_const_iterator>(hint), boost::forward<Args>(args)...));
  1477. }
  1478. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  1479. #define BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE(N) \
  1480. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  1481. iterator emplace(BOOST_MOVE_UREF##N)\
  1482. { return container_detail::force_copy<iterator>(m_flat_tree.emplace_equal(BOOST_MOVE_FWD##N)); }\
  1483. \
  1484. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  1485. iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  1486. {\
  1487. return container_detail::force_copy<iterator>(m_flat_tree.emplace_hint_equal\
  1488. (container_detail::force_copy<impl_const_iterator>(hint) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
  1489. }\
  1490. //
  1491. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE)
  1492. #undef BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE
  1493. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  1494. //! <b>Effects</b>: Inserts x and returns the iterator pointing to the
  1495. //! newly inserted element.
  1496. //!
  1497. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  1498. //! to the elements with bigger keys than x.
  1499. //!
  1500. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1501. iterator insert(const value_type& x)
  1502. {
  1503. return container_detail::force_copy<iterator>(
  1504. m_flat_tree.insert_equal(container_detail::force<impl_value_type>(x)));
  1505. }
  1506. //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
  1507. //! the iterator pointing to the newly inserted element.
  1508. //!
  1509. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  1510. //! to the elements with bigger keys than x.
  1511. //!
  1512. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1513. iterator insert(BOOST_RV_REF(value_type) x)
  1514. { return container_detail::force_copy<iterator>(m_flat_tree.insert_equal(boost::move(x))); }
  1515. //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
  1516. //! the iterator pointing to the newly inserted element.
  1517. //!
  1518. //! <b>Complexity</b>: Logarithmic search time plus linear insertion
  1519. //! to the elements with bigger keys than x.
  1520. //!
  1521. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1522. iterator insert(BOOST_RV_REF(impl_value_type) x)
  1523. { return container_detail::force_copy<iterator>(m_flat_tree.insert_equal(boost::move(x))); }
  1524. //! <b>Effects</b>: Inserts a copy of x in the container.
  1525. //! p is a hint pointing to where the insert should start to search.
  1526. //!
  1527. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1528. //! to the key of x.
  1529. //!
  1530. //! <b>Complexity</b>: Logarithmic search time (constant time if the value
  1531. //! is to be inserted before p) plus linear insertion
  1532. //! to the elements with bigger keys than x.
  1533. //!
  1534. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1535. iterator insert(const_iterator p, const value_type& x)
  1536. {
  1537. return container_detail::force_copy<iterator>
  1538. (m_flat_tree.insert_equal( container_detail::force_copy<impl_const_iterator>(p)
  1539. , container_detail::force<impl_value_type>(x)));
  1540. }
  1541. //! <b>Effects</b>: Inserts a value move constructed from x in the container.
  1542. //! p is a hint pointing to where the insert should start to search.
  1543. //!
  1544. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1545. //! to the key of x.
  1546. //!
  1547. //! <b>Complexity</b>: Logarithmic search time (constant time if the value
  1548. //! is to be inserted before p) plus linear insertion
  1549. //! to the elements with bigger keys than x.
  1550. //!
  1551. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1552. iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
  1553. {
  1554. return container_detail::force_copy<iterator>
  1555. (m_flat_tree.insert_equal(container_detail::force_copy<impl_const_iterator>(p)
  1556. , boost::move(x)));
  1557. }
  1558. //! <b>Effects</b>: Inserts a value move constructed from x in the container.
  1559. //! p is a hint pointing to where the insert should start to search.
  1560. //!
  1561. //! <b>Returns</b>: An iterator pointing to the element with key equivalent
  1562. //! to the key of x.
  1563. //!
  1564. //! <b>Complexity</b>: Logarithmic search time (constant time if the value
  1565. //! is to be inserted before p) plus linear insertion
  1566. //! to the elements with bigger keys than x.
  1567. //!
  1568. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1569. iterator insert(const_iterator p, BOOST_RV_REF(impl_value_type) x)
  1570. {
  1571. return container_detail::force_copy<iterator>(
  1572. m_flat_tree.insert_equal(container_detail::force_copy<impl_const_iterator>(p), boost::move(x)));
  1573. }
  1574. //! <b>Requires</b>: first, last are not iterators into *this.
  1575. //!
  1576. //! <b>Effects</b>: inserts each element from the range [first,last) .
  1577. //!
  1578. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  1579. //! search time plus N*size() insertion time.
  1580. //!
  1581. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1582. template <class InputIterator>
  1583. void insert(InputIterator first, InputIterator last)
  1584. { m_flat_tree.insert_equal(first, last); }
  1585. //! <b>Requires</b>: first, last are not iterators into *this.
  1586. //!
  1587. //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
  1588. //!
  1589. //! <b>Effects</b>: inserts each element from the range [first,last) if and only
  1590. //! if there is no element with key equivalent to the key of that element. This
  1591. //! function is more efficient than the normal range creation for ordered ranges.
  1592. //!
  1593. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  1594. //! search time plus N*size() insertion time.
  1595. //!
  1596. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1597. //!
  1598. //! <b>Note</b>: Non-standard extension.
  1599. template <class InputIterator>
  1600. void insert(ordered_range_t, InputIterator first, InputIterator last)
  1601. { m_flat_tree.insert_equal(ordered_range, first, last); }
  1602. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1603. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) .
  1604. //!
  1605. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  1606. //! search time plus N*size() insertion time.
  1607. //!
  1608. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1609. void insert(std::initializer_list<value_type> il)
  1610. { m_flat_tree.insert_equal(il.begin(), il.end()); }
  1611. //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
  1612. //!
  1613. //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
  1614. //! if there is no element with key equivalent to the key of that element. This
  1615. //! function is more efficient than the normal range creation for ordered ranges.
  1616. //!
  1617. //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
  1618. //! search time plus N*size() insertion time.
  1619. //!
  1620. //! <b>Note</b>: If an element is inserted it might invalidate elements.
  1621. //!
  1622. //! <b>Note</b>: Non-standard extension.
  1623. void insert(ordered_range_t, std::initializer_list<value_type> il)
  1624. { m_flat_tree.insert_equal(ordered_range, il.begin(), il.end()); }
  1625. #endif
  1626. //! <b>Effects</b>: Erases the element pointed to by p.
  1627. //!
  1628. //! <b>Returns</b>: Returns an iterator pointing to the element immediately
  1629. //! following q prior to the element being erased. If no such element exists,
  1630. //! returns end().
  1631. //!
  1632. //! <b>Complexity</b>: Linear to the elements with keys bigger than p
  1633. //!
  1634. //! <b>Note</b>: Invalidates elements with keys
  1635. //! not less than the erased element.
  1636. iterator erase(const_iterator p)
  1637. {
  1638. return container_detail::force_copy<iterator>(
  1639. m_flat_tree.erase(container_detail::force_copy<impl_const_iterator>(p)));
  1640. }
  1641. //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
  1642. //!
  1643. //! <b>Returns</b>: Returns the number of erased elements.
  1644. //!
  1645. //! <b>Complexity</b>: Logarithmic search time plus erasure time
  1646. //! linear to the elements with bigger keys.
  1647. size_type erase(const key_type& x)
  1648. { return m_flat_tree.erase(x); }
  1649. //! <b>Effects</b>: Erases all the elements in the range [first, last).
  1650. //!
  1651. //! <b>Returns</b>: Returns last.
  1652. //!
  1653. //! <b>Complexity</b>: size()*N where N is the distance from first to last.
  1654. //!
  1655. //! <b>Complexity</b>: Logarithmic search time plus erasure time
  1656. //! linear to the elements with bigger keys.
  1657. iterator erase(const_iterator first, const_iterator last)
  1658. {
  1659. return container_detail::force_copy<iterator>
  1660. (m_flat_tree.erase( container_detail::force_copy<impl_const_iterator>(first)
  1661. , container_detail::force_copy<impl_const_iterator>(last)));
  1662. }
  1663. //! <b>Effects</b>: Swaps the contents of *this and x.
  1664. //!
  1665. //! <b>Throws</b>: Nothing.
  1666. //!
  1667. //! <b>Complexity</b>: Constant.
  1668. void swap(flat_multimap& x)
  1669. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  1670. && boost::container::container_detail::is_nothrow_swappable<Compare>::value )
  1671. { m_flat_tree.swap(x.m_flat_tree); }
  1672. //! <b>Effects</b>: erase(a.begin(),a.end()).
  1673. //!
  1674. //! <b>Postcondition</b>: size() == 0.
  1675. //!
  1676. //! <b>Complexity</b>: linear in size().
  1677. void clear() BOOST_NOEXCEPT_OR_NOTHROW
  1678. { m_flat_tree.clear(); }
  1679. //////////////////////////////////////////////
  1680. //
  1681. // observers
  1682. //
  1683. //////////////////////////////////////////////
  1684. //! <b>Effects</b>: Returns the comparison object out
  1685. //! of which a was constructed.
  1686. //!
  1687. //! <b>Complexity</b>: Constant.
  1688. key_compare key_comp() const
  1689. { return container_detail::force_copy<key_compare>(m_flat_tree.key_comp()); }
  1690. //! <b>Effects</b>: Returns an object of value_compare constructed out
  1691. //! of the comparison object.
  1692. //!
  1693. //! <b>Complexity</b>: Constant.
  1694. value_compare value_comp() const
  1695. { return value_compare(container_detail::force_copy<key_compare>(m_flat_tree.key_comp())); }
  1696. //////////////////////////////////////////////
  1697. //
  1698. // map operations
  1699. //
  1700. //////////////////////////////////////////////
  1701. //! <b>Returns</b>: An iterator pointing to an element with the key
  1702. //! equivalent to x, or end() if such an element is not found.
  1703. //!
  1704. //! <b>Complexity</b>: Logarithmic.
  1705. iterator find(const key_type& x)
  1706. { return container_detail::force_copy<iterator>(m_flat_tree.find(x)); }
  1707. //! <b>Returns</b>: An const_iterator pointing to an element with the key
  1708. //! equivalent to x, or end() if such an element is not found.
  1709. //!
  1710. //! <b>Complexity</b>: Logarithmic.
  1711. const_iterator find(const key_type& x) const
  1712. { return container_detail::force_copy<const_iterator>(m_flat_tree.find(x)); }
  1713. //! <b>Returns</b>: The number of elements with key equivalent to x.
  1714. //!
  1715. //! <b>Complexity</b>: log(size())+count(k)
  1716. size_type count(const key_type& x) const
  1717. { return m_flat_tree.count(x); }
  1718. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1719. //! than k, or a.end() if such an element is not found.
  1720. //!
  1721. //! <b>Complexity</b>: Logarithmic
  1722. iterator lower_bound(const key_type& x)
  1723. { return container_detail::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
  1724. //! <b>Returns</b>: A const iterator pointing to the first element with key
  1725. //! not less than k, or a.end() if such an element is not found.
  1726. //!
  1727. //! <b>Complexity</b>: Logarithmic
  1728. const_iterator lower_bound(const key_type& x) const
  1729. { return container_detail::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
  1730. //! <b>Returns</b>: An iterator pointing to the first element with key not less
  1731. //! than x, or end() if such an element is not found.
  1732. //!
  1733. //! <b>Complexity</b>: Logarithmic
  1734. iterator upper_bound(const key_type& x)
  1735. {return container_detail::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
  1736. //! <b>Returns</b>: A const iterator pointing to the first element with key
  1737. //! not less than x, or end() if such an element is not found.
  1738. //!
  1739. //! <b>Complexity</b>: Logarithmic
  1740. const_iterator upper_bound(const key_type& x) const
  1741. { return container_detail::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
  1742. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1743. //!
  1744. //! <b>Complexity</b>: Logarithmic
  1745. std::pair<iterator,iterator> equal_range(const key_type& x)
  1746. { return container_detail::force_copy<std::pair<iterator,iterator> >(m_flat_tree.equal_range(x)); }
  1747. //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
  1748. //!
  1749. //! <b>Complexity</b>: Logarithmic
  1750. std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const
  1751. { return container_detail::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.equal_range(x)); }
  1752. //! <b>Effects</b>: Returns true if x and y are equal
  1753. //!
  1754. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1755. friend bool operator==(const flat_multimap& x, const flat_multimap& y)
  1756. { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
  1757. //! <b>Effects</b>: Returns true if x and y are unequal
  1758. //!
  1759. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1760. friend bool operator!=(const flat_multimap& x, const flat_multimap& y)
  1761. { return !(x == y); }
  1762. //! <b>Effects</b>: Returns true if x is less than y
  1763. //!
  1764. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1765. friend bool operator<(const flat_multimap& x, const flat_multimap& y)
  1766. { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  1767. //! <b>Effects</b>: Returns true if x is greater than y
  1768. //!
  1769. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1770. friend bool operator>(const flat_multimap& x, const flat_multimap& y)
  1771. { return y < x; }
  1772. //! <b>Effects</b>: Returns true if x is equal or less than y
  1773. //!
  1774. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1775. friend bool operator<=(const flat_multimap& x, const flat_multimap& y)
  1776. { return !(y < x); }
  1777. //! <b>Effects</b>: Returns true if x is equal or greater than y
  1778. //!
  1779. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1780. friend bool operator>=(const flat_multimap& x, const flat_multimap& y)
  1781. { return !(x < y); }
  1782. //! <b>Effects</b>: x.swap(y)
  1783. //!
  1784. //! <b>Complexity</b>: Constant.
  1785. friend void swap(flat_multimap& x, flat_multimap& y)
  1786. { x.swap(y); }
  1787. };
  1788. }}
  1789. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1790. namespace boost {
  1791. //!has_trivial_destructor_after_move<> == true_type
  1792. //!specialization for optimizations
  1793. template <class Key, class T, class Compare, class Allocator>
  1794. struct has_trivial_destructor_after_move< boost::container::flat_multimap<Key, T, Compare, Allocator> >
  1795. {
  1796. typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
  1797. static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
  1798. ::boost::has_trivial_destructor_after_move<pointer>::value &&
  1799. ::boost::has_trivial_destructor_after_move<Compare>::value;
  1800. };
  1801. } //namespace boost {
  1802. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1803. #include <boost/container/detail/config_end.hpp>
  1804. #endif // BOOST_CONTAINER_FLAT_MAP_HPP