1 /* Copyright 2003-2017 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/bind.hpp>
18 #include <boost/call_traits.hpp>
19 #include <boost/detail/allocator_utilities.hpp>
20 #include <boost/detail/no_exceptions_support.hpp>
21 #include <boost/detail/workaround.hpp>
22 #include <boost/foreach_fwd.hpp>
23 #include <boost/iterator/reverse_iterator.hpp>
24 #include <boost/move/core.hpp>
25 #include <boost/move/utility.hpp>
26 #include <boost/mpl/bool.hpp>
27 #include <boost/mpl/not.hpp>
28 #include <boost/mpl/push_front.hpp>
29 #include <boost/multi_index/detail/access_specifier.hpp>
30 #include <boost/multi_index/detail/bidir_node_iterator.hpp>
31 #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
32 #include <boost/multi_index/detail/index_node_base.hpp>
33 #include <boost/multi_index/detail/safe_mode.hpp>
34 #include <boost/multi_index/detail/scope_guard.hpp>
35 #include <boost/multi_index/detail/seq_index_node.hpp>
36 #include <boost/multi_index/detail/seq_index_ops.hpp>
37 #include <boost/multi_index/detail/vartempl_support.hpp>
38 #include <boost/multi_index/sequenced_index_fwd.hpp>
39 #include <boost/tuple/tuple.hpp>
40 #include <boost/type_traits/is_integral.hpp>
45 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
46 #include<initializer_list>
49 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
50 #include <boost/bind.hpp>
53 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
54 #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x) \
55 detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
56 detail::make_obj_guard(x,&sequenced_index::check_invariant_); \
57 BOOST_JOIN(check_invariant_,__LINE__).touch();
58 #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT \
59 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(*this)
61 #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x)
62 #define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT
67 namespace multi_index{
71 /* sequenced_index adds a layer of sequenced indexing to a given Super */
73 template<typename SuperMeta,typename TagList>
74 class sequenced_index:
75 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS SuperMeta::type
77 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
78 ,public safe_mode::safe_container<
79 sequenced_index<SuperMeta,TagList> >
83 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
84 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
85 /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
86 * lifetime of const references bound to temporaries --precisely what
90 #pragma parse_mfunc_templ off
93 typedef typename SuperMeta::type super;
96 typedef sequenced_index_node<
97 typename super::node_type> node_type;
100 typedef typename node_type::impl_type node_impl_type;
105 typedef typename node_type::value_type value_type;
106 typedef tuples::null_type ctor_args;
107 typedef typename super::final_allocator_type allocator_type;
108 typedef typename allocator_type::reference reference;
109 typedef typename allocator_type::const_reference const_reference;
111 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
112 typedef safe_mode::safe_iterator<
113 bidir_node_iterator<node_type>,
114 sequenced_index> iterator;
116 typedef bidir_node_iterator<node_type> iterator;
119 typedef iterator const_iterator;
121 typedef std::size_t size_type;
122 typedef std::ptrdiff_t difference_type;
123 typedef typename allocator_type::pointer pointer;
124 typedef typename allocator_type::const_pointer const_pointer;
126 boost::reverse_iterator<iterator> reverse_iterator;
128 boost::reverse_iterator<const_iterator> const_reverse_iterator;
129 typedef TagList tag_list;
132 typedef typename super::final_node_type final_node_type;
133 typedef tuples::cons<
135 typename super::ctor_args_list> ctor_args_list;
136 typedef typename mpl::push_front<
137 typename super::index_type_list,
138 sequenced_index>::type index_type_list;
139 typedef typename mpl::push_front<
140 typename super::iterator_type_list,
141 iterator>::type iterator_type_list;
142 typedef typename mpl::push_front<
143 typename super::const_iterator_type_list,
144 const_iterator>::type const_iterator_type_list;
145 typedef typename super::copy_map_type copy_map_type;
147 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
148 typedef typename super::index_saver_type index_saver_type;
149 typedef typename super::index_loader_type index_loader_type;
153 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
154 typedef safe_mode::safe_container<
155 sequenced_index> safe_super;
158 typedef typename call_traits<value_type>::param_type value_param_type;
160 /* Needed to avoid commas in BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL
164 typedef std::pair<iterator,bool> emplace_return_type;
168 /* construct/copy/destroy
169 * Default and copy ctors are in the protected section as indices are
170 * not supposed to be created on their own. No range ctor either.
173 sequenced_index<SuperMeta,TagList>& operator=(
174 const sequenced_index<SuperMeta,TagList>& x)
176 this->final()=x.final();
180 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
181 sequenced_index<SuperMeta,TagList>& operator=(
182 std::initializer_list<value_type> list)
189 template <class InputIterator>
190 void assign(InputIterator first,InputIterator last)
192 assign_iter(first,last,mpl::not_<is_integral<InputIterator> >());
195 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
196 void assign(std::initializer_list<value_type> list)
198 assign(list.begin(),list.end());
202 void assign(size_type n,value_param_type value)
204 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
206 for(size_type i=0;i<n;++i)push_back(value);
209 allocator_type get_allocator()const BOOST_NOEXCEPT
211 return this->final().get_allocator();
216 iterator begin()BOOST_NOEXCEPT
217 {return make_iterator(node_type::from_impl(header()->next()));}
218 const_iterator begin()const BOOST_NOEXCEPT
219 {return make_iterator(node_type::from_impl(header()->next()));}
221 end()BOOST_NOEXCEPT{return make_iterator(header());}
223 end()const BOOST_NOEXCEPT{return make_iterator(header());}
225 rbegin()BOOST_NOEXCEPT{return boost::make_reverse_iterator(end());}
226 const_reverse_iterator
227 rbegin()const BOOST_NOEXCEPT{return boost::make_reverse_iterator(end());}
229 rend()BOOST_NOEXCEPT{return boost::make_reverse_iterator(begin());}
230 const_reverse_iterator
231 rend()const BOOST_NOEXCEPT{return boost::make_reverse_iterator(begin());}
233 cbegin()const BOOST_NOEXCEPT{return begin();}
235 cend()const BOOST_NOEXCEPT{return end();}
236 const_reverse_iterator
237 crbegin()const BOOST_NOEXCEPT{return rbegin();}
238 const_reverse_iterator
239 crend()const BOOST_NOEXCEPT{return rend();}
241 iterator iterator_to(const value_type& x)
243 return make_iterator(node_from_value<node_type>(&x));
246 const_iterator iterator_to(const value_type& x)const
248 return make_iterator(node_from_value<node_type>(&x));
253 bool empty()const BOOST_NOEXCEPT{return this->final_empty_();}
254 size_type size()const BOOST_NOEXCEPT{return this->final_size_();}
255 size_type max_size()const BOOST_NOEXCEPT{return this->final_max_size_();}
257 void resize(size_type n)
259 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
261 for(size_type m=n-size();m--;)
262 this->final_emplace_(BOOST_MULTI_INDEX_NULL_PARAM_PACK);
264 else if(n<size()){for(size_type m=size()-n;m--;)pop_back();}
267 void resize(size_type n,value_param_type x)
269 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
270 if(n>size())insert(end(),n-size(),x);
271 else if(n<size())for(size_type m=size()-n;m--;)pop_back();
274 /* access: no non-const versions provided as sequenced_index
275 * handles const elements.
278 const_reference front()const{return *begin();}
279 const_reference back()const{return *--end();}
283 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
284 emplace_return_type,emplace_front,emplace_front_impl)
286 std::pair<iterator,bool> push_front(const value_type& x)
287 {return insert(begin(),x);}
288 std::pair<iterator,bool> push_front(BOOST_RV_REF(value_type) x)
289 {return insert(begin(),boost::move(x));}
290 void pop_front(){erase(begin());}
292 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
293 emplace_return_type,emplace_back,emplace_back_impl)
295 std::pair<iterator,bool> push_back(const value_type& x)
296 {return insert(end(),x);}
297 std::pair<iterator,bool> push_back(BOOST_RV_REF(value_type) x)
298 {return insert(end(),boost::move(x));}
299 void pop_back(){erase(--end());}
301 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
302 emplace_return_type,emplace,emplace_impl,iterator,position)
304 std::pair<iterator,bool> insert(iterator position,const value_type& x)
306 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
307 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
308 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
309 std::pair<final_node_type*,bool> p=this->final_insert_(x);
310 if(p.second&&position.get_node()!=header()){
311 relink(position.get_node(),p.first);
313 return std::pair<iterator,bool>(make_iterator(p.first),p.second);
316 std::pair<iterator,bool> insert(iterator position,BOOST_RV_REF(value_type) x)
318 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
319 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
320 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
321 std::pair<final_node_type*,bool> p=this->final_insert_rv_(x);
322 if(p.second&&position.get_node()!=header()){
323 relink(position.get_node(),p.first);
325 return std::pair<iterator,bool>(make_iterator(p.first),p.second);
328 void insert(iterator position,size_type n,value_param_type x)
330 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
331 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
332 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
333 for(size_type i=0;i<n;++i)insert(position,x);
336 template<typename InputIterator>
337 void insert(iterator position,InputIterator first,InputIterator last)
339 insert_iter(position,first,last,mpl::not_<is_integral<InputIterator> >());
342 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
343 void insert(iterator position,std::initializer_list<value_type> list)
345 insert(position,list.begin(),list.end());
349 iterator erase(iterator position)
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 this->final_erase_(static_cast<final_node_type*>(position++.get_node()));
359 iterator erase(iterator first,iterator last)
361 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
362 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
363 BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,*this);
364 BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,*this);
365 BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
366 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
373 bool replace(iterator position,const value_type& x)
375 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
376 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
377 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
378 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
379 return this->final_replace_(
380 x,static_cast<final_node_type*>(position.get_node()));
383 bool replace(iterator position,BOOST_RV_REF(value_type) x)
385 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
386 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
387 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
388 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
389 return this->final_replace_rv_(
390 x,static_cast<final_node_type*>(position.get_node()));
393 template<typename Modifier>
394 bool modify(iterator position,Modifier mod)
396 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
397 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
398 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
399 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
401 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
402 /* MSVC++ 6.0 optimizer on safe mode code chokes if this
403 * this is not added. Left it for all compilers as it does no
410 return this->final_modify_(
411 mod,static_cast<final_node_type*>(position.get_node()));
414 template<typename Modifier,typename Rollback>
415 bool modify(iterator position,Modifier mod,Rollback back_)
417 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
418 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(position);
419 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
420 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
422 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
423 /* MSVC++ 6.0 optimizer on safe mode code chokes if this
424 * this is not added. Left it for all compilers as it does no
431 return this->final_modify_(
432 mod,back_,static_cast<final_node_type*>(position.get_node()));
435 void swap(sequenced_index<SuperMeta,TagList>& x)
437 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
438 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x);
439 this->final_swap_(x.final());
442 void clear()BOOST_NOEXCEPT
444 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
445 this->final_clear_();
448 /* list operations */
450 void splice(iterator position,sequenced_index<SuperMeta,TagList>& x)
452 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
453 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
454 BOOST_MULTI_INDEX_CHECK_DIFFERENT_CONTAINER(*this,x);
455 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
456 iterator first=x.begin(),last=x.end();
458 if(insert(position,*first).second)first=x.erase(first);
463 void splice(iterator position,sequenced_index<SuperMeta,TagList>& x,iterator i)
465 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
466 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
467 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(i);
468 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(i);
469 BOOST_MULTI_INDEX_CHECK_IS_OWNER(i,x);
470 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
472 if(position!=i)relink(position.get_node(),i.get_node());
475 if(insert(position,*i).second){
477 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
478 /* MSVC++ 6.0 optimizer has a hard time with safe mode, and the following
479 * workaround is needed. Left it for all compilers as it does no
483 x.erase(x.make_iterator(i.get_node()));
493 iterator position,sequenced_index<SuperMeta,TagList>& x,
494 iterator first,iterator last)
496 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
497 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
498 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
499 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
500 BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,x);
501 BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,x);
502 BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
503 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
505 BOOST_MULTI_INDEX_CHECK_OUTSIDE_RANGE(position,first,last);
506 if(position!=last)relink(
507 position.get_node(),first.get_node(),last.get_node());
511 if(insert(position,*first).second)first=x.erase(first);
517 void remove(value_param_type value)
519 sequenced_index_remove(
521 ::boost::bind(std::equal_to<value_type>(),::boost::arg<1>(),value));
524 template<typename Predicate>
525 void remove_if(Predicate pred)
527 sequenced_index_remove(*this,pred);
532 sequenced_index_unique(*this,std::equal_to<value_type>());
535 template <class BinaryPredicate>
536 void unique(BinaryPredicate binary_pred)
538 sequenced_index_unique(*this,binary_pred);
541 void merge(sequenced_index<SuperMeta,TagList>& x)
543 sequenced_index_merge(*this,x,std::less<value_type>());
546 template <typename Compare>
547 void merge(sequenced_index<SuperMeta,TagList>& x,Compare comp)
549 sequenced_index_merge(*this,x,comp);
554 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
555 sequenced_index_sort(header(),std::less<value_type>());
558 template <typename Compare>
559 void sort(Compare comp)
561 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
562 sequenced_index_sort(header(),comp);
565 void reverse()BOOST_NOEXCEPT
567 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
568 node_impl_type::reverse(header()->impl());
571 /* rearrange operations */
573 void relocate(iterator position,iterator i)
575 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
576 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
577 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(i);
578 BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(i);
579 BOOST_MULTI_INDEX_CHECK_IS_OWNER(i,*this);
580 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
581 if(position!=i)relink(position.get_node(),i.get_node());
584 void relocate(iterator position,iterator first,iterator last)
586 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
587 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
588 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
589 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
590 BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,*this);
591 BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,*this);
592 BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
593 BOOST_MULTI_INDEX_CHECK_OUTSIDE_RANGE(position,first,last);
594 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
595 if(position!=last)relink(
596 position.get_node(),first.get_node(),last.get_node());
599 template<typename InputIterator>
600 void rearrange(InputIterator first)
602 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
603 node_type* pos=header();
604 for(size_type s=size();s--;){
605 const value_type& v=*first++;
606 relink(pos,node_from_value<node_type>(&v));
610 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
611 sequenced_index(const ctor_args_list& args_list,const allocator_type& al):
612 super(args_list.get_tail(),al)
617 sequenced_index(const sequenced_index<SuperMeta,TagList>& x):
620 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
625 /* the actual copying takes place in subsequent call to copy_() */
629 const sequenced_index<SuperMeta,TagList>& x,do_not_copy_elements_tag):
630 super(x,do_not_copy_elements_tag())
632 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
642 /* the container is guaranteed to be empty by now */
645 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
646 iterator make_iterator(node_type* node){return iterator(node,this);}
647 const_iterator make_iterator(node_type* node)const
648 {return const_iterator(node,const_cast<sequenced_index*>(this));}
650 iterator make_iterator(node_type* node){return iterator(node);}
651 const_iterator make_iterator(node_type* node)const
652 {return const_iterator(node);}
656 const sequenced_index<SuperMeta,TagList>& x,const copy_map_type& map)
658 node_type* org=x.header();
659 node_type* cpy=header();
661 node_type* next_org=node_type::from_impl(org->next());
662 node_type* next_cpy=map.find(static_cast<final_node_type*>(next_org));
663 cpy->next()=next_cpy->impl();
664 next_cpy->prior()=cpy->impl();
667 }while(org!=x.header());
672 template<typename Variant>
673 final_node_type* insert_(
674 value_param_type v,final_node_type*& x,Variant variant)
676 final_node_type* res=super::insert_(v,x,variant);
677 if(res==x)link(static_cast<node_type*>(x));
681 template<typename Variant>
682 final_node_type* insert_(
683 value_param_type v,node_type* position,final_node_type*& x,Variant variant)
685 final_node_type* res=super::insert_(v,position,x,variant);
686 if(res==x)link(static_cast<node_type*>(x));
690 void erase_(node_type* x)
695 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
700 void delete_all_nodes_()
702 for(node_type* x=node_type::from_impl(header()->next());x!=header();){
703 node_type* y=node_type::from_impl(x->next());
704 this->final_delete_node_(static_cast<final_node_type*>(x));
714 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
715 safe_super::detach_dereferenceable_iterators();
719 void swap_(sequenced_index<SuperMeta,TagList>& x)
721 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
728 void swap_elements_(sequenced_index<SuperMeta,TagList>& x)
730 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
734 super::swap_elements_(x);
737 template<typename Variant>
738 bool replace_(value_param_type v,node_type* x,Variant variant)
740 return super::replace_(v,x,variant);
743 bool modify_(node_type* x)
746 if(!super::modify_(x)){
749 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
760 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
769 bool modify_rollback_(node_type* x)
771 return super::modify_rollback_(x);
774 bool check_rollback_(node_type* x)const
776 return super::check_rollback_(x);
779 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
782 template<typename Archive>
784 Archive& ar,const unsigned int version,const index_saver_type& sm)const
786 sm.save(begin(),end(),ar,version);
787 super::save_(ar,version,sm);
790 template<typename Archive>
792 Archive& ar,const unsigned int version,const index_loader_type& lm)
796 &sequenced_index::rearranger,this,::boost::arg<1>(),::boost::arg<2>()),
798 super::load_(ar,version,lm);
802 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
803 /* invariant stuff */
805 bool invariant_()const
807 if(size()==0||begin()==end()){
808 if(size()!=0||begin()!=end()||
809 header()->next()!=header()->impl()||
810 header()->prior()!=header()->impl())return false;
814 for(const_iterator it=begin(),it_end=end();it!=it_end;++it,++s){
815 if(it.get_node()->next()->prior()!=it.get_node()->impl())return false;
816 if(it.get_node()->prior()->next()!=it.get_node()->impl())return false;
818 if(s!=size())return false;
821 return super::invariant_();
824 /* This forwarding function eases things for the boost::mem_fn construct
825 * in BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT. Actually,
826 * final_check_invariant is already an inherited member function of index.
828 void check_invariant_()const{this->final_check_invariant_();}
832 node_type* header()const{return this->final_header();}
834 void empty_initialize()
836 header()->prior()=header()->next()=header()->impl();
839 void link(node_type* x)
841 node_impl_type::link(x->impl(),header()->impl());
844 static void unlink(node_type* x)
846 node_impl_type::unlink(x->impl());
849 static void relink(node_type* position,node_type* x)
851 node_impl_type::relink(position->impl(),x->impl());
854 static void relink(node_type* position,node_type* first,node_type* last)
856 node_impl_type::relink(
857 position->impl(),first->impl(),last->impl());
860 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
861 void rearranger(node_type* position,node_type *x)
863 if(!position)position=header();
864 node_type::increment(position);
865 if(position!=x)relink(position,x);
869 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
870 void detach_iterators(node_type* x)
872 iterator it=make_iterator(x);
873 safe_mode::detach_equivalent_iterators(it);
877 template <class InputIterator>
878 void assign_iter(InputIterator first,InputIterator last,mpl::true_)
880 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
882 for(;first!=last;++first)this->final_insert_ref_(*first);
885 void assign_iter(size_type n,value_param_type value,mpl::false_)
887 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
889 for(size_type i=0;i<n;++i)push_back(value);
892 template<typename InputIterator>
894 iterator position,InputIterator first,InputIterator last,mpl::true_)
896 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
897 for(;first!=last;++first){
898 std::pair<final_node_type*,bool> p=
899 this->final_insert_ref_(*first);
900 if(p.second&&position.get_node()!=header()){
901 relink(position.get_node(),p.first);
907 iterator position,size_type n,value_param_type x,mpl::false_)
909 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
910 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
911 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
912 for(size_type i=0;i<n;++i)insert(position,x);
915 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
916 std::pair<iterator,bool> emplace_front_impl(
917 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
919 return emplace_impl(begin(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
922 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
923 std::pair<iterator,bool> emplace_back_impl(
924 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
926 return emplace_impl(end(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
929 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
930 std::pair<iterator,bool> emplace_impl(
931 iterator position,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
933 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
934 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
935 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
936 std::pair<final_node_type*,bool> p=
937 this->final_emplace_(BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
938 if(p.second&&position.get_node()!=header()){
939 relink(position.get_node(),p.first);
941 return std::pair<iterator,bool>(make_iterator(p.first),p.second);
944 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
945 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
946 #pragma parse_mfunc_templ reset
953 typename SuperMeta1,typename TagList1,
954 typename SuperMeta2,typename TagList2
957 const sequenced_index<SuperMeta1,TagList1>& x,
958 const sequenced_index<SuperMeta2,TagList2>& y)
960 return x.size()==y.size()&&std::equal(x.begin(),x.end(),y.begin());
964 typename SuperMeta1,typename TagList1,
965 typename SuperMeta2,typename TagList2
968 const sequenced_index<SuperMeta1,TagList1>& x,
969 const sequenced_index<SuperMeta2,TagList2>& y)
971 return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
975 typename SuperMeta1,typename TagList1,
976 typename SuperMeta2,typename TagList2
979 const sequenced_index<SuperMeta1,TagList1>& x,
980 const sequenced_index<SuperMeta2,TagList2>& y)
986 typename SuperMeta1,typename TagList1,
987 typename SuperMeta2,typename TagList2
990 const sequenced_index<SuperMeta1,TagList1>& x,
991 const sequenced_index<SuperMeta2,TagList2>& y)
997 typename SuperMeta1,typename TagList1,
998 typename SuperMeta2,typename TagList2
1001 const sequenced_index<SuperMeta1,TagList1>& x,
1002 const sequenced_index<SuperMeta2,TagList2>& y)
1008 typename SuperMeta1,typename TagList1,
1009 typename SuperMeta2,typename TagList2
1012 const sequenced_index<SuperMeta1,TagList1>& x,
1013 const sequenced_index<SuperMeta2,TagList2>& y)
1018 /* specialized algorithms */
1020 template<typename SuperMeta,typename TagList>
1022 sequenced_index<SuperMeta,TagList>& x,
1023 sequenced_index<SuperMeta,TagList>& y)
1028 } /* namespace multi_index::detail */
1030 /* sequenced index specifier */
1032 template <typename TagList>
1035 BOOST_STATIC_ASSERT(detail::is_tag<TagList>::value);
1037 template<typename Super>
1040 typedef detail::sequenced_index_node<Super> type;
1043 template<typename SuperMeta>
1046 typedef detail::sequenced_index<SuperMeta,typename TagList::type> type;
1050 } /* namespace multi_index */
1052 } /* namespace boost */
1054 /* Boost.Foreach compatibility */
1056 template<typename SuperMeta,typename TagList>
1057 inline boost::mpl::true_* boost_foreach_is_noncopyable(
1058 boost::multi_index::detail::sequenced_index<SuperMeta,TagList>*&,
1059 boost_foreach_argument_dependent_lookup_hack)
1064 #undef BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT
1065 #undef BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF