sequenced_index.hpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. /* Copyright 2003-2023 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/multi_index for library home page.
  7. */
  8. #ifndef BOOST_MULTI_INDEX_SEQUENCED_INDEX_HPP
  9. #define BOOST_MULTI_INDEX_SEQUENCED_INDEX_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  14. #include <boost/bind/bind.hpp>
  15. #include <boost/call_traits.hpp>
  16. #include <boost/core/addressof.hpp>
  17. #include <boost/core/no_exceptions_support.hpp>
  18. #include <boost/detail/workaround.hpp>
  19. #include <boost/iterator/reverse_iterator.hpp>
  20. #include <boost/move/core.hpp>
  21. #include <boost/move/utility_core.hpp>
  22. #include <boost/mpl/bool.hpp>
  23. #include <boost/mpl/not.hpp>
  24. #include <boost/mpl/push_front.hpp>
  25. #include <boost/multi_index/detail/access_specifier.hpp>
  26. #include <boost/multi_index/detail/allocator_traits.hpp>
  27. #include <boost/multi_index/detail/bidir_node_iterator.hpp>
  28. #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
  29. #include <boost/multi_index/detail/index_node_base.hpp>
  30. #include <boost/multi_index/detail/node_handle.hpp>
  31. #include <boost/multi_index/detail/safe_mode.hpp>
  32. #include <boost/multi_index/detail/scope_guard.hpp>
  33. #include <boost/multi_index/detail/seq_index_node.hpp>
  34. #include <boost/multi_index/detail/seq_index_ops.hpp>
  35. #include <boost/multi_index/detail/vartempl_support.hpp>
  36. #include <boost/multi_index/sequenced_index_fwd.hpp>
  37. #include <boost/tuple/tuple.hpp>
  38. #include <boost/type_traits/is_copy_constructible.hpp>
  39. #include <boost/type_traits/is_integral.hpp>
  40. #include <functional>
  41. #include <utility>
  42. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  43. #include<initializer_list>
  44. #endif
  45. #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
  46. #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x) \
  47. detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
  48. detail::make_obj_guard(x,&sequenced_index::check_invariant_); \
  49. BOOST_JOIN(check_invariant_,__LINE__).touch();
  50. #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT \
  51. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(*this)
  52. #else
  53. #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x)
  54. #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT
  55. #endif
  56. namespace boost{
  57. namespace multi_index{
  58. namespace detail{
  59. /* sequenced_index adds a layer of sequenced indexing to a given Super */
  60. #if defined(BOOST_MSVC)
  61. #pragma warning(push)
  62. #pragma warning(disable:4355) /* this used in base member initializer list */
  63. #endif
  64. template<typename SuperMeta,typename TagList>
  65. class sequenced_index:
  66. BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS SuperMeta::type
  67. {
  68. #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
  69. BOOST_WORKAROUND(__MWERKS__,<=0x3003)
  70. /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
  71. * lifetime of const references bound to temporaries --precisely what
  72. * scopeguards are.
  73. */
  74. #pragma parse_mfunc_templ off
  75. #endif
  76. #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
  77. /* cross-index access */
  78. template <typename,typename,typename> friend class index_base;
  79. #endif
  80. typedef typename SuperMeta::type super;
  81. protected:
  82. typedef sequenced_index_node<
  83. typename super::index_node_type> index_node_type;
  84. private:
  85. typedef typename index_node_type::impl_type node_impl_type;
  86. public:
  87. /* types */
  88. typedef typename index_node_type::value_type value_type;
  89. typedef tuples::null_type ctor_args;
  90. typedef typename super::final_allocator_type allocator_type;
  91. typedef value_type& reference;
  92. typedef const value_type& const_reference;
  93. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  94. typedef safe_mode::safe_iterator<
  95. bidir_node_iterator<index_node_type> > iterator;
  96. #else
  97. typedef bidir_node_iterator<index_node_type> iterator;
  98. #endif
  99. typedef iterator const_iterator;
  100. private:
  101. typedef allocator_traits<allocator_type> alloc_traits;
  102. public:
  103. typedef typename alloc_traits::pointer pointer;
  104. typedef typename alloc_traits::const_pointer const_pointer;
  105. typedef typename alloc_traits::size_type size_type;
  106. typedef typename alloc_traits::difference_type difference_type;
  107. typedef typename
  108. boost::reverse_iterator<iterator> reverse_iterator;
  109. typedef typename
  110. boost::reverse_iterator<const_iterator> const_reverse_iterator;
  111. typedef typename super::final_node_handle_type node_type;
  112. typedef detail::insert_return_type<
  113. iterator,node_type> insert_return_type;
  114. typedef TagList tag_list;
  115. protected:
  116. typedef typename super::final_node_type final_node_type;
  117. typedef tuples::cons<
  118. ctor_args,
  119. typename super::ctor_args_list> ctor_args_list;
  120. typedef typename mpl::push_front<
  121. typename super::index_type_list,
  122. sequenced_index>::type index_type_list;
  123. typedef typename mpl::push_front<
  124. typename super::iterator_type_list,
  125. iterator>::type iterator_type_list;
  126. typedef typename mpl::push_front<
  127. typename super::const_iterator_type_list,
  128. const_iterator>::type const_iterator_type_list;
  129. typedef typename super::copy_map_type copy_map_type;
  130. #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
  131. typedef typename super::index_saver_type index_saver_type;
  132. typedef typename super::index_loader_type index_loader_type;
  133. #endif
  134. private:
  135. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  136. typedef safe_mode::safe_container<iterator> safe_container;
  137. #endif
  138. typedef typename call_traits<value_type>::param_type value_param_type;
  139. /* needed to avoid commas in some macros */
  140. typedef std::pair<iterator,bool> pair_return_type;
  141. public:
  142. /* construct/copy/destroy
  143. * Default and copy ctors are in the protected section as indices are
  144. * not supposed to be created on their own. No range ctor either.
  145. */
  146. sequenced_index<SuperMeta,TagList>& operator=(
  147. const sequenced_index<SuperMeta,TagList>& x)
  148. {
  149. this->final()=x.final();
  150. return *this;
  151. }
  152. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  153. sequenced_index<SuperMeta,TagList>& operator=(
  154. std::initializer_list<value_type> list)
  155. {
  156. this->final()=list;
  157. return *this;
  158. }
  159. #endif
  160. template <class InputIterator>
  161. void assign(InputIterator first,InputIterator last)
  162. {
  163. assign_iter(first,last,mpl::not_<is_integral<InputIterator> >());
  164. }
  165. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  166. void assign(std::initializer_list<value_type> list)
  167. {
  168. assign(list.begin(),list.end());
  169. }
  170. #endif
  171. void assign(size_type n,value_param_type value)
  172. {
  173. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  174. clear();
  175. for(size_type i=0;i<n;++i)push_back(value);
  176. }
  177. allocator_type get_allocator()const BOOST_NOEXCEPT
  178. {
  179. return this->final().get_allocator();
  180. }
  181. /* iterators */
  182. iterator begin()BOOST_NOEXCEPT
  183. {return make_iterator(index_node_type::from_impl(header()->next()));}
  184. const_iterator begin()const BOOST_NOEXCEPT
  185. {return make_iterator(index_node_type::from_impl(header()->next()));}
  186. iterator
  187. end()BOOST_NOEXCEPT{return make_iterator(header());}
  188. const_iterator
  189. end()const BOOST_NOEXCEPT{return make_iterator(header());}
  190. reverse_iterator
  191. rbegin()BOOST_NOEXCEPT{return boost::make_reverse_iterator(end());}
  192. const_reverse_iterator
  193. rbegin()const BOOST_NOEXCEPT{return boost::make_reverse_iterator(end());}
  194. reverse_iterator
  195. rend()BOOST_NOEXCEPT{return boost::make_reverse_iterator(begin());}
  196. const_reverse_iterator
  197. rend()const BOOST_NOEXCEPT{return boost::make_reverse_iterator(begin());}
  198. const_iterator
  199. cbegin()const BOOST_NOEXCEPT{return begin();}
  200. const_iterator
  201. cend()const BOOST_NOEXCEPT{return end();}
  202. const_reverse_iterator
  203. crbegin()const BOOST_NOEXCEPT{return rbegin();}
  204. const_reverse_iterator
  205. crend()const BOOST_NOEXCEPT{return rend();}
  206. iterator iterator_to(const value_type& x)
  207. {
  208. return make_iterator(
  209. node_from_value<index_node_type>(boost::addressof(x)));
  210. }
  211. const_iterator iterator_to(const value_type& x)const
  212. {
  213. return make_iterator(
  214. node_from_value<index_node_type>(boost::addressof(x)));
  215. }
  216. /* capacity */
  217. bool empty()const BOOST_NOEXCEPT{return this->final_empty_();}
  218. size_type size()const BOOST_NOEXCEPT{return this->final_size_();}
  219. size_type max_size()const BOOST_NOEXCEPT{return this->final_max_size_();}
  220. void resize(size_type n)
  221. {
  222. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  223. if(n>size()){
  224. for(size_type m=n-size();m--;)
  225. this->final_emplace_(BOOST_MULTI_INDEX_NULL_PARAM_PACK);
  226. }
  227. else if(n<size()){for(size_type m=size()-n;m--;)pop_back();}
  228. }
  229. void resize(size_type n,value_param_type x)
  230. {
  231. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  232. if(n>size())insert(end(),static_cast<size_type>(n-size()),x);
  233. else if(n<size())for(size_type m=size()-n;m--;)pop_back();
  234. }
  235. /* access: no non-const versions provided as sequenced_index
  236. * handles const elements.
  237. */
  238. const_reference front()const{return *begin();}
  239. const_reference back()const{return *--end();}
  240. /* modifiers */
  241. BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
  242. pair_return_type,emplace_front,emplace_front_impl)
  243. std::pair<iterator,bool> push_front(const value_type& x)
  244. {return insert(begin(),x);}
  245. std::pair<iterator,bool> push_front(BOOST_RV_REF(value_type) x)
  246. {return insert(begin(),boost::move(x));}
  247. void pop_front(){erase(begin());}
  248. BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
  249. pair_return_type,emplace_back,emplace_back_impl)
  250. std::pair<iterator,bool> push_back(const value_type& x)
  251. {return insert(end(),x);}
  252. std::pair<iterator,bool> push_back(BOOST_RV_REF(value_type) x)
  253. {return insert(end(),boost::move(x));}
  254. void pop_back(){erase(--end());}
  255. BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
  256. pair_return_type,emplace,emplace_impl,iterator,position)
  257. std::pair<iterator,bool> insert(iterator position,const value_type& x)
  258. {
  259. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  260. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  261. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  262. std::pair<final_node_type*,bool> p=this->final_insert_(x);
  263. if(p.second&&position.get_node()!=header()){
  264. relink(position.get_node(),p.first);
  265. }
  266. return std::pair<iterator,bool>(make_iterator(p.first),p.second);
  267. }
  268. std::pair<iterator,bool> insert(iterator position,BOOST_RV_REF(value_type) x)
  269. {
  270. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  271. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  272. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  273. std::pair<final_node_type*,bool> p=this->final_insert_rv_(x);
  274. if(p.second&&position.get_node()!=header()){
  275. relink(position.get_node(),p.first);
  276. }
  277. return std::pair<iterator,bool>(make_iterator(p.first),p.second);
  278. }
  279. void insert(iterator position,size_type n,value_param_type x)
  280. {
  281. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  282. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  283. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  284. for(size_type i=0;i<n;++i)insert(position,x);
  285. }
  286. template<typename InputIterator>
  287. void insert(iterator position,InputIterator first,InputIterator last)
  288. {
  289. insert_iter(position,first,last,mpl::not_<is_integral<InputIterator> >());
  290. }
  291. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  292. void insert(iterator position,std::initializer_list<value_type> list)
  293. {
  294. insert(position,list.begin(),list.end());
  295. }
  296. #endif
  297. insert_return_type insert(const_iterator position,BOOST_RV_REF(node_type) nh)
  298. {
  299. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  300. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  301. if(nh)BOOST_MULTI_INDEX_CHECK_EQUAL_ALLOCATORS(*this,nh);
  302. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  303. std::pair<final_node_type*,bool> p=this->final_insert_nh_(nh);
  304. if(p.second&&position.get_node()!=header()){
  305. relink(position.get_node(),p.first);
  306. }
  307. return insert_return_type(make_iterator(p.first),p.second,boost::move(nh));
  308. }
  309. node_type extract(const_iterator position)
  310. {
  311. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  312. BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
  313. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  314. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  315. return this->final_extract_(
  316. static_cast<final_node_type*>(position.get_node()));
  317. }
  318. iterator erase(iterator position)
  319. {
  320. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  321. BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
  322. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  323. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  324. this->final_erase_(static_cast<final_node_type*>(position++.get_node()));
  325. return position;
  326. }
  327. iterator erase(iterator first,iterator last)
  328. {
  329. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
  330. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
  331. BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,*this);
  332. BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,*this);
  333. BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
  334. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  335. while(first!=last){
  336. first=erase(first);
  337. }
  338. return first;
  339. }
  340. bool replace(iterator position,const value_type& x)
  341. {
  342. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  343. BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
  344. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  345. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  346. return this->final_replace_(
  347. x,static_cast<final_node_type*>(position.get_node()));
  348. }
  349. bool replace(iterator position,BOOST_RV_REF(value_type) x)
  350. {
  351. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  352. BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
  353. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  354. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  355. return this->final_replace_rv_(
  356. x,static_cast<final_node_type*>(position.get_node()));
  357. }
  358. template<typename Modifier>
  359. bool modify(iterator position,Modifier mod)
  360. {
  361. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  362. BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
  363. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  364. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  365. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  366. /* MSVC++ 6.0 optimizer on safe mode code chokes if this
  367. * this is not added. Left it for all compilers as it does no
  368. * harm.
  369. */
  370. position.detach();
  371. #endif
  372. return this->final_modify_(
  373. mod,static_cast<final_node_type*>(position.get_node()));
  374. }
  375. template<typename Modifier,typename Rollback>
  376. bool modify(iterator position,Modifier mod,Rollback back_)
  377. {
  378. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  379. BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
  380. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  381. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  382. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  383. /* MSVC++ 6.0 optimizer on safe mode code chokes if this
  384. * this is not added. Left it for all compilers as it does no
  385. * harm.
  386. */
  387. position.detach();
  388. #endif
  389. return this->final_modify_(
  390. mod,back_,static_cast<final_node_type*>(position.get_node()));
  391. }
  392. void swap(sequenced_index<SuperMeta,TagList>& x)
  393. {
  394. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  395. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x);
  396. this->final_swap_(x.final());
  397. }
  398. void clear()BOOST_NOEXCEPT
  399. {
  400. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  401. this->final_clear_();
  402. }
  403. /* list operations */
  404. template<typename Index>
  405. BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(sequenced_index,Index,void)
  406. splice(iterator position,Index& x)
  407. {
  408. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  409. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  410. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  411. if(x.end().get_node()==this->header()){ /* same container */
  412. BOOST_MULTI_INDEX_SAFE_MODE_ASSERT(
  413. position==end(),safe_mode::inside_range);
  414. }
  415. else{
  416. external_splice(
  417. position,x,x.begin(),x.end(),
  418. boost::is_copy_constructible<value_type>());
  419. }
  420. }
  421. template<typename Index>
  422. BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(sequenced_index,Index,void)
  423. splice(iterator position,BOOST_RV_REF(Index) x)
  424. {
  425. splice(position,static_cast<Index&>(x));
  426. }
  427. template<typename Index>
  428. BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(
  429. sequenced_index,Index,pair_return_type)
  430. splice(
  431. iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i)
  432. {
  433. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  434. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  435. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(i);
  436. BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(i);
  437. BOOST_MULTI_INDEX_CHECK_IS_OWNER(i,x);
  438. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  439. if(x.end().get_node()==this->header()){ /* same container */
  440. index_node_type* pn=position.get_node();
  441. index_node_type* in=static_cast<index_node_type*>(i.get_node());
  442. if(pn!=in)relink(pn,in);
  443. return std::pair<iterator,bool>(make_iterator(in),true);
  444. }
  445. else{
  446. std::pair<final_node_type*,bool> p=
  447. external_splice(
  448. position,x,i,boost::is_copy_constructible<value_type>());
  449. return std::pair<iterator,bool>(make_iterator(p.first),p.second);
  450. }
  451. }
  452. template<typename Index>
  453. BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(
  454. sequenced_index,Index,pair_return_type)
  455. splice(
  456. iterator position,BOOST_RV_REF(Index) x,
  457. BOOST_DEDUCED_TYPENAME Index::iterator i)
  458. {
  459. return splice(position,static_cast<Index&>(x),i);
  460. }
  461. template<typename Index>
  462. BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(sequenced_index,Index,void)
  463. splice(
  464. iterator position,Index& x,
  465. BOOST_DEDUCED_TYPENAME Index::iterator first,
  466. BOOST_DEDUCED_TYPENAME Index::iterator last)
  467. {
  468. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  469. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  470. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
  471. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
  472. BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,x);
  473. BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,x);
  474. BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
  475. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  476. if(x.end().get_node()==this->header()){ /* same container */
  477. BOOST_MULTI_INDEX_CHECK_OUTSIDE_RANGE(position,first,last);
  478. internal_splice(position,first,last);
  479. }
  480. else{
  481. external_splice(
  482. position,x,first,last,boost::is_copy_constructible<value_type>());
  483. }
  484. }
  485. template<typename Index>
  486. BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(sequenced_index,Index,void)
  487. splice(
  488. iterator position,BOOST_RV_REF(Index) x,
  489. BOOST_DEDUCED_TYPENAME Index::iterator first,
  490. BOOST_DEDUCED_TYPENAME Index::iterator last)
  491. {
  492. splice(position,static_cast<Index&>(x),first,last);
  493. }
  494. void remove(value_param_type value)
  495. {
  496. sequenced_index_remove(
  497. *this,
  498. ::boost::bind<bool>(
  499. std::equal_to<value_type>(),::boost::arg<1>(),value));
  500. }
  501. template<typename Predicate>
  502. void remove_if(Predicate pred)
  503. {
  504. sequenced_index_remove(*this,pred);
  505. }
  506. void unique()
  507. {
  508. sequenced_index_unique(*this,std::equal_to<value_type>());
  509. }
  510. template <class BinaryPredicate>
  511. void unique(BinaryPredicate binary_pred)
  512. {
  513. sequenced_index_unique(*this,binary_pred);
  514. }
  515. void merge(sequenced_index<SuperMeta,TagList>& x)
  516. {
  517. sequenced_index_merge(*this,x,std::less<value_type>());
  518. }
  519. template <typename Compare>
  520. void merge(sequenced_index<SuperMeta,TagList>& x,Compare comp)
  521. {
  522. sequenced_index_merge(*this,x,comp);
  523. }
  524. void sort()
  525. {
  526. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  527. sequenced_index_sort(header(),std::less<value_type>());
  528. }
  529. template <typename Compare>
  530. void sort(Compare comp)
  531. {
  532. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  533. sequenced_index_sort(header(),comp);
  534. }
  535. void reverse()BOOST_NOEXCEPT
  536. {
  537. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  538. node_impl_type::reverse(header()->impl());
  539. }
  540. /* rearrange operations */
  541. void relocate(iterator position,iterator i)
  542. {
  543. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  544. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  545. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(i);
  546. BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(i);
  547. BOOST_MULTI_INDEX_CHECK_IS_OWNER(i,*this);
  548. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  549. if(position!=i)relink(position.get_node(),i.get_node());
  550. }
  551. void relocate(iterator position,iterator first,iterator last)
  552. {
  553. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  554. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  555. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
  556. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
  557. BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,*this);
  558. BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,*this);
  559. BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
  560. BOOST_MULTI_INDEX_CHECK_OUTSIDE_RANGE(position,first,last);
  561. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  562. if(position!=last)relink(
  563. position.get_node(),first.get_node(),last.get_node());
  564. }
  565. template<typename InputIterator>
  566. void rearrange(InputIterator first)
  567. {
  568. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  569. index_node_type* pos=header();
  570. for(size_type s=size();s--;){
  571. const value_type& v=*first++;
  572. relink(pos,node_from_value<index_node_type>(&v));
  573. }
  574. }
  575. BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
  576. sequenced_index(const ctor_args_list& args_list,const allocator_type& al):
  577. super(args_list.get_tail(),al)
  578. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  579. ,safe(*this)
  580. #endif
  581. {
  582. empty_initialize();
  583. }
  584. sequenced_index(const sequenced_index<SuperMeta,TagList>& x):
  585. super(x)
  586. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  587. ,safe(*this)
  588. #endif
  589. {
  590. /* the actual copying takes place in subsequent call to copy_() */
  591. }
  592. sequenced_index(
  593. const sequenced_index<SuperMeta,TagList>& x,do_not_copy_elements_tag):
  594. super(x,do_not_copy_elements_tag())
  595. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  596. ,safe(*this)
  597. #endif
  598. {
  599. empty_initialize();
  600. }
  601. ~sequenced_index()
  602. {
  603. /* the container is guaranteed to be empty by now */
  604. }
  605. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  606. iterator make_iterator(index_node_type* node)
  607. {return iterator(node,&safe);}
  608. const_iterator make_iterator(index_node_type* node)const
  609. {return const_iterator(node,const_cast<safe_container*>(&safe));}
  610. #else
  611. iterator make_iterator(index_node_type* node){return iterator(node);}
  612. const_iterator make_iterator(index_node_type* node)const
  613. {return const_iterator(node);}
  614. #endif
  615. void copy_(
  616. const sequenced_index<SuperMeta,TagList>& x,const copy_map_type& map)
  617. {
  618. index_node_type* org=x.header();
  619. index_node_type* cpy=header();
  620. do{
  621. index_node_type* next_org=index_node_type::from_impl(org->next());
  622. index_node_type* next_cpy=map.find(
  623. static_cast<final_node_type*>(next_org));
  624. cpy->next()=next_cpy->impl();
  625. next_cpy->prior()=cpy->impl();
  626. org=next_org;
  627. cpy=next_cpy;
  628. }while(org!=x.header());
  629. super::copy_(x,map);
  630. }
  631. template<typename Variant>
  632. final_node_type* insert_(
  633. value_param_type v,final_node_type*& x,Variant variant)
  634. {
  635. final_node_type* res=super::insert_(v,x,variant);
  636. if(res==x)link(static_cast<index_node_type*>(x));
  637. return res;
  638. }
  639. template<typename Variant>
  640. final_node_type* insert_(
  641. value_param_type v,index_node_type* position,
  642. final_node_type*& x,Variant variant)
  643. {
  644. final_node_type* res=super::insert_(v,position,x,variant);
  645. if(res==x)link(static_cast<index_node_type*>(x));
  646. return res;
  647. }
  648. template<typename Dst>
  649. void extract_(index_node_type* x,Dst dst)
  650. {
  651. unlink(x);
  652. super::extract_(x,dst.next());
  653. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  654. transfer_iterators(dst.get(),x);
  655. #endif
  656. }
  657. void delete_all_nodes_()
  658. {
  659. for(index_node_type* x=index_node_type::from_impl(header()->next());
  660. x!=header();){
  661. index_node_type* y=index_node_type::from_impl(x->next());
  662. this->final_delete_node_(static_cast<final_node_type*>(x));
  663. x=y;
  664. }
  665. }
  666. void clear_()
  667. {
  668. super::clear_();
  669. empty_initialize();
  670. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  671. safe.detach_dereferenceable_iterators();
  672. #endif
  673. }
  674. template<typename BoolConstant>
  675. void swap_(
  676. sequenced_index<SuperMeta,TagList>& x,BoolConstant swap_allocators)
  677. {
  678. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  679. safe.swap(x.safe);
  680. #endif
  681. super::swap_(x,swap_allocators);
  682. }
  683. void swap_elements_(sequenced_index<SuperMeta,TagList>& x)
  684. {
  685. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  686. safe.swap(x.safe);
  687. #endif
  688. super::swap_elements_(x);
  689. }
  690. template<typename Variant>
  691. bool replace_(value_param_type v,index_node_type* x,Variant variant)
  692. {
  693. return super::replace_(v,x,variant);
  694. }
  695. bool modify_(index_node_type* x)
  696. {
  697. BOOST_TRY{
  698. if(!super::modify_(x)){
  699. unlink(x);
  700. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  701. detach_iterators(x);
  702. #endif
  703. return false;
  704. }
  705. else return true;
  706. }
  707. BOOST_CATCH(...){
  708. unlink(x);
  709. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  710. detach_iterators(x);
  711. #endif
  712. BOOST_RETHROW;
  713. }
  714. BOOST_CATCH_END
  715. }
  716. bool modify_rollback_(index_node_type* x)
  717. {
  718. return super::modify_rollback_(x);
  719. }
  720. bool check_rollback_(index_node_type* x)const
  721. {
  722. return super::check_rollback_(x);
  723. }
  724. #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
  725. /* serialization */
  726. template<typename Archive>
  727. void save_(
  728. Archive& ar,const unsigned int version,const index_saver_type& sm)const
  729. {
  730. sm.save(begin(),end(),ar,version);
  731. super::save_(ar,version,sm);
  732. }
  733. template<typename Archive>
  734. void load_(
  735. Archive& ar,const unsigned int version,const index_loader_type& lm)
  736. {
  737. lm.load(
  738. ::boost::bind(
  739. &sequenced_index::rearranger,this,::boost::arg<1>(),::boost::arg<2>()),
  740. ar,version);
  741. super::load_(ar,version,lm);
  742. }
  743. #endif
  744. #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
  745. /* invariant stuff */
  746. bool invariant_()const
  747. {
  748. if(size()==0||begin()==end()){
  749. if(size()!=0||begin()!=end()||
  750. header()->next()!=header()->impl()||
  751. header()->prior()!=header()->impl())return false;
  752. }
  753. else{
  754. size_type s=0;
  755. for(const_iterator it=begin(),it_end=end();it!=it_end;++it,++s){
  756. if(it.get_node()->next()->prior()!=it.get_node()->impl())return false;
  757. if(it.get_node()->prior()->next()!=it.get_node()->impl())return false;
  758. }
  759. if(s!=size())return false;
  760. }
  761. return super::invariant_();
  762. }
  763. /* This forwarding function eases things for the boost::mem_fn construct
  764. * in BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT. Actually,
  765. * final_check_invariant is already an inherited member function of index.
  766. */
  767. void check_invariant_()const{this->final_check_invariant_();}
  768. #endif
  769. private:
  770. index_node_type* header()const{return this->final_header();}
  771. void empty_initialize()
  772. {
  773. header()->prior()=header()->next()=header()->impl();
  774. }
  775. void link(index_node_type* x)
  776. {
  777. node_impl_type::link(x->impl(),header()->impl());
  778. }
  779. static void unlink(index_node_type* x)
  780. {
  781. node_impl_type::unlink(x->impl());
  782. }
  783. static void relink(index_node_type* position,index_node_type* x)
  784. {
  785. node_impl_type::relink(position->impl(),x->impl());
  786. }
  787. static void relink(
  788. index_node_type* position,index_node_type* first,index_node_type* last)
  789. {
  790. node_impl_type::relink(
  791. position->impl(),first->impl(),last->impl());
  792. }
  793. #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
  794. void rearranger(index_node_type* position,index_node_type *x)
  795. {
  796. if(!position)position=header();
  797. index_node_type::increment(position);
  798. if(position!=x)relink(position,x);
  799. }
  800. #endif
  801. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  802. void detach_iterators(index_node_type* x)
  803. {
  804. iterator it=make_iterator(x);
  805. safe_mode::detach_equivalent_iterators(it);
  806. }
  807. template<typename Dst>
  808. void transfer_iterators(Dst& dst,index_node_type* x)
  809. {
  810. iterator it=make_iterator(x);
  811. safe_mode::transfer_equivalent_iterators(dst,it);
  812. }
  813. #endif
  814. template <class InputIterator>
  815. void assign_iter(InputIterator first,InputIterator last,mpl::true_)
  816. {
  817. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  818. clear();
  819. for(;first!=last;++first)this->final_insert_ref_(*first);
  820. }
  821. void assign_iter(size_type n,value_param_type value,mpl::false_)
  822. {
  823. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  824. clear();
  825. for(size_type i=0;i<n;++i)push_back(value);
  826. }
  827. template<typename InputIterator>
  828. void insert_iter(
  829. iterator position,InputIterator first,InputIterator last,mpl::true_)
  830. {
  831. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  832. for(;first!=last;++first){
  833. std::pair<final_node_type*,bool> p=
  834. this->final_insert_ref_(*first);
  835. if(p.second&&position.get_node()!=header()){
  836. relink(position.get_node(),p.first);
  837. }
  838. }
  839. }
  840. void insert_iter(
  841. iterator position,size_type n,value_param_type x,mpl::false_)
  842. {
  843. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  844. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  845. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  846. for(size_type i=0;i<n;++i)insert(position,x);
  847. }
  848. template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
  849. std::pair<iterator,bool> emplace_front_impl(
  850. BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
  851. {
  852. return emplace_impl(begin(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
  853. }
  854. template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
  855. std::pair<iterator,bool> emplace_back_impl(
  856. BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
  857. {
  858. return emplace_impl(end(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
  859. }
  860. template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
  861. std::pair<iterator,bool> emplace_impl(
  862. iterator position,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
  863. {
  864. BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
  865. BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
  866. BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
  867. std::pair<final_node_type*,bool> p=
  868. this->final_emplace_(BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
  869. if(p.second&&position.get_node()!=header()){
  870. relink(position.get_node(),p.first);
  871. }
  872. return std::pair<iterator,bool>(make_iterator(p.first),p.second);
  873. }
  874. template<typename Index>
  875. std::pair<final_node_type*,bool> external_splice(
  876. iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i,
  877. boost::true_type /* copy-constructible value */)
  878. {
  879. if(get_allocator()==x.get_allocator()){
  880. return external_splice(position,x,i,boost::false_type());
  881. }
  882. else{
  883. /* backwards compatibility with old, non-transfer-based splice */
  884. std::pair<iterator,bool> p=insert(position,*i);
  885. if(p.second)x.erase(i);
  886. return std::pair<final_node_type*,bool>(
  887. static_cast<final_node_type*>(p.first.get_node()),p.second);
  888. }
  889. }
  890. template<typename Index>
  891. std::pair<final_node_type*,bool> external_splice(
  892. iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i,
  893. boost::false_type /* copy-constructible value */)
  894. {
  895. BOOST_MULTI_INDEX_CHECK_EQUAL_ALLOCATORS(*this,x);
  896. std::pair<final_node_type*,bool> p=this->final_transfer_(
  897. x,static_cast<final_node_type*>(i.get_node()));
  898. if(p.second&&position.get_node()!=header()){
  899. relink(position.get_node(),p.first);
  900. }
  901. return p;
  902. }
  903. template<typename Iterator>
  904. void internal_splice(iterator position,Iterator first,Iterator last)
  905. {
  906. index_node_type* pn=position.get_node();
  907. while(first!=last){
  908. relink(pn,static_cast<index_node_type*>((first++).get_node()));
  909. }
  910. }
  911. void internal_splice(iterator position,iterator first,iterator last)
  912. {
  913. index_node_type* pn=position.get_node();
  914. index_node_type* fn=static_cast<index_node_type*>(first.get_node());
  915. index_node_type* ln=static_cast<index_node_type*>(last.get_node());
  916. if(pn!=ln)relink(pn,fn,ln);
  917. }
  918. template<typename Index>
  919. void external_splice(
  920. iterator position,Index& x,
  921. BOOST_DEDUCED_TYPENAME Index::iterator first,
  922. BOOST_DEDUCED_TYPENAME Index::iterator last,
  923. boost::true_type /* copy-constructible value */)
  924. {
  925. if(get_allocator()==x.get_allocator()){
  926. external_splice(position,x,first,last,boost::false_type());
  927. }
  928. else{
  929. /* backwards compatibility with old, non-transfer-based splice */
  930. while(first!=last){
  931. if(insert(position,*first).second)first=x.erase(first);
  932. else ++first;
  933. }
  934. }
  935. }
  936. template<typename Index>
  937. void external_splice(
  938. iterator position,Index& x,
  939. BOOST_DEDUCED_TYPENAME Index::iterator first,
  940. BOOST_DEDUCED_TYPENAME Index::iterator last,
  941. boost::false_type /* copy-constructible value */)
  942. {
  943. BOOST_MULTI_INDEX_CHECK_EQUAL_ALLOCATORS(*this,x);
  944. if(position==end()){
  945. this->final_transfer_range_(x,first,last);
  946. }
  947. else{
  948. iterator first_to_relink=end();
  949. --first_to_relink;
  950. BOOST_TRY{
  951. this->final_transfer_range_(x,first,last);
  952. }
  953. BOOST_CATCH(...){
  954. ++first_to_relink;
  955. relink(position.get_node(),first_to_relink.get_node(),header());
  956. }
  957. BOOST_CATCH_END
  958. ++first_to_relink;
  959. relink(position.get_node(),first_to_relink.get_node(),header());
  960. }
  961. }
  962. #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
  963. safe_container safe;
  964. #endif
  965. #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
  966. BOOST_WORKAROUND(__MWERKS__,<=0x3003)
  967. #pragma parse_mfunc_templ reset
  968. #endif
  969. };
  970. #if defined(BOOST_MSVC)
  971. #pragma warning(pop) /* C4355 */
  972. #endif
  973. /* comparison */
  974. template<
  975. typename SuperMeta1,typename TagList1,
  976. typename SuperMeta2,typename TagList2
  977. >
  978. bool operator==(
  979. const sequenced_index<SuperMeta1,TagList1>& x,
  980. const sequenced_index<SuperMeta2,TagList2>& y)
  981. {
  982. return x.size()==y.size()&&std::equal(x.begin(),x.end(),y.begin());
  983. }
  984. template<
  985. typename SuperMeta1,typename TagList1,
  986. typename SuperMeta2,typename TagList2
  987. >
  988. bool operator<(
  989. const sequenced_index<SuperMeta1,TagList1>& x,
  990. const sequenced_index<SuperMeta2,TagList2>& y)
  991. {
  992. return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
  993. }
  994. template<
  995. typename SuperMeta1,typename TagList1,
  996. typename SuperMeta2,typename TagList2
  997. >
  998. bool operator!=(
  999. const sequenced_index<SuperMeta1,TagList1>& x,
  1000. const sequenced_index<SuperMeta2,TagList2>& y)
  1001. {
  1002. return !(x==y);
  1003. }
  1004. template<
  1005. typename SuperMeta1,typename TagList1,
  1006. typename SuperMeta2,typename TagList2
  1007. >
  1008. bool operator>(
  1009. const sequenced_index<SuperMeta1,TagList1>& x,
  1010. const sequenced_index<SuperMeta2,TagList2>& y)
  1011. {
  1012. return y<x;
  1013. }
  1014. template<
  1015. typename SuperMeta1,typename TagList1,
  1016. typename SuperMeta2,typename TagList2
  1017. >
  1018. bool operator>=(
  1019. const sequenced_index<SuperMeta1,TagList1>& x,
  1020. const sequenced_index<SuperMeta2,TagList2>& y)
  1021. {
  1022. return !(x<y);
  1023. }
  1024. template<
  1025. typename SuperMeta1,typename TagList1,
  1026. typename SuperMeta2,typename TagList2
  1027. >
  1028. bool operator<=(
  1029. const sequenced_index<SuperMeta1,TagList1>& x,
  1030. const sequenced_index<SuperMeta2,TagList2>& y)
  1031. {
  1032. return !(x>y);
  1033. }
  1034. /* specialized algorithms */
  1035. template<typename SuperMeta,typename TagList>
  1036. void swap(
  1037. sequenced_index<SuperMeta,TagList>& x,
  1038. sequenced_index<SuperMeta,TagList>& y)
  1039. {
  1040. x.swap(y);
  1041. }
  1042. } /* namespace multi_index::detail */
  1043. /* sequenced index specifier */
  1044. template <typename TagList>
  1045. struct sequenced
  1046. {
  1047. BOOST_STATIC_ASSERT(detail::is_tag<TagList>::value);
  1048. template<typename Super>
  1049. struct node_class
  1050. {
  1051. typedef detail::sequenced_index_node<Super> type;
  1052. };
  1053. template<typename SuperMeta>
  1054. struct index_class
  1055. {
  1056. typedef detail::sequenced_index<SuperMeta,typename TagList::type> type;
  1057. };
  1058. };
  1059. } /* namespace multi_index */
  1060. } /* namespace boost */
  1061. /* Boost.Foreach compatibility */
  1062. namespace boost{
  1063. namespace foreach{
  1064. template<typename>
  1065. struct is_noncopyable;
  1066. template<typename SuperMeta,typename TagList>
  1067. struct is_noncopyable<
  1068. boost::multi_index::detail::sequenced_index<SuperMeta,TagList>
  1069. >:boost::mpl::true_{};
  1070. }
  1071. }
  1072. #undef BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT
  1073. #undef BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF
  1074. #endif