multi_index_container.hpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  1. /* Multiply indexed container.
  2. *
  3. * Copyright 2003-2020 Joaquin M Lopez Munoz.
  4. * Distributed under the Boost Software License, Version 1.0.
  5. * (See accompanying file LICENSE_1_0.txt or copy at
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. *
  8. * See http://www.boost.org/libs/multi_index for library home page.
  9. */
  10. #ifndef BOOST_MULTI_INDEX_HPP
  11. #define BOOST_MULTI_INDEX_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  16. #include <algorithm>
  17. #include <boost/core/addressof.hpp>
  18. #include <boost/detail/no_exceptions_support.hpp>
  19. #include <boost/detail/workaround.hpp>
  20. #include <boost/move/core.hpp>
  21. #include <boost/move/utility_core.hpp>
  22. #include <boost/mpl/at.hpp>
  23. #include <boost/mpl/contains.hpp>
  24. #include <boost/mpl/find_if.hpp>
  25. #include <boost/mpl/identity.hpp>
  26. #include <boost/mpl/int.hpp>
  27. #include <boost/mpl/size.hpp>
  28. #include <boost/mpl/deref.hpp>
  29. #include <boost/multi_index_container_fwd.hpp>
  30. #include <boost/multi_index/detail/access_specifier.hpp>
  31. #include <boost/multi_index/detail/adl_swap.hpp>
  32. #include <boost/multi_index/detail/allocator_traits.hpp>
  33. #include <boost/multi_index/detail/base_type.hpp>
  34. #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
  35. #include <boost/multi_index/detail/converter.hpp>
  36. #include <boost/multi_index/detail/header_holder.hpp>
  37. #include <boost/multi_index/detail/has_tag.hpp>
  38. #include <boost/multi_index/detail/no_duplicate_tags.hpp>
  39. #include <boost/multi_index/detail/safe_mode.hpp>
  40. #include <boost/multi_index/detail/scope_guard.hpp>
  41. #include <boost/multi_index/detail/vartempl_support.hpp>
  42. #include <boost/static_assert.hpp>
  43. #include <boost/type_traits/integral_constant.hpp>
  44. #include <boost/type_traits/is_same.hpp>
  45. #include <boost/utility/base_from_member.hpp>
  46. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  47. #include <initializer_list>
  48. #endif
  49. #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
  50. #include <boost/multi_index/detail/archive_constructed.hpp>
  51. #include <boost/multi_index/detail/serialization_version.hpp>
  52. #include <boost/serialization/collection_size_type.hpp>
  53. #include <boost/serialization/nvp.hpp>
  54. #include <boost/serialization/split_member.hpp>
  55. #include <boost/serialization/version.hpp>
  56. #include <boost/throw_exception.hpp>
  57. #endif
  58. #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
  59. #include <boost/multi_index/detail/invariant_assert.hpp>
  60. #define BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x) \
  61. detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
  62. detail::make_obj_guard(x,&multi_index_container::check_invariant_); \
  63. BOOST_JOIN(check_invariant_,__LINE__).touch();
  64. #define BOOST_MULTI_INDEX_CHECK_INVARIANT \
  65. BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(*this)
  66. #else
  67. #define BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x)
  68. #define BOOST_MULTI_INDEX_CHECK_INVARIANT
  69. #endif
  70. namespace boost{
  71. namespace multi_index{
  72. namespace detail{
  73. struct unequal_alloc_move_ctor_tag{};
  74. } /* namespace multi_index::detail */
  75. #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
  76. #pragma warning(push)
  77. #pragma warning(disable:4522) /* spurious warning on multiple operator=()'s */
  78. #endif
  79. template<typename Value,typename IndexSpecifierList,typename Allocator>
  80. class multi_index_container:
  81. private ::boost::base_from_member<
  82. typename detail::rebind_alloc_for<
  83. Allocator,
  84. typename detail::multi_index_node_type<
  85. Value,IndexSpecifierList,Allocator>::type
  86. >::type
  87. >,
  88. BOOST_MULTI_INDEX_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS detail::header_holder<
  89. typename detail::allocator_traits<
  90. typename detail::rebind_alloc_for<
  91. Allocator,
  92. typename detail::multi_index_node_type<
  93. Value,IndexSpecifierList,Allocator>::type
  94. >::type
  95. >::pointer,
  96. multi_index_container<Value,IndexSpecifierList,Allocator> >,
  97. public detail::multi_index_base_type<
  98. Value,IndexSpecifierList,Allocator>::type
  99. {
  100. #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
  101. BOOST_WORKAROUND(__MWERKS__,<=0x3003)
  102. /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
  103. * lifetime of const references bound to temporaries --precisely what
  104. * scopeguards are.
  105. */
  106. #pragma parse_mfunc_templ off
  107. #endif
  108. private:
  109. BOOST_COPYABLE_AND_MOVABLE(multi_index_container)
  110. #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
  111. template <typename,typename,typename> friend class detail::index_base;
  112. template <typename,typename> friend struct detail::header_holder;
  113. template <typename,typename> friend struct detail::converter;
  114. #endif
  115. typedef typename detail::multi_index_base_type<
  116. Value,IndexSpecifierList,Allocator>::type super;
  117. typedef typename detail::rebind_alloc_for<
  118. Allocator,
  119. typename super::node_type
  120. >::type node_allocator;
  121. typedef detail::allocator_traits<node_allocator> node_alloc_traits;
  122. typedef typename node_alloc_traits::pointer node_pointer;
  123. typedef ::boost::base_from_member<
  124. node_allocator> bfm_allocator;
  125. typedef detail::header_holder<
  126. node_pointer,
  127. multi_index_container> bfm_header;
  128. public:
  129. /* All types are inherited from super, a few are explicitly
  130. * brought forward here to save us some typename's.
  131. */
  132. typedef typename super::ctor_args_list ctor_args_list;
  133. typedef IndexSpecifierList index_specifier_type_list;
  134. typedef typename super::index_type_list index_type_list;
  135. typedef typename super::iterator_type_list iterator_type_list;
  136. typedef typename super::const_iterator_type_list const_iterator_type_list;
  137. typedef typename super::value_type value_type;
  138. typedef typename super::final_allocator_type allocator_type;
  139. typedef typename super::size_type size_type;
  140. typedef typename super::iterator iterator;
  141. typedef typename super::const_iterator const_iterator;
  142. BOOST_STATIC_ASSERT(
  143. detail::no_duplicate_tags_in_index_list<index_type_list>::value);
  144. /* global project() needs to see this publicly */
  145. typedef typename super::node_type node_type;
  146. /* construct/copy/destroy */
  147. multi_index_container():
  148. bfm_allocator(allocator_type()),
  149. super(ctor_args_list(),bfm_allocator::member),
  150. node_count(0)
  151. {
  152. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  153. }
  154. explicit multi_index_container(
  155. const ctor_args_list& args_list,
  156. #if BOOST_WORKAROUND(__IBMCPP__,<=600)
  157. /* VisualAge seems to have an ETI issue with the default value for
  158. * argument al.
  159. */
  160. const allocator_type& al=
  161. typename mpl::identity<multi_index_container>::type::
  162. allocator_type()):
  163. #else
  164. const allocator_type& al=allocator_type()):
  165. #endif
  166. bfm_allocator(al),
  167. super(args_list,bfm_allocator::member),
  168. node_count(0)
  169. {
  170. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  171. }
  172. explicit multi_index_container(const allocator_type& al):
  173. bfm_allocator(al),
  174. super(ctor_args_list(),bfm_allocator::member),
  175. node_count(0)
  176. {
  177. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  178. }
  179. template<typename InputIterator>
  180. multi_index_container(
  181. InputIterator first,InputIterator last,
  182. #if BOOST_WORKAROUND(__IBMCPP__,<=600)
  183. /* VisualAge seems to have an ETI issue with the default values
  184. * for arguments args_list and al.
  185. */
  186. const ctor_args_list& args_list=
  187. typename mpl::identity<multi_index_container>::type::
  188. ctor_args_list(),
  189. const allocator_type& al=
  190. typename mpl::identity<multi_index_container>::type::
  191. allocator_type()):
  192. #else
  193. const ctor_args_list& args_list=ctor_args_list(),
  194. const allocator_type& al=allocator_type()):
  195. #endif
  196. bfm_allocator(al),
  197. super(args_list,bfm_allocator::member),
  198. node_count(0)
  199. {
  200. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  201. BOOST_TRY{
  202. iterator hint=super::end();
  203. for(;first!=last;++first){
  204. hint=super::make_iterator(
  205. insert_ref_(*first,hint.get_node()).first);
  206. ++hint;
  207. }
  208. }
  209. BOOST_CATCH(...){
  210. clear_();
  211. BOOST_RETHROW;
  212. }
  213. BOOST_CATCH_END
  214. }
  215. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  216. multi_index_container(
  217. std::initializer_list<Value> list,
  218. const ctor_args_list& args_list=ctor_args_list(),
  219. const allocator_type& al=allocator_type()):
  220. bfm_allocator(al),
  221. super(args_list,bfm_allocator::member),
  222. node_count(0)
  223. {
  224. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  225. BOOST_TRY{
  226. typedef const Value* init_iterator;
  227. iterator hint=super::end();
  228. for(init_iterator first=list.begin(),last=list.end();
  229. first!=last;++first){
  230. hint=super::make_iterator(insert_(*first,hint.get_node()).first);
  231. ++hint;
  232. }
  233. }
  234. BOOST_CATCH(...){
  235. clear_();
  236. BOOST_RETHROW;
  237. }
  238. BOOST_CATCH_END
  239. }
  240. #endif
  241. multi_index_container(
  242. const multi_index_container<Value,IndexSpecifierList,Allocator>& x):
  243. bfm_allocator(
  244. node_alloc_traits::select_on_container_copy_construction(
  245. x.bfm_allocator::member)),
  246. bfm_header(),
  247. super(x),
  248. node_count(0)
  249. {
  250. copy_construct_from(x);
  251. }
  252. multi_index_container(BOOST_RV_REF(multi_index_container) x):
  253. bfm_allocator(boost::move(x.bfm_allocator::member)),
  254. bfm_header(),
  255. super(x,detail::do_not_copy_elements_tag()),
  256. node_count(0)
  257. {
  258. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  259. BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x);
  260. swap_elements_(x);
  261. }
  262. multi_index_container(
  263. const multi_index_container<Value,IndexSpecifierList,Allocator>& x,
  264. const allocator_type& al):
  265. bfm_allocator(al),
  266. bfm_header(),
  267. super(x),
  268. node_count(0)
  269. {
  270. copy_construct_from(x);
  271. }
  272. multi_index_container(
  273. BOOST_RV_REF(multi_index_container) x,const allocator_type& al):
  274. bfm_allocator(al),
  275. bfm_header(),
  276. super(x,detail::do_not_copy_elements_tag()),
  277. node_count(0)
  278. {
  279. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  280. BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x);
  281. if(al==x.get_allocator()){
  282. swap_elements_(x);
  283. }
  284. else{
  285. multi_index_container y(x,al,detail::unequal_alloc_move_ctor_tag());
  286. swap_elements_(y);
  287. }
  288. }
  289. ~multi_index_container()
  290. {
  291. delete_all_nodes_();
  292. }
  293. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  294. /* As per http://www.boost.org/doc/html/move/emulation_limitations.html
  295. * #move.emulation_limitations.assignment_operator
  296. */
  297. multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
  298. const multi_index_container<Value,IndexSpecifierList,Allocator>& x)
  299. {
  300. multi_index_container y(
  301. x,
  302. node_alloc_traits::propagate_on_container_copy_assignment::value?
  303. x.get_allocator():this->get_allocator());
  304. swap_(y,boost::true_type() /* swap_allocators */);
  305. return *this;
  306. }
  307. #endif
  308. multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
  309. BOOST_COPY_ASSIGN_REF(multi_index_container) x)
  310. {
  311. multi_index_container y(
  312. x,
  313. node_alloc_traits::propagate_on_container_copy_assignment::value?
  314. x.get_allocator():this->get_allocator());
  315. swap_(y,boost::true_type() /* swap_allocators */);
  316. return *this;
  317. }
  318. multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
  319. BOOST_RV_REF(multi_index_container) x)
  320. {
  321. #if !defined(BOOST_NO_CXX17_IF_CONSTEXPR)
  322. #define BOOST_MULTI_INDEX_IF_CONSTEXPR if constexpr
  323. #else
  324. #define BOOST_MULTI_INDEX_IF_CONSTEXPR if
  325. #if defined(BOOST_MSVC)
  326. #pragma warning(push)
  327. #pragma warning(disable:4127) /* conditional expression is constant */
  328. #endif
  329. #endif
  330. BOOST_MULTI_INDEX_IF_CONSTEXPR(
  331. node_alloc_traits::propagate_on_container_move_assignment::value){
  332. swap_(x,boost::true_type() /* swap_allocators */);
  333. }
  334. else if(this->get_allocator()==x.get_allocator()){
  335. swap_(x,boost::false_type() /* swap_allocators */);
  336. }
  337. else{
  338. multi_index_container y(boost::move(x),this->get_allocator());
  339. swap_(y,boost::false_type() /* swap_allocators */);
  340. }
  341. return *this;
  342. #undef BOOST_MULTI_INDEX_IF_CONSTEXPR
  343. #if defined(BOOST_NO_CXX17_IF_CONSTEXPR)&&defined(BOOST_MSVC)
  344. #pragma warning(pop) /* C4127 */
  345. #endif
  346. }
  347. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  348. multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
  349. std::initializer_list<Value> list)
  350. {
  351. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  352. typedef const Value* init_iterator;
  353. multi_index_container x(*this,detail::do_not_copy_elements_tag());
  354. iterator hint=x.end();
  355. for(init_iterator first=list.begin(),last=list.end();
  356. first!=last;++first){
  357. hint=x.make_iterator(x.insert_(*first,hint.get_node()).first);
  358. ++hint;
  359. }
  360. x.swap_elements_(*this);
  361. return*this;
  362. }
  363. #endif
  364. allocator_type get_allocator()const BOOST_NOEXCEPT
  365. {
  366. return allocator_type(bfm_allocator::member);
  367. }
  368. /* retrieval of indices by number */
  369. #if !defined(BOOST_NO_MEMBER_TEMPLATES)
  370. template<int N>
  371. struct nth_index
  372. {
  373. BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
  374. typedef typename mpl::at_c<index_type_list,N>::type type;
  375. };
  376. template<int N>
  377. typename nth_index<N>::type& get()BOOST_NOEXCEPT
  378. {
  379. BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
  380. return *this;
  381. }
  382. template<int N>
  383. const typename nth_index<N>::type& get()const BOOST_NOEXCEPT
  384. {
  385. BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
  386. return *this;
  387. }
  388. #endif
  389. /* retrieval of indices by tag */
  390. #if !defined(BOOST_NO_MEMBER_TEMPLATES)
  391. template<typename Tag>
  392. struct index
  393. {
  394. typedef typename mpl::find_if<
  395. index_type_list,
  396. detail::has_tag<Tag>
  397. >::type iter;
  398. BOOST_STATIC_CONSTANT(
  399. bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
  400. BOOST_STATIC_ASSERT(index_found);
  401. typedef typename mpl::deref<iter>::type type;
  402. };
  403. template<typename Tag>
  404. typename index<Tag>::type& get()BOOST_NOEXCEPT
  405. {
  406. return *this;
  407. }
  408. template<typename Tag>
  409. const typename index<Tag>::type& get()const BOOST_NOEXCEPT
  410. {
  411. return *this;
  412. }
  413. #endif
  414. /* projection of iterators by number */
  415. #if !defined(BOOST_NO_MEMBER_TEMPLATES)
  416. template<int N>
  417. struct nth_index_iterator
  418. {
  419. typedef typename nth_index<N>::type::iterator type;
  420. };
  421. template<int N>
  422. struct nth_index_const_iterator
  423. {
  424. typedef typename nth_index<N>::type::const_iterator type;
  425. };
  426. template<int N,typename IteratorType>
  427. typename nth_index_iterator<N>::type project(IteratorType it)
  428. {
  429. typedef typename nth_index<N>::type index_type;
  430. #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
  431. BOOST_STATIC_ASSERT(
  432. (mpl::contains<iterator_type_list,IteratorType>::value));
  433. #endif
  434. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
  435. BOOST_MULTI_INDEX_CHECK_IS_OWNER(
  436. it,static_cast<typename IteratorType::container_type&>(*this));
  437. return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
  438. }
  439. template<int N,typename IteratorType>
  440. typename nth_index_const_iterator<N>::type project(IteratorType it)const
  441. {
  442. typedef typename nth_index<N>::type index_type;
  443. #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
  444. BOOST_STATIC_ASSERT((
  445. mpl::contains<iterator_type_list,IteratorType>::value||
  446. mpl::contains<const_iterator_type_list,IteratorType>::value));
  447. #endif
  448. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
  449. BOOST_MULTI_INDEX_CHECK_IS_OWNER(
  450. it,static_cast<const typename IteratorType::container_type&>(*this));
  451. return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
  452. }
  453. #endif
  454. /* projection of iterators by tag */
  455. #if !defined(BOOST_NO_MEMBER_TEMPLATES)
  456. template<typename Tag>
  457. struct index_iterator
  458. {
  459. typedef typename index<Tag>::type::iterator type;
  460. };
  461. template<typename Tag>
  462. struct index_const_iterator
  463. {
  464. typedef typename index<Tag>::type::const_iterator type;
  465. };
  466. template<typename Tag,typename IteratorType>
  467. typename index_iterator<Tag>::type project(IteratorType it)
  468. {
  469. typedef typename index<Tag>::type index_type;
  470. #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
  471. BOOST_STATIC_ASSERT(
  472. (mpl::contains<iterator_type_list,IteratorType>::value));
  473. #endif
  474. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
  475. BOOST_MULTI_INDEX_CHECK_IS_OWNER(
  476. it,static_cast<typename IteratorType::container_type&>(*this));
  477. return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
  478. }
  479. template<typename Tag,typename IteratorType>
  480. typename index_const_iterator<Tag>::type project(IteratorType it)const
  481. {
  482. typedef typename index<Tag>::type index_type;
  483. #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
  484. BOOST_STATIC_ASSERT((
  485. mpl::contains<iterator_type_list,IteratorType>::value||
  486. mpl::contains<const_iterator_type_list,IteratorType>::value));
  487. #endif
  488. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
  489. BOOST_MULTI_INDEX_CHECK_IS_OWNER(
  490. it,static_cast<const typename IteratorType::container_type&>(*this));
  491. return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
  492. }
  493. #endif
  494. BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
  495. typedef typename super::copy_map_type copy_map_type;
  496. multi_index_container(
  497. multi_index_container<Value,IndexSpecifierList,Allocator>& x,
  498. const allocator_type& al,
  499. detail::unequal_alloc_move_ctor_tag):
  500. bfm_allocator(al),
  501. bfm_header(),
  502. super(x),
  503. node_count(0)
  504. {
  505. BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x);
  506. BOOST_TRY{
  507. copy_map_type map(bfm_allocator::member,x.size(),x.header(),header());
  508. for(const_iterator it=x.begin(),it_end=x.end();it!=it_end;++it){
  509. map.move_clone(it.get_node());
  510. }
  511. super::copy_(x,map);
  512. map.release();
  513. node_count=x.size();
  514. x.clear();
  515. }
  516. BOOST_CATCH(...){
  517. x.clear();
  518. BOOST_RETHROW;
  519. }
  520. BOOST_CATCH_END
  521. /* Not until this point are the indices required to be consistent,
  522. * hence the position of the invariant checker.
  523. */
  524. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  525. }
  526. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  527. multi_index_container(
  528. const multi_index_container<Value,IndexSpecifierList,Allocator>& x,
  529. detail::do_not_copy_elements_tag):
  530. bfm_allocator(x.bfm_allocator::member),
  531. bfm_header(),
  532. super(x,detail::do_not_copy_elements_tag()),
  533. node_count(0)
  534. {
  535. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  536. }
  537. #endif
  538. void copy_construct_from(
  539. const multi_index_container<Value,IndexSpecifierList,Allocator>& x)
  540. {
  541. copy_map_type map(bfm_allocator::member,x.size(),x.header(),header());
  542. for(const_iterator it=x.begin(),it_end=x.end();it!=it_end;++it){
  543. map.copy_clone(it.get_node());
  544. }
  545. super::copy_(x,map);
  546. map.release();
  547. node_count=x.size();
  548. /* Not until this point are the indices required to be consistent,
  549. * hence the position of the invariant checker.
  550. */
  551. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  552. }
  553. node_type* header()const
  554. {
  555. return &*bfm_header::member;
  556. }
  557. node_type* allocate_node()
  558. {
  559. return &*node_alloc_traits::allocate(bfm_allocator::member,1);
  560. }
  561. void deallocate_node(node_type* x)
  562. {
  563. node_alloc_traits::deallocate(
  564. bfm_allocator::member,static_cast<node_pointer>(x),1);
  565. }
  566. void construct_value(node_type* x,const Value& v)
  567. {
  568. node_alloc_traits::construct(
  569. bfm_allocator::member,boost::addressof(x->value()),v);
  570. }
  571. void construct_value(node_type* x,BOOST_RV_REF(Value) v)
  572. {
  573. node_alloc_traits::construct(
  574. bfm_allocator::member,boost::addressof(x->value()),boost::move(v));
  575. }
  576. BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
  577. void,construct_value,vartempl_construct_value_impl,node_type*,x)
  578. void destroy_value(node_type* x)
  579. {
  580. node_alloc_traits::destroy(
  581. bfm_allocator::member,boost::addressof(x->value()));
  582. }
  583. bool empty_()const
  584. {
  585. return node_count==0;
  586. }
  587. size_type size_()const
  588. {
  589. return node_count;
  590. }
  591. size_type max_size_()const
  592. {
  593. return static_cast<size_type>(-1);
  594. }
  595. template<typename Variant>
  596. std::pair<node_type*,bool> insert_(const Value& v,Variant variant)
  597. {
  598. node_type* x=0;
  599. node_type* res=super::insert_(v,x,variant);
  600. if(res==x){
  601. ++node_count;
  602. return std::pair<node_type*,bool>(res,true);
  603. }
  604. else{
  605. return std::pair<node_type*,bool>(res,false);
  606. }
  607. }
  608. std::pair<node_type*,bool> insert_(const Value& v)
  609. {
  610. return insert_(v,detail::lvalue_tag());
  611. }
  612. std::pair<node_type*,bool> insert_rv_(const Value& v)
  613. {
  614. return insert_(v,detail::rvalue_tag());
  615. }
  616. template<typename T>
  617. std::pair<node_type*,bool> insert_ref_(T& t)
  618. {
  619. node_type* x=allocate_node();
  620. BOOST_TRY{
  621. construct_value(x,t);
  622. BOOST_TRY{
  623. node_type* res=super::insert_(x->value(),x,detail::emplaced_tag());
  624. if(res==x){
  625. ++node_count;
  626. return std::pair<node_type*,bool>(res,true);
  627. }
  628. else{
  629. destroy_value(x);
  630. deallocate_node(x);
  631. return std::pair<node_type*,bool>(res,false);
  632. }
  633. }
  634. BOOST_CATCH(...){
  635. destroy_value(x);
  636. BOOST_RETHROW;
  637. }
  638. BOOST_CATCH_END
  639. }
  640. BOOST_CATCH(...){
  641. deallocate_node(x);
  642. BOOST_RETHROW;
  643. }
  644. BOOST_CATCH_END
  645. }
  646. std::pair<node_type*,bool> insert_ref_(const value_type& x)
  647. {
  648. return insert_(x);
  649. }
  650. std::pair<node_type*,bool> insert_ref_(value_type& x)
  651. {
  652. return insert_(x);
  653. }
  654. template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
  655. std::pair<node_type*,bool> emplace_(
  656. BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
  657. {
  658. node_type* x=allocate_node();
  659. BOOST_TRY{
  660. construct_value(x,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
  661. BOOST_TRY{
  662. node_type* res=super::insert_(x->value(),x,detail::emplaced_tag());
  663. if(res==x){
  664. ++node_count;
  665. return std::pair<node_type*,bool>(res,true);
  666. }
  667. else{
  668. destroy_value(x);
  669. deallocate_node(x);
  670. return std::pair<node_type*,bool>(res,false);
  671. }
  672. }
  673. BOOST_CATCH(...){
  674. destroy_value(x);
  675. BOOST_RETHROW;
  676. }
  677. BOOST_CATCH_END
  678. }
  679. BOOST_CATCH(...){
  680. deallocate_node(x);
  681. BOOST_RETHROW;
  682. }
  683. BOOST_CATCH_END
  684. }
  685. template<typename Variant>
  686. std::pair<node_type*,bool> insert_(
  687. const Value& v,node_type* position,Variant variant)
  688. {
  689. node_type* x=0;
  690. node_type* res=super::insert_(v,position,x,variant);
  691. if(res==x){
  692. ++node_count;
  693. return std::pair<node_type*,bool>(res,true);
  694. }
  695. else{
  696. return std::pair<node_type*,bool>(res,false);
  697. }
  698. }
  699. std::pair<node_type*,bool> insert_(const Value& v,node_type* position)
  700. {
  701. return insert_(v,position,detail::lvalue_tag());
  702. }
  703. std::pair<node_type*,bool> insert_rv_(const Value& v,node_type* position)
  704. {
  705. return insert_(v,position,detail::rvalue_tag());
  706. }
  707. template<typename T>
  708. std::pair<node_type*,bool> insert_ref_(
  709. T& t,node_type* position)
  710. {
  711. node_type* x=allocate_node();
  712. BOOST_TRY{
  713. construct_value(x,t);
  714. BOOST_TRY{
  715. node_type* res=super::insert_(
  716. x->value(),position,x,detail::emplaced_tag());
  717. if(res==x){
  718. ++node_count;
  719. return std::pair<node_type*,bool>(res,true);
  720. }
  721. else{
  722. destroy_value(x);
  723. deallocate_node(x);
  724. return std::pair<node_type*,bool>(res,false);
  725. }
  726. }
  727. BOOST_CATCH(...){
  728. destroy_value(x);
  729. BOOST_RETHROW;
  730. }
  731. BOOST_CATCH_END
  732. }
  733. BOOST_CATCH(...){
  734. deallocate_node(x);
  735. BOOST_RETHROW;
  736. }
  737. BOOST_CATCH_END
  738. }
  739. std::pair<node_type*,bool> insert_ref_(
  740. const value_type& x,node_type* position)
  741. {
  742. return insert_(x,position);
  743. }
  744. std::pair<node_type*,bool> insert_ref_(
  745. value_type& x,node_type* position)
  746. {
  747. return insert_(x,position);
  748. }
  749. template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
  750. std::pair<node_type*,bool> emplace_hint_(
  751. node_type* position,
  752. BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
  753. {
  754. node_type* x=allocate_node();
  755. BOOST_TRY{
  756. construct_value(x,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
  757. BOOST_TRY{
  758. node_type* res=super::insert_(
  759. x->value(),position,x,detail::emplaced_tag());
  760. if(res==x){
  761. ++node_count;
  762. return std::pair<node_type*,bool>(res,true);
  763. }
  764. else{
  765. destroy_value(x);
  766. deallocate_node(x);
  767. return std::pair<node_type*,bool>(res,false);
  768. }
  769. }
  770. BOOST_CATCH(...){
  771. destroy_value(x);
  772. BOOST_RETHROW;
  773. }
  774. BOOST_CATCH_END
  775. }
  776. BOOST_CATCH(...){
  777. deallocate_node(x);
  778. BOOST_RETHROW;
  779. }
  780. BOOST_CATCH_END
  781. }
  782. void erase_(node_type* x)
  783. {
  784. --node_count;
  785. super::erase_(x);
  786. deallocate_node(x);
  787. }
  788. void delete_node_(node_type* x)
  789. {
  790. super::delete_node_(x);
  791. deallocate_node(x);
  792. }
  793. void delete_all_nodes_()
  794. {
  795. super::delete_all_nodes_();
  796. }
  797. void clear_()
  798. {
  799. delete_all_nodes_();
  800. super::clear_();
  801. node_count=0;
  802. }
  803. void swap_(multi_index_container<Value,IndexSpecifierList,Allocator>& x)
  804. {
  805. swap_(
  806. x,
  807. boost::integral_constant<
  808. bool,node_alloc_traits::propagate_on_container_swap::value>());
  809. }
  810. void swap_(
  811. multi_index_container<Value,IndexSpecifierList,Allocator>& x,
  812. boost::true_type swap_allocators)
  813. {
  814. detail::adl_swap(bfm_allocator::member,x.bfm_allocator::member);
  815. std::swap(bfm_header::member,x.bfm_header::member);
  816. super::swap_(x,swap_allocators);
  817. std::swap(node_count,x.node_count);
  818. }
  819. void swap_(
  820. multi_index_container<Value,IndexSpecifierList,Allocator>& x,
  821. boost::false_type swap_allocators)
  822. {
  823. std::swap(bfm_header::member,x.bfm_header::member);
  824. super::swap_(x,swap_allocators);
  825. std::swap(node_count,x.node_count);
  826. }
  827. void swap_elements_(
  828. multi_index_container<Value,IndexSpecifierList,Allocator>& x)
  829. {
  830. std::swap(bfm_header::member,x.bfm_header::member);
  831. super::swap_elements_(x);
  832. std::swap(node_count,x.node_count);
  833. }
  834. bool replace_(const Value& k,node_type* x)
  835. {
  836. return super::replace_(k,x,detail::lvalue_tag());
  837. }
  838. bool replace_rv_(const Value& k,node_type* x)
  839. {
  840. return super::replace_(k,x,detail::rvalue_tag());
  841. }
  842. template<typename Modifier>
  843. bool modify_(Modifier& mod,node_type* x)
  844. {
  845. BOOST_TRY{
  846. mod(const_cast<value_type&>(x->value()));
  847. }
  848. BOOST_CATCH(...){
  849. this->erase_(x);
  850. BOOST_RETHROW;
  851. }
  852. BOOST_CATCH_END
  853. BOOST_TRY{
  854. if(!super::modify_(x)){
  855. deallocate_node(x);
  856. --node_count;
  857. return false;
  858. }
  859. else return true;
  860. }
  861. BOOST_CATCH(...){
  862. deallocate_node(x);
  863. --node_count;
  864. BOOST_RETHROW;
  865. }
  866. BOOST_CATCH_END
  867. }
  868. template<typename Modifier,typename Rollback>
  869. bool modify_(Modifier& mod,Rollback& back_,node_type* x)
  870. {
  871. BOOST_TRY{
  872. mod(const_cast<value_type&>(x->value()));
  873. }
  874. BOOST_CATCH(...){
  875. this->erase_(x);
  876. BOOST_RETHROW;
  877. }
  878. BOOST_CATCH_END
  879. bool b;
  880. BOOST_TRY{
  881. b=super::modify_rollback_(x);
  882. }
  883. BOOST_CATCH(...){
  884. BOOST_TRY{
  885. back_(const_cast<value_type&>(x->value()));
  886. if(!super::check_rollback_(x))this->erase_(x);
  887. BOOST_RETHROW;
  888. }
  889. BOOST_CATCH(...){
  890. this->erase_(x);
  891. BOOST_RETHROW;
  892. }
  893. BOOST_CATCH_END
  894. }
  895. BOOST_CATCH_END
  896. BOOST_TRY{
  897. if(!b){
  898. back_(const_cast<value_type&>(x->value()));
  899. if(!super::check_rollback_(x))this->erase_(x);
  900. return false;
  901. }
  902. else return true;
  903. }
  904. BOOST_CATCH(...){
  905. this->erase_(x);
  906. BOOST_RETHROW;
  907. }
  908. BOOST_CATCH_END
  909. }
  910. #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
  911. /* serialization */
  912. friend class boost::serialization::access;
  913. BOOST_SERIALIZATION_SPLIT_MEMBER()
  914. typedef typename super::index_saver_type index_saver_type;
  915. typedef typename super::index_loader_type index_loader_type;
  916. template<class Archive>
  917. void save(Archive& ar,const unsigned int version)const
  918. {
  919. const serialization::collection_size_type s(size_());
  920. const detail::serialization_version<value_type> value_version;
  921. ar<<serialization::make_nvp("count",s);
  922. ar<<serialization::make_nvp("value_version",value_version);
  923. index_saver_type sm(bfm_allocator::member,s);
  924. for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){
  925. serialization::save_construct_data_adl(
  926. ar,boost::addressof(*it),value_version);
  927. ar<<serialization::make_nvp("item",*it);
  928. sm.add(it.get_node(),ar,version);
  929. }
  930. sm.add_track(header(),ar,version);
  931. super::save_(ar,version,sm);
  932. }
  933. template<class Archive>
  934. void load(Archive& ar,const unsigned int version)
  935. {
  936. BOOST_MULTI_INDEX_CHECK_INVARIANT;
  937. clear_();
  938. serialization::collection_size_type s;
  939. detail::serialization_version<value_type> value_version;
  940. if(version<1){
  941. std::size_t sz;
  942. ar>>serialization::make_nvp("count",sz);
  943. s=static_cast<serialization::collection_size_type>(sz);
  944. }
  945. else{
  946. ar>>serialization::make_nvp("count",s);
  947. }
  948. if(version<2){
  949. value_version=0;
  950. }
  951. else{
  952. ar>>serialization::make_nvp("value_version",value_version);
  953. }
  954. index_loader_type lm(bfm_allocator::member,s);
  955. for(std::size_t n=0;n<s;++n){
  956. detail::archive_constructed<Value> value("item",ar,value_version);
  957. std::pair<node_type*,bool> p=insert_rv_(
  958. value.get(),super::end().get_node());
  959. if(!p.second)throw_exception(
  960. archive::archive_exception(
  961. archive::archive_exception::other_exception));
  962. ar.reset_object_address(
  963. boost::addressof(p.first->value()),boost::addressof(value.get()));
  964. lm.add(p.first,ar,version);
  965. }
  966. lm.add_track(header(),ar,version);
  967. super::load_(ar,version,lm);
  968. }
  969. #endif
  970. #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
  971. /* invariant stuff */
  972. bool invariant_()const
  973. {
  974. return super::invariant_();
  975. }
  976. void check_invariant_()const
  977. {
  978. BOOST_MULTI_INDEX_INVARIANT_ASSERT(invariant_());
  979. }
  980. #endif
  981. private:
  982. template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
  983. void vartempl_construct_value_impl(
  984. node_type* x,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
  985. {
  986. node_alloc_traits::construct(
  987. bfm_allocator::member,boost::addressof(x->value()),
  988. BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
  989. }
  990. size_type node_count;
  991. #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
  992. BOOST_WORKAROUND(__MWERKS__,<=0x3003)
  993. #pragma parse_mfunc_templ reset
  994. #endif
  995. };
  996. #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
  997. #pragma warning(pop) /* C4522 */
  998. #endif
  999. /* retrieval of indices by number */
  1000. template<typename MultiIndexContainer,int N>
  1001. struct nth_index
  1002. {
  1003. BOOST_STATIC_CONSTANT(
  1004. int,
  1005. M=mpl::size<typename MultiIndexContainer::index_type_list>::type::value);
  1006. BOOST_STATIC_ASSERT(N>=0&&N<M);
  1007. typedef typename mpl::at_c<
  1008. typename MultiIndexContainer::index_type_list,N>::type type;
  1009. };
  1010. template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
  1011. typename nth_index<
  1012. multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
  1013. get(
  1014. multi_index_container<Value,IndexSpecifierList,Allocator>& m)BOOST_NOEXCEPT
  1015. {
  1016. typedef multi_index_container<
  1017. Value,IndexSpecifierList,Allocator> multi_index_type;
  1018. typedef typename nth_index<
  1019. multi_index_container<
  1020. Value,IndexSpecifierList,Allocator>,
  1021. N
  1022. >::type index_type;
  1023. BOOST_STATIC_ASSERT(N>=0&&
  1024. N<
  1025. mpl::size<
  1026. BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
  1027. >::type::value);
  1028. return detail::converter<multi_index_type,index_type>::index(m);
  1029. }
  1030. template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
  1031. const typename nth_index<
  1032. multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
  1033. get(
  1034. const multi_index_container<Value,IndexSpecifierList,Allocator>& m
  1035. )BOOST_NOEXCEPT
  1036. {
  1037. typedef multi_index_container<
  1038. Value,IndexSpecifierList,Allocator> multi_index_type;
  1039. typedef typename nth_index<
  1040. multi_index_container<
  1041. Value,IndexSpecifierList,Allocator>,
  1042. N
  1043. >::type index_type;
  1044. BOOST_STATIC_ASSERT(N>=0&&
  1045. N<
  1046. mpl::size<
  1047. BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
  1048. >::type::value);
  1049. return detail::converter<multi_index_type,index_type>::index(m);
  1050. }
  1051. /* retrieval of indices by tag */
  1052. template<typename MultiIndexContainer,typename Tag>
  1053. struct index
  1054. {
  1055. typedef typename MultiIndexContainer::index_type_list index_type_list;
  1056. typedef typename mpl::find_if<
  1057. index_type_list,
  1058. detail::has_tag<Tag>
  1059. >::type iter;
  1060. BOOST_STATIC_CONSTANT(
  1061. bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
  1062. BOOST_STATIC_ASSERT(index_found);
  1063. typedef typename mpl::deref<iter>::type type;
  1064. };
  1065. template<
  1066. typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
  1067. >
  1068. typename ::boost::multi_index::index<
  1069. multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
  1070. get(
  1071. multi_index_container<Value,IndexSpecifierList,Allocator>& m)BOOST_NOEXCEPT
  1072. {
  1073. typedef multi_index_container<
  1074. Value,IndexSpecifierList,Allocator> multi_index_type;
  1075. typedef typename ::boost::multi_index::index<
  1076. multi_index_container<
  1077. Value,IndexSpecifierList,Allocator>,
  1078. Tag
  1079. >::type index_type;
  1080. return detail::converter<multi_index_type,index_type>::index(m);
  1081. }
  1082. template<
  1083. typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
  1084. >
  1085. const typename ::boost::multi_index::index<
  1086. multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
  1087. get(
  1088. const multi_index_container<Value,IndexSpecifierList,Allocator>& m
  1089. )BOOST_NOEXCEPT
  1090. {
  1091. typedef multi_index_container<
  1092. Value,IndexSpecifierList,Allocator> multi_index_type;
  1093. typedef typename ::boost::multi_index::index<
  1094. multi_index_container<
  1095. Value,IndexSpecifierList,Allocator>,
  1096. Tag
  1097. >::type index_type;
  1098. return detail::converter<multi_index_type,index_type>::index(m);
  1099. }
  1100. /* projection of iterators by number */
  1101. template<typename MultiIndexContainer,int N>
  1102. struct nth_index_iterator
  1103. {
  1104. typedef typename nth_index<MultiIndexContainer,N>::type::iterator type;
  1105. };
  1106. template<typename MultiIndexContainer,int N>
  1107. struct nth_index_const_iterator
  1108. {
  1109. typedef typename nth_index<MultiIndexContainer,N>::type::const_iterator type;
  1110. };
  1111. template<
  1112. int N,typename IteratorType,
  1113. typename Value,typename IndexSpecifierList,typename Allocator>
  1114. typename nth_index_iterator<
  1115. multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
  1116. project(
  1117. multi_index_container<Value,IndexSpecifierList,Allocator>& m,
  1118. IteratorType it)
  1119. {
  1120. typedef multi_index_container<
  1121. Value,IndexSpecifierList,Allocator> multi_index_type;
  1122. typedef typename nth_index<multi_index_type,N>::type index_type;
  1123. #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
  1124. BOOST_STATIC_ASSERT((
  1125. mpl::contains<
  1126. BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
  1127. IteratorType>::value));
  1128. #endif
  1129. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
  1130. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  1131. typedef detail::converter<
  1132. multi_index_type,
  1133. BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
  1134. BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
  1135. #endif
  1136. return detail::converter<multi_index_type,index_type>::iterator(
  1137. m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
  1138. }
  1139. template<
  1140. int N,typename IteratorType,
  1141. typename Value,typename IndexSpecifierList,typename Allocator>
  1142. typename nth_index_const_iterator<
  1143. multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
  1144. project(
  1145. const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
  1146. IteratorType it)
  1147. {
  1148. typedef multi_index_container<
  1149. Value,IndexSpecifierList,Allocator> multi_index_type;
  1150. typedef typename nth_index<multi_index_type,N>::type index_type;
  1151. #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
  1152. BOOST_STATIC_ASSERT((
  1153. mpl::contains<
  1154. BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
  1155. IteratorType>::value||
  1156. mpl::contains<
  1157. BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
  1158. IteratorType>::value));
  1159. #endif
  1160. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
  1161. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  1162. typedef detail::converter<
  1163. multi_index_type,
  1164. BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
  1165. BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
  1166. #endif
  1167. return detail::converter<multi_index_type,index_type>::const_iterator(
  1168. m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
  1169. }
  1170. /* projection of iterators by tag */
  1171. template<typename MultiIndexContainer,typename Tag>
  1172. struct index_iterator
  1173. {
  1174. typedef typename ::boost::multi_index::index<
  1175. MultiIndexContainer,Tag>::type::iterator type;
  1176. };
  1177. template<typename MultiIndexContainer,typename Tag>
  1178. struct index_const_iterator
  1179. {
  1180. typedef typename ::boost::multi_index::index<
  1181. MultiIndexContainer,Tag>::type::const_iterator type;
  1182. };
  1183. template<
  1184. typename Tag,typename IteratorType,
  1185. typename Value,typename IndexSpecifierList,typename Allocator>
  1186. typename index_iterator<
  1187. multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
  1188. project(
  1189. multi_index_container<Value,IndexSpecifierList,Allocator>& m,
  1190. IteratorType it)
  1191. {
  1192. typedef multi_index_container<
  1193. Value,IndexSpecifierList,Allocator> multi_index_type;
  1194. typedef typename ::boost::multi_index::index<
  1195. multi_index_type,Tag>::type index_type;
  1196. #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
  1197. BOOST_STATIC_ASSERT((
  1198. mpl::contains<
  1199. BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
  1200. IteratorType>::value));
  1201. #endif
  1202. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
  1203. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  1204. typedef detail::converter<
  1205. multi_index_type,
  1206. BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
  1207. BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
  1208. #endif
  1209. return detail::converter<multi_index_type,index_type>::iterator(
  1210. m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
  1211. }
  1212. template<
  1213. typename Tag,typename IteratorType,
  1214. typename Value,typename IndexSpecifierList,typename Allocator>
  1215. typename index_const_iterator<
  1216. multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
  1217. project(
  1218. const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
  1219. IteratorType it)
  1220. {
  1221. typedef multi_index_container<
  1222. Value,IndexSpecifierList,Allocator> multi_index_type;
  1223. typedef typename ::boost::multi_index::index<
  1224. multi_index_type,Tag>::type index_type;
  1225. #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
  1226. BOOST_STATIC_ASSERT((
  1227. mpl::contains<
  1228. BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
  1229. IteratorType>::value||
  1230. mpl::contains<
  1231. BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
  1232. IteratorType>::value));
  1233. #endif
  1234. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
  1235. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  1236. typedef detail::converter<
  1237. multi_index_type,
  1238. BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
  1239. BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
  1240. #endif
  1241. return detail::converter<multi_index_type,index_type>::const_iterator(
  1242. m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
  1243. }
  1244. /* Comparison. Simple forward to first index. */
  1245. template<
  1246. typename Value1,typename IndexSpecifierList1,typename Allocator1,
  1247. typename Value2,typename IndexSpecifierList2,typename Allocator2
  1248. >
  1249. bool operator==(
  1250. const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
  1251. const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
  1252. {
  1253. return get<0>(x)==get<0>(y);
  1254. }
  1255. template<
  1256. typename Value1,typename IndexSpecifierList1,typename Allocator1,
  1257. typename Value2,typename IndexSpecifierList2,typename Allocator2
  1258. >
  1259. bool operator<(
  1260. const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
  1261. const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
  1262. {
  1263. return get<0>(x)<get<0>(y);
  1264. }
  1265. template<
  1266. typename Value1,typename IndexSpecifierList1,typename Allocator1,
  1267. typename Value2,typename IndexSpecifierList2,typename Allocator2
  1268. >
  1269. bool operator!=(
  1270. const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
  1271. const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
  1272. {
  1273. return get<0>(x)!=get<0>(y);
  1274. }
  1275. template<
  1276. typename Value1,typename IndexSpecifierList1,typename Allocator1,
  1277. typename Value2,typename IndexSpecifierList2,typename Allocator2
  1278. >
  1279. bool operator>(
  1280. const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
  1281. const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
  1282. {
  1283. return get<0>(x)>get<0>(y);
  1284. }
  1285. template<
  1286. typename Value1,typename IndexSpecifierList1,typename Allocator1,
  1287. typename Value2,typename IndexSpecifierList2,typename Allocator2
  1288. >
  1289. bool operator>=(
  1290. const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
  1291. const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
  1292. {
  1293. return get<0>(x)>=get<0>(y);
  1294. }
  1295. template<
  1296. typename Value1,typename IndexSpecifierList1,typename Allocator1,
  1297. typename Value2,typename IndexSpecifierList2,typename Allocator2
  1298. >
  1299. bool operator<=(
  1300. const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
  1301. const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
  1302. {
  1303. return get<0>(x)<=get<0>(y);
  1304. }
  1305. /* specialized algorithms */
  1306. template<typename Value,typename IndexSpecifierList,typename Allocator>
  1307. void swap(
  1308. multi_index_container<Value,IndexSpecifierList,Allocator>& x,
  1309. multi_index_container<Value,IndexSpecifierList,Allocator>& y)
  1310. {
  1311. x.swap(y);
  1312. }
  1313. } /* namespace multi_index */
  1314. #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
  1315. /* class version = 1 : we now serialize the size through
  1316. * boost::serialization::collection_size_type.
  1317. * class version = 2 : proper use of {save|load}_construct_data.
  1318. */
  1319. namespace serialization {
  1320. template<typename Value,typename IndexSpecifierList,typename Allocator>
  1321. struct version<
  1322. boost::multi_index_container<Value,IndexSpecifierList,Allocator>
  1323. >
  1324. {
  1325. BOOST_STATIC_CONSTANT(int,value=2);
  1326. };
  1327. } /* namespace serialization */
  1328. #endif
  1329. /* Associated global functions are promoted to namespace boost, except
  1330. * comparison operators and swap, which are meant to be Koenig looked-up.
  1331. */
  1332. using multi_index::get;
  1333. using multi_index::project;
  1334. } /* namespace boost */
  1335. #undef BOOST_MULTI_INDEX_CHECK_INVARIANT
  1336. #undef BOOST_MULTI_INDEX_CHECK_INVARIANT_OF
  1337. #endif