multi_index_container.hpp 41 KB

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