]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/multi_index/sequenced_index.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / multi_index / sequenced_index.hpp
CommitLineData
f67539c2 1/* Copyright 2003-2020 Joaquin M Lopez Munoz.
7c673cae
FG
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
9#ifndef BOOST_MULTI_INDEX_SEQUENCED_INDEX_HPP
10#define BOOST_MULTI_INDEX_SEQUENCED_INDEX_HPP
11
12#if defined(_MSC_VER)
13#pragma once
14#endif
15
16#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
f67539c2 17#include <boost/bind/bind.hpp>
7c673cae 18#include <boost/call_traits.hpp>
11fdf7f2 19#include <boost/core/addressof.hpp>
7c673cae
FG
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>
92f5a8d4 25#include <boost/move/utility_core.hpp>
7c673cae
FG
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>
92f5a8d4 30#include <boost/multi_index/detail/allocator_traits.hpp>
7c673cae
FG
31#include <boost/multi_index/detail/bidir_node_iterator.hpp>
32#include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
33#include <boost/multi_index/detail/index_node_base.hpp>
34#include <boost/multi_index/detail/safe_mode.hpp>
35#include <boost/multi_index/detail/scope_guard.hpp>
36#include <boost/multi_index/detail/seq_index_node.hpp>
37#include <boost/multi_index/detail/seq_index_ops.hpp>
38#include <boost/multi_index/detail/vartempl_support.hpp>
39#include <boost/multi_index/sequenced_index_fwd.hpp>
40#include <boost/tuple/tuple.hpp>
41#include <boost/type_traits/is_integral.hpp>
7c673cae
FG
42#include <functional>
43#include <utility>
44
45#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
46#include<initializer_list>
47#endif
48
7c673cae
FG
49#if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
50#define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x) \
51 detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
52 detail::make_obj_guard(x,&sequenced_index::check_invariant_); \
53 BOOST_JOIN(check_invariant_,__LINE__).touch();
54#define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT \
55 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(*this)
56#else
57#define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x)
58#define BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT
59#endif
60
61namespace boost{
62
63namespace multi_index{
64
65namespace detail{
66
67/* sequenced_index adds a layer of sequenced indexing to a given Super */
68
69template<typename SuperMeta,typename TagList>
70class sequenced_index:
71 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS SuperMeta::type
72
73#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
74 ,public safe_mode::safe_container<
75 sequenced_index<SuperMeta,TagList> >
76#endif
77
78{
79#if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
80 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
81/* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
82 * lifetime of const references bound to temporaries --precisely what
83 * scopeguards are.
84 */
85
86#pragma parse_mfunc_templ off
87#endif
88
92f5a8d4 89 typedef typename SuperMeta::type super;
7c673cae
FG
90
91protected:
92 typedef sequenced_index_node<
92f5a8d4 93 typename super::node_type> node_type;
7c673cae
FG
94
95private:
92f5a8d4 96 typedef typename node_type::impl_type node_impl_type;
7c673cae
FG
97
98public:
99 /* types */
100
92f5a8d4
TL
101 typedef typename node_type::value_type value_type;
102 typedef tuples::null_type ctor_args;
103 typedef typename super::final_allocator_type allocator_type;
104 typedef value_type& reference;
105 typedef const value_type& const_reference;
7c673cae
FG
106
107#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
108 typedef safe_mode::safe_iterator<
109 bidir_node_iterator<node_type>,
92f5a8d4 110 sequenced_index> iterator;
7c673cae 111#else
92f5a8d4 112 typedef bidir_node_iterator<node_type> iterator;
7c673cae
FG
113#endif
114
92f5a8d4 115 typedef iterator const_iterator;
7c673cae 116
92f5a8d4
TL
117private:
118 typedef allocator_traits<allocator_type> alloc_traits;
119
120public:
121 typedef typename alloc_traits::pointer pointer;
122 typedef typename alloc_traits::const_pointer const_pointer;
123 typedef typename alloc_traits::size_type size_type;
124 typedef typename alloc_traits::difference_type difference_type;
7c673cae 125 typedef typename
92f5a8d4 126 boost::reverse_iterator<iterator> reverse_iterator;
7c673cae 127 typedef typename
92f5a8d4
TL
128 boost::reverse_iterator<const_iterator> const_reverse_iterator;
129 typedef TagList tag_list;
7c673cae
FG
130
131protected:
132 typedef typename super::final_node_type final_node_type;
133 typedef tuples::cons<
134 ctor_args,
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;
146
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;
150#endif
151
152private:
153#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
154 typedef safe_mode::safe_container<
155 sequenced_index> safe_super;
156#endif
157
158 typedef typename call_traits<value_type>::param_type value_param_type;
159
160 /* Needed to avoid commas in BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL
161 * expansion.
162 */
163
164 typedef std::pair<iterator,bool> emplace_return_type;
165
166public:
167
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.
171 */
172
173 sequenced_index<SuperMeta,TagList>& operator=(
174 const sequenced_index<SuperMeta,TagList>& x)
175 {
176 this->final()=x.final();
177 return *this;
178 }
179
180#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
181 sequenced_index<SuperMeta,TagList>& operator=(
182 std::initializer_list<value_type> list)
183 {
184 this->final()=list;
185 return *this;
186 }
187#endif
188
189 template <class InputIterator>
190 void assign(InputIterator first,InputIterator last)
191 {
192 assign_iter(first,last,mpl::not_<is_integral<InputIterator> >());
193 }
194
195#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
196 void assign(std::initializer_list<value_type> list)
197 {
198 assign(list.begin(),list.end());
199 }
200#endif
201
202 void assign(size_type n,value_param_type value)
203 {
204 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
205 clear();
206 for(size_type i=0;i<n;++i)push_back(value);
207 }
208
209 allocator_type get_allocator()const BOOST_NOEXCEPT
210 {
211 return this->final().get_allocator();
212 }
213
214 /* iterators */
215
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()));}
220 iterator
221 end()BOOST_NOEXCEPT{return make_iterator(header());}
222 const_iterator
223 end()const BOOST_NOEXCEPT{return make_iterator(header());}
224 reverse_iterator
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());}
228 reverse_iterator
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());}
232 const_iterator
233 cbegin()const BOOST_NOEXCEPT{return begin();}
234 const_iterator
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();}
240
241 iterator iterator_to(const value_type& x)
242 {
11fdf7f2 243 return make_iterator(node_from_value<node_type>(boost::addressof(x)));
7c673cae
FG
244 }
245
246 const_iterator iterator_to(const value_type& x)const
247 {
11fdf7f2 248 return make_iterator(node_from_value<node_type>(boost::addressof(x)));
7c673cae
FG
249 }
250
251 /* capacity */
252
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_();}
256
257 void resize(size_type n)
258 {
259 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
260 if(n>size()){
261 for(size_type m=n-size();m--;)
262 this->final_emplace_(BOOST_MULTI_INDEX_NULL_PARAM_PACK);
263 }
264 else if(n<size()){for(size_type m=size()-n;m--;)pop_back();}
265 }
266
267 void resize(size_type n,value_param_type x)
268 {
269 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
92f5a8d4 270 if(n>size())insert(end(),static_cast<size_type>(n-size()),x);
7c673cae
FG
271 else if(n<size())for(size_type m=size()-n;m--;)pop_back();
272 }
273
274 /* access: no non-const versions provided as sequenced_index
275 * handles const elements.
276 */
277
278 const_reference front()const{return *begin();}
279 const_reference back()const{return *--end();}
280
281 /* modifiers */
282
283 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
284 emplace_return_type,emplace_front,emplace_front_impl)
285
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());}
291
292 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
293 emplace_return_type,emplace_back,emplace_back_impl)
294
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());}
300
301 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
302 emplace_return_type,emplace,emplace_impl,iterator,position)
303
304 std::pair<iterator,bool> insert(iterator position,const value_type& x)
305 {
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);
312 }
313 return std::pair<iterator,bool>(make_iterator(p.first),p.second);
314 }
315
316 std::pair<iterator,bool> insert(iterator position,BOOST_RV_REF(value_type) x)
317 {
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);
324 }
325 return std::pair<iterator,bool>(make_iterator(p.first),p.second);
326 }
327
328 void insert(iterator position,size_type n,value_param_type x)
329 {
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);
334 }
335
336 template<typename InputIterator>
337 void insert(iterator position,InputIterator first,InputIterator last)
338 {
339 insert_iter(position,first,last,mpl::not_<is_integral<InputIterator> >());
340 }
341
342#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
343 void insert(iterator position,std::initializer_list<value_type> list)
344 {
345 insert(position,list.begin(),list.end());
346 }
347#endif
348
349 iterator erase(iterator position)
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 this->final_erase_(static_cast<final_node_type*>(position++.get_node()));
356 return position;
357 }
358
359 iterator erase(iterator first,iterator last)
360 {
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;
367 while(first!=last){
368 first=erase(first);
369 }
370 return first;
371 }
372
373 bool replace(iterator position,const value_type& x)
374 {
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()));
381 }
382
383 bool replace(iterator position,BOOST_RV_REF(value_type) x)
384 {
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()));
391 }
392
393 template<typename Modifier>
394 bool modify(iterator position,Modifier mod)
395 {
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;
400
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
404 * harm.
405 */
406
407 position.detach();
408#endif
409
410 return this->final_modify_(
411 mod,static_cast<final_node_type*>(position.get_node()));
412 }
413
414 template<typename Modifier,typename Rollback>
415 bool modify(iterator position,Modifier mod,Rollback back_)
416 {
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;
421
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
425 * harm.
426 */
427
428 position.detach();
429#endif
430
431 return this->final_modify_(
432 mod,back_,static_cast<final_node_type*>(position.get_node()));
433 }
434
435 void swap(sequenced_index<SuperMeta,TagList>& x)
436 {
437 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
438 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF(x);
439 this->final_swap_(x.final());
440 }
441
442 void clear()BOOST_NOEXCEPT
443 {
444 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
445 this->final_clear_();
446 }
447
448 /* list operations */
449
450 void splice(iterator position,sequenced_index<SuperMeta,TagList>& x)
451 {
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();
457 while(first!=last){
458 if(insert(position,*first).second)first=x.erase(first);
459 else ++first;
460 }
461 }
462
463 void splice(iterator position,sequenced_index<SuperMeta,TagList>& x,iterator i)
464 {
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;
471 if(&x==this){
472 if(position!=i)relink(position.get_node(),i.get_node());
473 }
474 else{
475 if(insert(position,*i).second){
476
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
480 * harm.
481 */
482 i.detach();
483 x.erase(x.make_iterator(i.get_node()));
484#else
485 x.erase(i);
486#endif
487
488 }
489 }
490 }
491
492 void splice(
493 iterator position,sequenced_index<SuperMeta,TagList>& x,
494 iterator first,iterator last)
495 {
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;
504 if(&x==this){
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());
508 }
509 else{
510 while(first!=last){
511 if(insert(position,*first).second)first=x.erase(first);
512 else ++first;
513 }
514 }
515 }
516
517 void remove(value_param_type value)
518 {
519 sequenced_index_remove(
520 *this,
521 ::boost::bind(std::equal_to<value_type>(),::boost::arg<1>(),value));
522 }
523
524 template<typename Predicate>
525 void remove_if(Predicate pred)
526 {
527 sequenced_index_remove(*this,pred);
528 }
529
530 void unique()
531 {
532 sequenced_index_unique(*this,std::equal_to<value_type>());
533 }
534
535 template <class BinaryPredicate>
536 void unique(BinaryPredicate binary_pred)
537 {
538 sequenced_index_unique(*this,binary_pred);
539 }
540
541 void merge(sequenced_index<SuperMeta,TagList>& x)
542 {
543 sequenced_index_merge(*this,x,std::less<value_type>());
544 }
545
546 template <typename Compare>
547 void merge(sequenced_index<SuperMeta,TagList>& x,Compare comp)
548 {
549 sequenced_index_merge(*this,x,comp);
550 }
551
552 void sort()
553 {
554 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
555 sequenced_index_sort(header(),std::less<value_type>());
556 }
557
558 template <typename Compare>
559 void sort(Compare comp)
560 {
561 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
562 sequenced_index_sort(header(),comp);
563 }
564
565 void reverse()BOOST_NOEXCEPT
566 {
567 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
568 node_impl_type::reverse(header()->impl());
569 }
570
571 /* rearrange operations */
572
573 void relocate(iterator position,iterator i)
574 {
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());
582 }
583
584 void relocate(iterator position,iterator first,iterator last)
585 {
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());
597 }
598
599 template<typename InputIterator>
600 void rearrange(InputIterator first)
601 {
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));
607 }
608 }
609
610BOOST_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)
613 {
614 empty_initialize();
615 }
616
617 sequenced_index(const sequenced_index<SuperMeta,TagList>& x):
618 super(x)
619
620#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
621 ,safe_super()
622#endif
623
624 {
625 /* the actual copying takes place in subsequent call to copy_() */
626 }
627
628 sequenced_index(
629 const sequenced_index<SuperMeta,TagList>& x,do_not_copy_elements_tag):
630 super(x,do_not_copy_elements_tag())
631
632#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
633 ,safe_super()
634#endif
635
636 {
637 empty_initialize();
638 }
639
640 ~sequenced_index()
641 {
642 /* the container is guaranteed to be empty by now */
643 }
644
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));}
649#else
650 iterator make_iterator(node_type* node){return iterator(node);}
651 const_iterator make_iterator(node_type* node)const
652 {return const_iterator(node);}
653#endif
654
655 void copy_(
656 const sequenced_index<SuperMeta,TagList>& x,const copy_map_type& map)
657 {
658 node_type* org=x.header();
659 node_type* cpy=header();
660 do{
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();
665 org=next_org;
666 cpy=next_cpy;
667 }while(org!=x.header());
668
669 super::copy_(x,map);
670 }
671
672 template<typename Variant>
673 final_node_type* insert_(
674 value_param_type v,final_node_type*& x,Variant variant)
675 {
676 final_node_type* res=super::insert_(v,x,variant);
677 if(res==x)link(static_cast<node_type*>(x));
678 return res;
679 }
680
681 template<typename Variant>
682 final_node_type* insert_(
683 value_param_type v,node_type* position,final_node_type*& x,Variant variant)
684 {
685 final_node_type* res=super::insert_(v,position,x,variant);
686 if(res==x)link(static_cast<node_type*>(x));
687 return res;
688 }
689
690 void erase_(node_type* x)
691 {
692 unlink(x);
693 super::erase_(x);
694
695#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
696 detach_iterators(x);
697#endif
698 }
699
700 void delete_all_nodes_()
701 {
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));
705 x=y;
706 }
707 }
708
709 void clear_()
710 {
711 super::clear_();
712 empty_initialize();
713
714#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
715 safe_super::detach_dereferenceable_iterators();
716#endif
717 }
718
f67539c2
TL
719 template<typename BoolConstant>
720 void swap_(
721 sequenced_index<SuperMeta,TagList>& x,BoolConstant swap_allocators)
7c673cae
FG
722 {
723#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
724 safe_super::swap(x);
725#endif
726
f67539c2 727 super::swap_(x,swap_allocators);
7c673cae
FG
728 }
729
730 void swap_elements_(sequenced_index<SuperMeta,TagList>& x)
731 {
732#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
733 safe_super::swap(x);
734#endif
735
736 super::swap_elements_(x);
737 }
738
739 template<typename Variant>
740 bool replace_(value_param_type v,node_type* x,Variant variant)
741 {
742 return super::replace_(v,x,variant);
743 }
744
745 bool modify_(node_type* x)
746 {
747 BOOST_TRY{
748 if(!super::modify_(x)){
749 unlink(x);
750
751#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
752 detach_iterators(x);
753#endif
754
755 return false;
756 }
757 else return true;
758 }
759 BOOST_CATCH(...){
760 unlink(x);
761
762#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
763 detach_iterators(x);
764#endif
765
766 BOOST_RETHROW;
767 }
768 BOOST_CATCH_END
769 }
770
771 bool modify_rollback_(node_type* x)
772 {
773 return super::modify_rollback_(x);
774 }
775
b32b8144
FG
776 bool check_rollback_(node_type* x)const
777 {
778 return super::check_rollback_(x);
779 }
780
7c673cae
FG
781#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
782 /* serialization */
783
784 template<typename Archive>
785 void save_(
786 Archive& ar,const unsigned int version,const index_saver_type& sm)const
787 {
788 sm.save(begin(),end(),ar,version);
789 super::save_(ar,version,sm);
790 }
791
792 template<typename Archive>
793 void load_(
794 Archive& ar,const unsigned int version,const index_loader_type& lm)
795 {
796 lm.load(
797 ::boost::bind(
798 &sequenced_index::rearranger,this,::boost::arg<1>(),::boost::arg<2>()),
799 ar,version);
800 super::load_(ar,version,lm);
801 }
802#endif
803
804#if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
805 /* invariant stuff */
806
807 bool invariant_()const
808 {
809 if(size()==0||begin()==end()){
810 if(size()!=0||begin()!=end()||
811 header()->next()!=header()->impl()||
812 header()->prior()!=header()->impl())return false;
813 }
814 else{
815 size_type s=0;
816 for(const_iterator it=begin(),it_end=end();it!=it_end;++it,++s){
817 if(it.get_node()->next()->prior()!=it.get_node()->impl())return false;
818 if(it.get_node()->prior()->next()!=it.get_node()->impl())return false;
819 }
820 if(s!=size())return false;
821 }
822
823 return super::invariant_();
824 }
825
826 /* This forwarding function eases things for the boost::mem_fn construct
827 * in BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT. Actually,
828 * final_check_invariant is already an inherited member function of index.
829 */
830 void check_invariant_()const{this->final_check_invariant_();}
831#endif
832
833private:
834 node_type* header()const{return this->final_header();}
835
836 void empty_initialize()
837 {
838 header()->prior()=header()->next()=header()->impl();
839 }
840
841 void link(node_type* x)
842 {
843 node_impl_type::link(x->impl(),header()->impl());
92f5a8d4 844 }
7c673cae
FG
845
846 static void unlink(node_type* x)
847 {
848 node_impl_type::unlink(x->impl());
849 }
850
851 static void relink(node_type* position,node_type* x)
852 {
853 node_impl_type::relink(position->impl(),x->impl());
854 }
855
856 static void relink(node_type* position,node_type* first,node_type* last)
857 {
858 node_impl_type::relink(
859 position->impl(),first->impl(),last->impl());
860 }
861
862#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
863 void rearranger(node_type* position,node_type *x)
864 {
865 if(!position)position=header();
866 node_type::increment(position);
867 if(position!=x)relink(position,x);
868 }
869#endif
870
871#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
872 void detach_iterators(node_type* x)
873 {
874 iterator it=make_iterator(x);
875 safe_mode::detach_equivalent_iterators(it);
876 }
877#endif
878
879 template <class InputIterator>
880 void assign_iter(InputIterator first,InputIterator last,mpl::true_)
881 {
882 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
883 clear();
884 for(;first!=last;++first)this->final_insert_ref_(*first);
885 }
886
887 void assign_iter(size_type n,value_param_type value,mpl::false_)
888 {
889 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
890 clear();
891 for(size_type i=0;i<n;++i)push_back(value);
892 }
893
894 template<typename InputIterator>
895 void insert_iter(
896 iterator position,InputIterator first,InputIterator last,mpl::true_)
897 {
898 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
899 for(;first!=last;++first){
900 std::pair<final_node_type*,bool> p=
901 this->final_insert_ref_(*first);
902 if(p.second&&position.get_node()!=header()){
903 relink(position.get_node(),p.first);
904 }
905 }
906 }
907
908 void insert_iter(
909 iterator position,size_type n,value_param_type x,mpl::false_)
910 {
911 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
912 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
913 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
914 for(size_type i=0;i<n;++i)insert(position,x);
915 }
916
917 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
918 std::pair<iterator,bool> emplace_front_impl(
919 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
920 {
921 return emplace_impl(begin(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
922 }
923
924 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
925 std::pair<iterator,bool> emplace_back_impl(
926 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
927 {
928 return emplace_impl(end(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
929 }
930
931 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
932 std::pair<iterator,bool> emplace_impl(
933 iterator position,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
934 {
935 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
936 BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
937 BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT;
938 std::pair<final_node_type*,bool> p=
939 this->final_emplace_(BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
940 if(p.second&&position.get_node()!=header()){
941 relink(position.get_node(),p.first);
942 }
943 return std::pair<iterator,bool>(make_iterator(p.first),p.second);
944 }
945
946#if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
947 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
948#pragma parse_mfunc_templ reset
949#endif
950};
951
952/* comparison */
953
954template<
955 typename SuperMeta1,typename TagList1,
956 typename SuperMeta2,typename TagList2
957>
958bool operator==(
959 const sequenced_index<SuperMeta1,TagList1>& x,
960 const sequenced_index<SuperMeta2,TagList2>& y)
961{
962 return x.size()==y.size()&&std::equal(x.begin(),x.end(),y.begin());
963}
964
965template<
966 typename SuperMeta1,typename TagList1,
967 typename SuperMeta2,typename TagList2
968>
969bool operator<(
970 const sequenced_index<SuperMeta1,TagList1>& x,
971 const sequenced_index<SuperMeta2,TagList2>& y)
972{
973 return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
974}
975
976template<
977 typename SuperMeta1,typename TagList1,
978 typename SuperMeta2,typename TagList2
979>
980bool operator!=(
981 const sequenced_index<SuperMeta1,TagList1>& x,
982 const sequenced_index<SuperMeta2,TagList2>& y)
983{
984 return !(x==y);
985}
986
987template<
988 typename SuperMeta1,typename TagList1,
989 typename SuperMeta2,typename TagList2
990>
991bool operator>(
992 const sequenced_index<SuperMeta1,TagList1>& x,
993 const sequenced_index<SuperMeta2,TagList2>& y)
994{
995 return y<x;
996}
997
998template<
999 typename SuperMeta1,typename TagList1,
1000 typename SuperMeta2,typename TagList2
1001>
1002bool operator>=(
1003 const sequenced_index<SuperMeta1,TagList1>& x,
1004 const sequenced_index<SuperMeta2,TagList2>& y)
1005{
1006 return !(x<y);
1007}
1008
1009template<
1010 typename SuperMeta1,typename TagList1,
1011 typename SuperMeta2,typename TagList2
1012>
1013bool operator<=(
1014 const sequenced_index<SuperMeta1,TagList1>& x,
1015 const sequenced_index<SuperMeta2,TagList2>& y)
1016{
1017 return !(x>y);
1018}
1019
1020/* specialized algorithms */
1021
1022template<typename SuperMeta,typename TagList>
1023void swap(
1024 sequenced_index<SuperMeta,TagList>& x,
1025 sequenced_index<SuperMeta,TagList>& y)
1026{
1027 x.swap(y);
1028}
1029
1030} /* namespace multi_index::detail */
1031
1032/* sequenced index specifier */
1033
1034template <typename TagList>
1035struct sequenced
1036{
1037 BOOST_STATIC_ASSERT(detail::is_tag<TagList>::value);
1038
1039 template<typename Super>
1040 struct node_class
1041 {
1042 typedef detail::sequenced_index_node<Super> type;
1043 };
1044
1045 template<typename SuperMeta>
1046 struct index_class
1047 {
1048 typedef detail::sequenced_index<SuperMeta,typename TagList::type> type;
1049 };
1050};
1051
1052} /* namespace multi_index */
1053
1054} /* namespace boost */
1055
1056/* Boost.Foreach compatibility */
1057
1058template<typename SuperMeta,typename TagList>
1059inline boost::mpl::true_* boost_foreach_is_noncopyable(
1060 boost::multi_index::detail::sequenced_index<SuperMeta,TagList>*&,
1061 boost_foreach_argument_dependent_lookup_hack)
1062{
1063 return 0;
1064}
1065
1066#undef BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT
1067#undef BOOST_MULTI_INDEX_SEQ_INDEX_CHECK_INVARIANT_OF
1068
1069#endif