1 /* Copyright 2003-2014 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)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_SEQUENCED_INDEX_HPP
10 #define BOOST_MULTI_INDEX_SEQUENCED_INDEX_HPP
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/call_traits.hpp>
18 #include <boost/detail/allocator_utilities.hpp>
19 #include <boost/detail/no_exceptions_support.hpp>
20 #include <boost/detail/workaround.hpp>
21 #include <boost/foreach_fwd.hpp>
22 #include <boost/iterator/reverse_iterator.hpp>
23 #include <boost/move/core.hpp>
24 #include <boost/move/utility.hpp>
25 #include <boost/mpl/bool.hpp>
26 #include <boost/mpl/not.hpp>
27 #include <boost/mpl/push_front.hpp>
28 #include <boost/multi_index/detail/access_specifier.hpp>
29 #include <boost/multi_index/detail/bidir_node_iterator.hpp>
30 #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
31 #include <boost/multi_index/detail/index_node_base.hpp>
32 #include <boost/multi_index/detail/safe_mode.hpp>
33 #include <boost/multi_index/detail/scope_guard.hpp>
34 #include <boost/multi_index/detail/seq_index_node.hpp>
35 #include <boost/multi_index/detail/seq_index_ops.hpp>
36 #include <boost/multi_index/detail/vartempl_support.hpp>
37 #include <boost/multi_index/sequenced_index_fwd.hpp>
38 #include <boost/tuple/tuple.hpp>
39 #include <boost/type_traits/is_integral.hpp>
44 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
45 #include<initializer_list>
48 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
49 #include <boost/bind.hpp>
52 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
53 #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x) \
54 detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
55 detail::make_obj_guard(x,&sequenced_index::check_invariant_); \
56 BOOST_JOIN(check_invariant_,__LINE__).touch();
57 #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT \
58 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(*this)
60 #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x)
61 #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT
66 namespace multi_index{
70 /* sequenced_index adds a layer of sequenced indexing to a given Super */
72 template<typename SuperMeta,typename TagList>
73 class sequenced_index:
74 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS SuperMeta::type
76 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
77 ,public safe_mode::safe_container<
78 sequenced_index<SuperMeta,TagList> >
82 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
83 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
84 /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
85 * lifetime of const references bound to temporaries --precisely what
89 #pragma parse_mfunc_templ off
92 typedef typename SuperMeta::type super;
95 typedef sequenced_index_node<
96 typename super::node_type> node_type;
99 typedef typename node_type::impl_type node_impl_type;
104 typedef typename node_type::value_type value_type;
105 typedef tuples::null_type ctor_args;
106 typedef typename super::final_allocator_type allocator_type;
107 typedef typename allocator_type::reference reference;
108 typedef typename allocator_type::const_reference const_reference;
110 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
111 typedef safe_mode::safe_iterator<
112 bidir_node_iterator<node_type>,
113 sequenced_index> iterator;
115 typedef bidir_node_iterator<node_type> iterator;
118 typedef iterator const_iterator;
120 typedef std::size_t size_type;
121 typedef std::ptrdiff_t difference_type;
122 typedef typename allocator_type::pointer pointer;
123 typedef typename allocator_type::const_pointer const_pointer;
125 boost::reverse_iterator<iterator> reverse_iterator;
127 boost::reverse_iterator<const_iterator> const_reverse_iterator;
128 typedef TagList tag_list;
131 typedef typename super::final_node_type final_node_type;
132 typedef tuples::cons<
134 typename super::ctor_args_list> ctor_args_list;
135 typedef typename mpl::push_front<
136 typename super::index_type_list,
137 sequenced_index>::type index_type_list;
138 typedef typename mpl::push_front<
139 typename super::iterator_type_list,
140 iterator>::type iterator_type_list;
141 typedef typename mpl::push_front<
142 typename super::const_iterator_type_list,
143 const_iterator>::type const_iterator_type_list;
144 typedef typename super::copy_map_type copy_map_type;
146 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
147 typedef typename super::index_saver_type index_saver_type;
148 typedef typename super::index_loader_type index_loader_type;
152 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
153 typedef safe_mode::safe_container<
154 sequenced_index> safe_super;
157 typedef typename call_traits<value_type>::param_type value_param_type;
159 /* Needed to avoid commas in BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL
163 typedef std::pair<iterator,bool> emplace_return_type;
167 /* construct/copy/destroy
168 * Default and copy ctors are in the protected section as indices are
169 * not supposed to be created on their own. No range ctor either.
172 sequenced_index<SuperMeta,TagList>& operator=(
173 const sequenced_index<SuperMeta,TagList>& x)
175 this->final()=x.final();
179 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
180 sequenced_index<SuperMeta,TagList>& operator=(
181 std::initializer_list<value_type> list)
188 template <class InputIterator>
189 void assign(InputIterator first,InputIterator last)
191 assign_iter(first,last,mpl::not_<is_integral<InputIterator> >());
194 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
195 void assign(std::initializer_list<value_type> list)
197 assign(list.begin(),list.end());
201 void assign(size_type n,value_param_type value)
203 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
205 for(size_type i=0;i<n;++i)push_back(value);
208 allocator_type get_allocator()const BOOST_NOEXCEPT
210 return this->final().get_allocator();
215 iterator begin()BOOST_NOEXCEPT
216 {return make_iterator(node_type::from_impl(header()->next()));}
217 const_iterator begin()const BOOST_NOEXCEPT
218 {return make_iterator(node_type::from_impl(header()->next()));}
220 end()BOOST_NOEXCEPT{return make_iterator(header());}
222 end()const BOOST_NOEXCEPT{return make_iterator(header());}
224 rbegin()BOOST_NOEXCEPT{return boost::make_reverse_iterator(end());}
225 const_reverse_iterator
226 rbegin()const BOOST_NOEXCEPT{return boost::make_reverse_iterator(end());}
228 rend()BOOST_NOEXCEPT{return boost::make_reverse_iterator(begin());}
229 const_reverse_iterator
230 rend()const BOOST_NOEXCEPT{return boost::make_reverse_iterator(begin());}
232 cbegin()const BOOST_NOEXCEPT{return begin();}
234 cend()const BOOST_NOEXCEPT{return end();}
235 const_reverse_iterator
236 crbegin()const BOOST_NOEXCEPT{return rbegin();}
237 const_reverse_iterator
238 crend()const BOOST_NOEXCEPT{return rend();}
240 iterator iterator_to(const value_type& x)
242 return make_iterator(node_from_value<node_type>(&x));
245 const_iterator iterator_to(const value_type& x)const
247 return make_iterator(node_from_value<node_type>(&x));
252 bool empty()const BOOST_NOEXCEPT{return this->final_empty_();}
253 size_type size()const BOOST_NOEXCEPT{return this->final_size_();}
254 size_type max_size()const BOOST_NOEXCEPT{return this->final_max_size_();}
256 void resize(size_type n)
258 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
260 for(size_type m=n-size();m--;)
261 this->final_emplace_(BOOST_MULTI_INDEX_NULL_PARAM_PACK);
263 else if(n<size()){for(size_type m=size()-n;m--;)pop_back();}
266 void resize(size_type n,value_param_type x)
268 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
269 if(n>size())insert(end(),n-size(),x);
270 else if(n<size())for(size_type m=size()-n;m--;)pop_back();
273 /* access: no non-const versions provided as sequenced_index
274 * handles const elements.
277 const_reference front()const{return *begin();}
278 const_reference back()const{return *--end();}
282 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
283 emplace_return_type,emplace_front,emplace_front_impl)
285 std::pair<iterator,bool> push_front(const value_type& x)
286 {return insert(begin(),x);}
287 std::pair<iterator,bool> push_front(BOOST_RV_REF(value_type) x)
288 {return insert(begin(),boost::move(x));}
289 void pop_front(){erase(begin());}
291 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
292 emplace_return_type,emplace_back,emplace_back_impl)
294 std::pair<iterator,bool> push_back(const value_type& x)
295 {return insert(end(),x);}
296 std::pair<iterator,bool> push_back(BOOST_RV_REF(value_type) x)
297 {return insert(end(),boost::move(x));}
298 void pop_back(){erase(--end());}
300 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
301 emplace_return_type,emplace,emplace_impl,iterator,position)
303 std::pair<iterator,bool> insert(iterator position,const value_type& x)
305 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
306 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
307 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
308 std::pair<final_node_type*,bool> p=this->final_insert_(x);
309 if(p.second&&position.get_node()!=header()){
310 relink(position.get_node(),p.first);
312 return std::pair<iterator,bool>(make_iterator(p.first),p.second);
315 std::pair<iterator,bool> insert(iterator position,BOOST_RV_REF(value_type) x)
317 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
318 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
319 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
320 std::pair<final_node_type*,bool> p=this->final_insert_rv_(x);
321 if(p.second&&position.get_node()!=header()){
322 relink(position.get_node(),p.first);
324 return std::pair<iterator,bool>(make_iterator(p.first),p.second);
327 void insert(iterator position,size_type n,value_param_type x)
329 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
330 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
331 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
332 for(size_type i=0;i<n;++i)insert(position,x);
335 template<typename InputIterator>
336 void insert(iterator position,InputIterator first,InputIterator last)
338 insert_iter(position,first,last,mpl::not_<is_integral<InputIterator> >());
341 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
342 void insert(iterator position,std::initializer_list<value_type> list)
344 insert(position,list.begin(),list.end());
348 iterator erase(iterator position)
350 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
351 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
352 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
353 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
354 this->final_erase_(static_cast<final_node_type*>(position++.get_node()));
358 iterator erase(iterator first,iterator last)
360 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
361 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
362 BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,*this);
363 BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,*this);
364 BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
365 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
372 bool replace(iterator position,const value_type& x)
374 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
375 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
376 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
377 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
378 return this->final_replace_(
379 x,static_cast<final_node_type*>(position.get_node()));
382 bool replace(iterator position,BOOST_RV_REF(value_type) x)
384 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
385 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
386 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
387 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
388 return this->final_replace_rv_(
389 x,static_cast<final_node_type*>(position.get_node()));
392 template<typename Modifier>
393 bool modify(iterator position,Modifier mod)
395 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
396 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
397 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
398 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
400 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
401 /* MSVC++ 6.0 optimizer on safe mode code chokes if this
402 * this is not added. Left it for all compilers as it does no
409 return this->final_modify_(
410 mod,static_cast<final_node_type*>(position.get_node()));
413 template<typename Modifier,typename Rollback>
414 bool modify(iterator position,Modifier mod,Rollback back_)
416 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
417 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
418 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
419 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
421 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
422 /* MSVC++ 6.0 optimizer on safe mode code chokes if this
423 * this is not added. Left it for all compilers as it does no
430 return this->final_modify_(
431 mod,back_,static_cast<final_node_type*>(position.get_node()));
434 void swap(sequenced_index<SuperMeta,TagList>& x)
436 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
437 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x);
438 this->final_swap_(x.final());
441 void clear()BOOST_NOEXCEPT
443 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
444 this->final_clear_();
447 /* list operations */
449 void splice(iterator position,sequenced_index<SuperMeta,TagList>& x)
451 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
452 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
453 BOOST_MULTI_INDEX_CHECK_DIFFERENT_CONTAINER(*this,x);
454 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
455 iterator first=x.begin(),last=x.end();
457 if(insert(position,*first).second)first=x.erase(first);
462 void splice(iterator position,sequenced_index<SuperMeta,TagList>& x,iterator i)
464 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
465 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
466 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(i);
467 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(i);
468 BOOST_MULTI_INDEX_CHECK_IS_OWNER(i,x);
469 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
471 if(position!=i)relink(position.get_node(),i.get_node());
474 if(insert(position,*i).second){
476 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
477 /* MSVC++ 6.0 optimizer has a hard time with safe mode, and the following
478 * workaround is needed. Left it for all compilers as it does no
482 x.erase(x.make_iterator(i.get_node()));
492 iterator position,sequenced_index<SuperMeta,TagList>& x,
493 iterator first,iterator last)
495 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
496 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
497 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
498 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
499 BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,x);
500 BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,x);
501 BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
502 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
504 BOOST_MULTI_INDEX_CHECK_OUTSIDE_RANGE(position,first,last);
505 if(position!=last)relink(
506 position.get_node(),first.get_node(),last.get_node());
510 if(insert(position,*first).second)first=x.erase(first);
516 void remove(value_param_type value)
518 sequenced_index_remove(
519 *this,std::bind2nd(std::equal_to<value_type>(),value));
522 template<typename Predicate>
523 void remove_if(Predicate pred)
525 sequenced_index_remove(*this,pred);
530 sequenced_index_unique(*this,std::equal_to<value_type>());
533 template <class BinaryPredicate>
534 void unique(BinaryPredicate binary_pred)
536 sequenced_index_unique(*this,binary_pred);
539 void merge(sequenced_index<SuperMeta,TagList>& x)
541 sequenced_index_merge(*this,x,std::less<value_type>());
544 template <typename Compare>
545 void merge(sequenced_index<SuperMeta,TagList>& x,Compare comp)
547 sequenced_index_merge(*this,x,comp);
552 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
553 sequenced_index_sort(header(),std::less<value_type>());
556 template <typename Compare>
557 void sort(Compare comp)
559 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
560 sequenced_index_sort(header(),comp);
563 void reverse()BOOST_NOEXCEPT
565 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
566 node_impl_type::reverse(header()->impl());
569 /* rearrange operations */
571 void relocate(iterator position,iterator i)
573 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
574 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
575 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(i);
576 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(i);
577 BOOST_MULTI_INDEX_CHECK_IS_OWNER(i,*this);
578 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
579 if(position!=i)relink(position.get_node(),i.get_node());
582 void relocate(iterator position,iterator first,iterator last)
584 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
585 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
586 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
587 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
588 BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,*this);
589 BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,*this);
590 BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
591 BOOST_MULTI_INDEX_CHECK_OUTSIDE_RANGE(position,first,last);
592 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
593 if(position!=last)relink(
594 position.get_node(),first.get_node(),last.get_node());
597 template<typename InputIterator>
598 void rearrange(InputIterator first)
600 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
601 node_type* pos=header();
602 for(size_type s=size();s--;){
603 const value_type& v=*first++;
604 relink(pos,node_from_value<node_type>(&v));
608 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
609 sequenced_index(const ctor_args_list& args_list,const allocator_type& al):
610 super(args_list.get_tail(),al)
615 sequenced_index(const sequenced_index<SuperMeta,TagList>& x):
618 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
623 /* the actual copying takes place in subsequent call to copy_() */
627 const sequenced_index<SuperMeta,TagList>& x,do_not_copy_elements_tag):
628 super(x,do_not_copy_elements_tag())
630 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
640 /* the container is guaranteed to be empty by now */
643 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
644 iterator make_iterator(node_type* node){return iterator(node,this);}
645 const_iterator make_iterator(node_type* node)const
646 {return const_iterator(node,const_cast<sequenced_index*>(this));}
648 iterator make_iterator(node_type* node){return iterator(node);}
649 const_iterator make_iterator(node_type* node)const
650 {return const_iterator(node);}
654 const sequenced_index<SuperMeta,TagList>& x,const copy_map_type& map)
656 node_type* org=x.header();
657 node_type* cpy=header();
659 node_type* next_org=node_type::from_impl(org->next());
660 node_type* next_cpy=map.find(static_cast<final_node_type*>(next_org));
661 cpy->next()=next_cpy->impl();
662 next_cpy->prior()=cpy->impl();
665 }while(org!=x.header());
670 template<typename Variant>
671 final_node_type* insert_(
672 value_param_type v,final_node_type*& x,Variant variant)
674 final_node_type* res=super::insert_(v,x,variant);
675 if(res==x)link(static_cast<node_type*>(x));
679 template<typename Variant>
680 final_node_type* insert_(
681 value_param_type v,node_type* position,final_node_type*& x,Variant variant)
683 final_node_type* res=super::insert_(v,position,x,variant);
684 if(res==x)link(static_cast<node_type*>(x));
688 void erase_(node_type* x)
693 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
698 void delete_all_nodes_()
700 for(node_type* x=node_type::from_impl(header()->next());x!=header();){
701 node_type* y=node_type::from_impl(x->next());
702 this->final_delete_node_(static_cast<final_node_type*>(x));
712 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
713 safe_super::detach_dereferenceable_iterators();
717 void swap_(sequenced_index<SuperMeta,TagList>& x)
719 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
726 void swap_elements_(sequenced_index<SuperMeta,TagList>& x)
728 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
732 super::swap_elements_(x);
735 template<typename Variant>
736 bool replace_(value_param_type v,node_type* x,Variant variant)
738 return super::replace_(v,x,variant);
741 bool modify_(node_type* x)
744 if(!super::modify_(x)){
747 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
758 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
767 bool modify_rollback_(node_type* x)
769 return super::modify_rollback_(x);
772 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
775 template<typename Archive>
777 Archive& ar,const unsigned int version,const index_saver_type& sm)const
779 sm.save(begin(),end(),ar,version);
780 super::save_(ar,version,sm);
783 template<typename Archive>
785 Archive& ar,const unsigned int version,const index_loader_type& lm)
789 &sequenced_index::rearranger,this,::boost::arg<1>(),::boost::arg<2>()),
791 super::load_(ar,version,lm);
795 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
796 /* invariant stuff */
798 bool invariant_()const
800 if(size()==0||begin()==end()){
801 if(size()!=0||begin()!=end()||
802 header()->next()!=header()->impl()||
803 header()->prior()!=header()->impl())return false;
807 for(const_iterator it=begin(),it_end=end();it!=it_end;++it,++s){
808 if(it.get_node()->next()->prior()!=it.get_node()->impl())return false;
809 if(it.get_node()->prior()->next()!=it.get_node()->impl())return false;
811 if(s!=size())return false;
814 return super::invariant_();
817 /* This forwarding function eases things for the boost::mem_fn construct
818 * in BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT. Actually,
819 * final_check_invariant is already an inherited member function of index.
821 void check_invariant_()const{this->final_check_invariant_();}
825 node_type* header()const{return this->final_header();}
827 void empty_initialize()
829 header()->prior()=header()->next()=header()->impl();
832 void link(node_type* x)
834 node_impl_type::link(x->impl(),header()->impl());
837 static void unlink(node_type* x)
839 node_impl_type::unlink(x->impl());
842 static void relink(node_type* position,node_type* x)
844 node_impl_type::relink(position->impl(),x->impl());
847 static void relink(node_type* position,node_type* first,node_type* last)
849 node_impl_type::relink(
850 position->impl(),first->impl(),last->impl());
853 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
854 void rearranger(node_type* position,node_type *x)
856 if(!position)position=header();
857 node_type::increment(position);
858 if(position!=x)relink(position,x);
862 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
863 void detach_iterators(node_type* x)
865 iterator it=make_iterator(x);
866 safe_mode::detach_equivalent_iterators(it);
870 template <class InputIterator>
871 void assign_iter(InputIterator first,InputIterator last,mpl::true_)
873 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
875 for(;first!=last;++first)this->final_insert_ref_(*first);
878 void assign_iter(size_type n,value_param_type value,mpl::false_)
880 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
882 for(size_type i=0;i<n;++i)push_back(value);
885 template<typename InputIterator>
887 iterator position,InputIterator first,InputIterator last,mpl::true_)
889 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
890 for(;first!=last;++first){
891 std::pair<final_node_type*,bool> p=
892 this->final_insert_ref_(*first);
893 if(p.second&&position.get_node()!=header()){
894 relink(position.get_node(),p.first);
900 iterator position,size_type n,value_param_type x,mpl::false_)
902 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
903 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
904 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
905 for(size_type i=0;i<n;++i)insert(position,x);
908 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
909 std::pair<iterator,bool> emplace_front_impl(
910 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
912 return emplace_impl(begin(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
915 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
916 std::pair<iterator,bool> emplace_back_impl(
917 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
919 return emplace_impl(end(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
922 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
923 std::pair<iterator,bool> emplace_impl(
924 iterator position,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
926 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
927 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
928 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
929 std::pair<final_node_type*,bool> p=
930 this->final_emplace_(BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
931 if(p.second&&position.get_node()!=header()){
932 relink(position.get_node(),p.first);
934 return std::pair<iterator,bool>(make_iterator(p.first),p.second);
937 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
938 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
939 #pragma parse_mfunc_templ reset
946 typename SuperMeta1,typename TagList1,
947 typename SuperMeta2,typename TagList2
950 const sequenced_index<SuperMeta1,TagList1>& x,
951 const sequenced_index<SuperMeta2,TagList2>& y)
953 return x.size()==y.size()&&std::equal(x.begin(),x.end(),y.begin());
957 typename SuperMeta1,typename TagList1,
958 typename SuperMeta2,typename TagList2
961 const sequenced_index<SuperMeta1,TagList1>& x,
962 const sequenced_index<SuperMeta2,TagList2>& y)
964 return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
968 typename SuperMeta1,typename TagList1,
969 typename SuperMeta2,typename TagList2
972 const sequenced_index<SuperMeta1,TagList1>& x,
973 const sequenced_index<SuperMeta2,TagList2>& y)
979 typename SuperMeta1,typename TagList1,
980 typename SuperMeta2,typename TagList2
983 const sequenced_index<SuperMeta1,TagList1>& x,
984 const sequenced_index<SuperMeta2,TagList2>& y)
990 typename SuperMeta1,typename TagList1,
991 typename SuperMeta2,typename TagList2
994 const sequenced_index<SuperMeta1,TagList1>& x,
995 const sequenced_index<SuperMeta2,TagList2>& y)
1001 typename SuperMeta1,typename TagList1,
1002 typename SuperMeta2,typename TagList2
1005 const sequenced_index<SuperMeta1,TagList1>& x,
1006 const sequenced_index<SuperMeta2,TagList2>& y)
1011 /* specialized algorithms */
1013 template<typename SuperMeta,typename TagList>
1015 sequenced_index<SuperMeta,TagList>& x,
1016 sequenced_index<SuperMeta,TagList>& y)
1021 } /* namespace multi_index::detail */
1023 /* sequenced index specifier */
1025 template <typename TagList>
1028 BOOST_STATIC_ASSERT(detail::is_tag<TagList>::value);
1030 template<typename Super>
1033 typedef detail::sequenced_index_node<Super> type;
1036 template<typename SuperMeta>
1039 typedef detail::sequenced_index<SuperMeta,typename TagList::type> type;
1043 } /* namespace multi_index */
1045 } /* namespace boost */
1047 /* Boost.Foreach compatibility */
1049 template<typename SuperMeta,typename TagList>
1050 inline boost::mpl::true_* boost_foreach_is_noncopyable(
1051 boost::multi_index::detail::sequenced_index<SuperMeta,TagList>*&,
1052 boost::foreach::tag)
1057 #undef BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT
1058 #undef BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF