1 /* Multiply indexed container.
3 * Copyright 2003-2017 Joaquin M Lopez Munoz.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org/libs/multi_index for library home page.
11 #ifndef BOOST_MULTI_INDEX_HPP
12 #define BOOST_MULTI_INDEX_HPP
18 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
20 #include <boost/detail/allocator_utilities.hpp>
21 #include <boost/detail/no_exceptions_support.hpp>
22 #include <boost/detail/workaround.hpp>
23 #include <boost/move/core.hpp>
24 #include <boost/mpl/at.hpp>
25 #include <boost/mpl/contains.hpp>
26 #include <boost/mpl/find_if.hpp>
27 #include <boost/mpl/identity.hpp>
28 #include <boost/mpl/int.hpp>
29 #include <boost/mpl/size.hpp>
30 #include <boost/mpl/deref.hpp>
31 #include <boost/multi_index_container_fwd.hpp>
32 #include <boost/multi_index/detail/access_specifier.hpp>
33 #include <boost/multi_index/detail/adl_swap.hpp>
34 #include <boost/multi_index/detail/base_type.hpp>
35 #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp>
36 #include <boost/multi_index/detail/converter.hpp>
37 #include <boost/multi_index/detail/header_holder.hpp>
38 #include <boost/multi_index/detail/has_tag.hpp>
39 #include <boost/multi_index/detail/no_duplicate_tags.hpp>
40 #include <boost/multi_index/detail/safe_mode.hpp>
41 #include <boost/multi_index/detail/scope_guard.hpp>
42 #include <boost/multi_index/detail/vartempl_support.hpp>
43 #include <boost/static_assert.hpp>
44 #include <boost/type_traits/is_same.hpp>
45 #include <boost/utility/base_from_member.hpp>
47 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
48 #include <initializer_list>
51 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
52 #include <boost/multi_index/detail/archive_constructed.hpp>
53 #include <boost/multi_index/detail/serialization_version.hpp>
54 #include <boost/serialization/collection_size_type.hpp>
55 #include <boost/serialization/nvp.hpp>
56 #include <boost/serialization/split_member.hpp>
57 #include <boost/serialization/version.hpp>
58 #include <boost/throw_exception.hpp>
61 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
62 #include <boost/multi_index/detail/invariant_assert.hpp>
63 #define BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x) \
64 detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
65 detail::make_obj_guard(x,&multi_index_container::check_invariant_); \
66 BOOST_JOIN(check_invariant_,__LINE__).touch();
67 #define BOOST_MULTI_INDEX_CHECK_INVARIANT \
68 BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(*this)
70 #define BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x)
71 #define BOOST_MULTI_INDEX_CHECK_INVARIANT
76 namespace multi_index{
78 #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
80 #pragma warning(disable:4522) /* spurious warning on multiple operator=()'s */
83 template<typename Value,typename IndexSpecifierList,typename Allocator>
84 class multi_index_container:
85 private ::boost::base_from_member<
86 typename boost::detail::allocator::rebind_to<
88 typename detail::multi_index_node_type<
89 Value,IndexSpecifierList,Allocator>::type
91 BOOST_MULTI_INDEX_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS detail::header_holder<
92 typename boost::detail::allocator::rebind_to<
94 typename detail::multi_index_node_type<
95 Value,IndexSpecifierList,Allocator>::type
97 multi_index_container<Value,IndexSpecifierList,Allocator> >,
98 public detail::multi_index_base_type<
99 Value,IndexSpecifierList,Allocator>::type
101 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
102 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
103 /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
104 * lifetime of const references bound to temporaries --precisely what
108 #pragma parse_mfunc_templ off
112 BOOST_COPYABLE_AND_MOVABLE(multi_index_container)
114 #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
115 template <typename,typename,typename> friend class detail::index_base;
116 template <typename,typename> friend struct detail::header_holder;
117 template <typename,typename> friend struct detail::converter;
120 typedef typename detail::multi_index_base_type<
121 Value,IndexSpecifierList,Allocator>::type super;
123 boost::detail::allocator::rebind_to<
125 typename super::node_type
126 >::type node_allocator;
127 typedef ::boost::base_from_member<
128 node_allocator> bfm_allocator;
129 typedef detail::header_holder<
130 typename node_allocator::pointer,
131 multi_index_container> bfm_header;
135 /* All types are inherited from super, a few are explicitly
136 * brought forward here to save us some typename's.
139 typedef typename super::ctor_args_list ctor_args_list;
140 typedef IndexSpecifierList index_specifier_type_list;
142 typedef typename super::index_type_list index_type_list;
144 typedef typename super::iterator_type_list iterator_type_list;
145 typedef typename super::const_iterator_type_list const_iterator_type_list;
146 typedef typename super::value_type value_type;
147 typedef typename super::final_allocator_type allocator_type;
148 typedef typename super::iterator iterator;
149 typedef typename super::const_iterator const_iterator;
152 detail::no_duplicate_tags_in_index_list<index_type_list>::value);
154 /* global project() needs to see this publicly */
156 typedef typename super::node_type node_type;
158 /* construct/copy/destroy */
160 explicit multi_index_container(
162 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
163 /* VisualAge seems to have an ETI issue with the default values
164 * for arguments args_list and al.
167 const ctor_args_list& args_list=
168 typename mpl::identity<multi_index_container>::type::
170 const allocator_type& al=
171 typename mpl::identity<multi_index_container>::type::
174 const ctor_args_list& args_list=ctor_args_list(),
175 const allocator_type& al=allocator_type()):
179 super(args_list,bfm_allocator::member),
182 BOOST_MULTI_INDEX_CHECK_INVARIANT;
185 explicit multi_index_container(const allocator_type& al):
187 super(ctor_args_list(),bfm_allocator::member),
190 BOOST_MULTI_INDEX_CHECK_INVARIANT;
193 template<typename InputIterator>
194 multi_index_container(
195 InputIterator first,InputIterator last,
197 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
198 /* VisualAge seems to have an ETI issue with the default values
199 * for arguments args_list and al.
202 const ctor_args_list& args_list=
203 typename mpl::identity<multi_index_container>::type::
205 const allocator_type& al=
206 typename mpl::identity<multi_index_container>::type::
209 const ctor_args_list& args_list=ctor_args_list(),
210 const allocator_type& al=allocator_type()):
214 super(args_list,bfm_allocator::member),
217 BOOST_MULTI_INDEX_CHECK_INVARIANT;
219 iterator hint=super::end();
220 for(;first!=last;++first){
221 hint=super::make_iterator(
222 insert_ref_(*first,hint.get_node()).first);
233 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
234 multi_index_container(
235 std::initializer_list<Value> list,
236 const ctor_args_list& args_list=ctor_args_list(),
237 const allocator_type& al=allocator_type()):
239 super(args_list,bfm_allocator::member),
242 BOOST_MULTI_INDEX_CHECK_INVARIANT;
244 typedef const Value* init_iterator;
246 iterator hint=super::end();
247 for(init_iterator first=list.begin(),last=list.end();
248 first!=last;++first){
249 hint=super::make_iterator(insert_(*first,hint.get_node()).first);
261 multi_index_container(
262 const multi_index_container<Value,IndexSpecifierList,Allocator>& x):
263 bfm_allocator(x.bfm_allocator::member),
268 copy_map_type map(bfm_allocator::member,x.size(),x.header(),header());
269 for(const_iterator it=x.begin(),it_end=x.end();it!=it_end;++it){
270 map.clone(it.get_node());
276 /* Not until this point are the indices required to be consistent,
277 * hence the position of the invariant checker.
280 BOOST_MULTI_INDEX_CHECK_INVARIANT;
283 multi_index_container(BOOST_RV_REF(multi_index_container) x):
284 bfm_allocator(x.bfm_allocator::member),
286 super(x,detail::do_not_copy_elements_tag()),
289 BOOST_MULTI_INDEX_CHECK_INVARIANT;
290 BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x);
294 ~multi_index_container()
299 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
300 /* As per http://www.boost.org/doc/html/move/emulation_limitations.html
301 * #move.emulation_limitations.assignment_operator
304 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
305 const multi_index_container<Value,IndexSpecifierList,Allocator>& x)
307 multi_index_container y(x);
313 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
314 BOOST_COPY_ASSIGN_REF(multi_index_container) x)
316 multi_index_container y(x);
321 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
322 BOOST_RV_REF(multi_index_container) x)
328 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
329 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
330 std::initializer_list<Value> list)
332 BOOST_MULTI_INDEX_CHECK_INVARIANT;
333 typedef const Value* init_iterator;
335 multi_index_container x(*this,detail::do_not_copy_elements_tag());
336 iterator hint=x.end();
337 for(init_iterator first=list.begin(),last=list.end();
338 first!=last;++first){
339 hint=x.make_iterator(x.insert_(*first,hint.get_node()).first);
342 x.swap_elements_(*this);
347 allocator_type get_allocator()const BOOST_NOEXCEPT
349 return allocator_type(bfm_allocator::member);
352 /* retrieval of indices by number */
354 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
358 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
359 typedef typename mpl::at_c<index_type_list,N>::type type;
363 typename nth_index<N>::type& get()BOOST_NOEXCEPT
365 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
370 const typename nth_index<N>::type& get()const BOOST_NOEXCEPT
372 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
377 /* retrieval of indices by tag */
379 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
380 template<typename Tag>
383 typedef typename mpl::find_if<
388 BOOST_STATIC_CONSTANT(
389 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
390 BOOST_STATIC_ASSERT(index_found);
392 typedef typename mpl::deref<iter>::type type;
395 template<typename Tag>
396 typename index<Tag>::type& get()BOOST_NOEXCEPT
401 template<typename Tag>
402 const typename index<Tag>::type& get()const BOOST_NOEXCEPT
408 /* projection of iterators by number */
410 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
412 struct nth_index_iterator
414 typedef typename nth_index<N>::type::iterator type;
418 struct nth_index_const_iterator
420 typedef typename nth_index<N>::type::const_iterator type;
423 template<int N,typename IteratorType>
424 typename nth_index_iterator<N>::type project(IteratorType it)
426 typedef typename nth_index<N>::type index_type;
428 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
430 (mpl::contains<iterator_type_list,IteratorType>::value));
433 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
434 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
435 it,static_cast<typename IteratorType::container_type&>(*this));
437 return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
440 template<int N,typename IteratorType>
441 typename nth_index_const_iterator<N>::type project(IteratorType it)const
443 typedef typename nth_index<N>::type index_type;
445 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
446 BOOST_STATIC_ASSERT((
447 mpl::contains<iterator_type_list,IteratorType>::value||
448 mpl::contains<const_iterator_type_list,IteratorType>::value));
451 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
452 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
453 it,static_cast<const typename IteratorType::container_type&>(*this));
454 return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
458 /* projection of iterators by tag */
460 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
461 template<typename Tag>
462 struct index_iterator
464 typedef typename index<Tag>::type::iterator type;
467 template<typename Tag>
468 struct index_const_iterator
470 typedef typename index<Tag>::type::const_iterator type;
473 template<typename Tag,typename IteratorType>
474 typename index_iterator<Tag>::type project(IteratorType it)
476 typedef typename index<Tag>::type index_type;
478 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
480 (mpl::contains<iterator_type_list,IteratorType>::value));
483 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
484 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
485 it,static_cast<typename IteratorType::container_type&>(*this));
486 return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
489 template<typename Tag,typename IteratorType>
490 typename index_const_iterator<Tag>::type project(IteratorType it)const
492 typedef typename index<Tag>::type index_type;
494 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
495 BOOST_STATIC_ASSERT((
496 mpl::contains<iterator_type_list,IteratorType>::value||
497 mpl::contains<const_iterator_type_list,IteratorType>::value));
500 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
501 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
502 it,static_cast<const typename IteratorType::container_type&>(*this));
503 return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
507 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
508 typedef typename super::copy_map_type copy_map_type;
510 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
511 multi_index_container(
512 const multi_index_container<Value,IndexSpecifierList,Allocator>& x,
513 detail::do_not_copy_elements_tag):
514 bfm_allocator(x.bfm_allocator::member),
516 super(x,detail::do_not_copy_elements_tag()),
519 BOOST_MULTI_INDEX_CHECK_INVARIANT;
523 node_type* header()const
525 return &*bfm_header::member;
528 node_type* allocate_node()
530 return &*bfm_allocator::member.allocate(1);
533 void deallocate_node(node_type* x)
535 typedef typename node_allocator::pointer node_pointer;
536 bfm_allocator::member.deallocate(static_cast<node_pointer>(x),1);
541 return node_count==0;
544 std::size_t size_()const
549 std::size_t max_size_()const
551 return static_cast<std::size_t >(-1);
554 template<typename Variant>
555 std::pair<node_type*,bool> insert_(const Value& v,Variant variant)
558 node_type* res=super::insert_(v,x,variant);
561 return std::pair<node_type*,bool>(res,true);
564 return std::pair<node_type*,bool>(res,false);
568 std::pair<node_type*,bool> insert_(const Value& v)
570 return insert_(v,detail::lvalue_tag());
573 std::pair<node_type*,bool> insert_rv_(const Value& v)
575 return insert_(v,detail::rvalue_tag());
579 std::pair<node_type*,bool> insert_ref_(T& t)
581 node_type* x=allocate_node();
583 new(&x->value()) value_type(t);
585 node_type* res=super::insert_(x->value(),x,detail::emplaced_tag());
588 return std::pair<node_type*,bool>(res,true);
591 boost::detail::allocator::destroy(&x->value());
593 return std::pair<node_type*,bool>(res,false);
597 boost::detail::allocator::destroy(&x->value());
609 std::pair<node_type*,bool> insert_ref_(const value_type& x)
614 std::pair<node_type*,bool> insert_ref_(value_type& x)
619 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
620 std::pair<node_type*,bool> emplace_(
621 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
623 node_type* x=allocate_node();
625 detail::vartempl_placement_new(
626 &x->value(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
628 node_type* res=super::insert_(x->value(),x,detail::emplaced_tag());
631 return std::pair<node_type*,bool>(res,true);
634 boost::detail::allocator::destroy(&x->value());
636 return std::pair<node_type*,bool>(res,false);
640 boost::detail::allocator::destroy(&x->value());
652 template<typename Variant>
653 std::pair<node_type*,bool> insert_(
654 const Value& v,node_type* position,Variant variant)
657 node_type* res=super::insert_(v,position,x,variant);
660 return std::pair<node_type*,bool>(res,true);
663 return std::pair<node_type*,bool>(res,false);
667 std::pair<node_type*,bool> insert_(const Value& v,node_type* position)
669 return insert_(v,position,detail::lvalue_tag());
672 std::pair<node_type*,bool> insert_rv_(const Value& v,node_type* position)
674 return insert_(v,position,detail::rvalue_tag());
678 std::pair<node_type*,bool> insert_ref_(
679 T& t,node_type* position)
681 node_type* x=allocate_node();
683 new(&x->value()) value_type(t);
685 node_type* res=super::insert_(
686 x->value(),position,x,detail::emplaced_tag());
689 return std::pair<node_type*,bool>(res,true);
692 boost::detail::allocator::destroy(&x->value());
694 return std::pair<node_type*,bool>(res,false);
698 boost::detail::allocator::destroy(&x->value());
710 std::pair<node_type*,bool> insert_ref_(
711 const value_type& x,node_type* position)
713 return insert_(x,position);
716 std::pair<node_type*,bool> insert_ref_(
717 value_type& x,node_type* position)
719 return insert_(x,position);
722 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
723 std::pair<node_type*,bool> emplace_hint_(
725 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
727 node_type* x=allocate_node();
729 detail::vartempl_placement_new(
730 &x->value(),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
732 node_type* res=super::insert_(
733 x->value(),position,x,detail::emplaced_tag());
736 return std::pair<node_type*,bool>(res,true);
739 boost::detail::allocator::destroy(&x->value());
741 return std::pair<node_type*,bool>(res,false);
745 boost::detail::allocator::destroy(&x->value());
757 void erase_(node_type* x)
764 void delete_node_(node_type* x)
766 super::delete_node_(x);
770 void delete_all_nodes_()
772 super::delete_all_nodes_();
782 void swap_(multi_index_container<Value,IndexSpecifierList,Allocator>& x)
784 if(bfm_allocator::member!=x.bfm_allocator::member){
785 detail::adl_swap(bfm_allocator::member,x.bfm_allocator::member);
787 std::swap(bfm_header::member,x.bfm_header::member);
789 std::swap(node_count,x.node_count);
793 multi_index_container<Value,IndexSpecifierList,Allocator>& x)
795 std::swap(bfm_header::member,x.bfm_header::member);
796 super::swap_elements_(x);
797 std::swap(node_count,x.node_count);
800 bool replace_(const Value& k,node_type* x)
802 return super::replace_(k,x,detail::lvalue_tag());
805 bool replace_rv_(const Value& k,node_type* x)
807 return super::replace_(k,x,detail::rvalue_tag());
810 template<typename Modifier>
811 bool modify_(Modifier& mod,node_type* x)
814 mod(const_cast<value_type&>(x->value()));
823 if(!super::modify_(x)){
838 template<typename Modifier,typename Rollback>
839 bool modify_(Modifier& mod,Rollback& back_,node_type* x)
842 mod(const_cast<value_type&>(x->value()));
852 b=super::modify_rollback_(x);
856 back_(const_cast<value_type&>(x->value()));
857 if(!super::check_rollback_(x))this->erase_(x);
870 back_(const_cast<value_type&>(x->value()));
871 if(!super::check_rollback_(x))this->erase_(x);
883 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
886 friend class boost::serialization::access;
888 BOOST_SERIALIZATION_SPLIT_MEMBER()
890 typedef typename super::index_saver_type index_saver_type;
891 typedef typename super::index_loader_type index_loader_type;
893 template<class Archive>
894 void save(Archive& ar,const unsigned int version)const
896 const serialization::collection_size_type s(size_());
897 const detail::serialization_version<value_type> value_version;
898 ar<<serialization::make_nvp("count",s);
899 ar<<serialization::make_nvp("value_version",value_version);
901 index_saver_type sm(bfm_allocator::member,s);
903 for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){
904 serialization::save_construct_data_adl(ar,&*it,value_version);
905 ar<<serialization::make_nvp("item",*it);
906 sm.add(it.get_node(),ar,version);
908 sm.add_track(header(),ar,version);
910 super::save_(ar,version,sm);
913 template<class Archive>
914 void load(Archive& ar,const unsigned int version)
916 BOOST_MULTI_INDEX_CHECK_INVARIANT;
919 serialization::collection_size_type s;
920 detail::serialization_version<value_type> value_version;
923 ar>>serialization::make_nvp("count",sz);
924 s=static_cast<serialization::collection_size_type>(sz);
927 ar>>serialization::make_nvp("count",s);
933 ar>>serialization::make_nvp("value_version",value_version);
936 index_loader_type lm(bfm_allocator::member,s);
938 for(std::size_t n=0;n<s;++n){
939 detail::archive_constructed<Value> value("item",ar,value_version);
940 std::pair<node_type*,bool> p=insert_(
941 value.get(),super::end().get_node());
942 if(!p.second)throw_exception(
943 archive::archive_exception(
944 archive::archive_exception::other_exception));
945 ar.reset_object_address(&p.first->value(),&value.get());
946 lm.add(p.first,ar,version);
948 lm.add_track(header(),ar,version);
950 super::load_(ar,version,lm);
954 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
955 /* invariant stuff */
957 bool invariant_()const
959 return super::invariant_();
962 void check_invariant_()const
964 BOOST_MULTI_INDEX_INVARIANT_ASSERT(invariant_());
969 std::size_t node_count;
971 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
972 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
973 #pragma parse_mfunc_templ reset
977 #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
978 #pragma warning(pop) /* C4522 */
981 /* retrieval of indices by number */
983 template<typename MultiIndexContainer,int N>
986 BOOST_STATIC_CONSTANT(
988 M=mpl::size<typename MultiIndexContainer::index_type_list>::type::value);
989 BOOST_STATIC_ASSERT(N>=0&&N<M);
990 typedef typename mpl::at_c<
991 typename MultiIndexContainer::index_type_list,N>::type type;
994 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
996 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
998 multi_index_container<Value,IndexSpecifierList,Allocator>& m)BOOST_NOEXCEPT
1000 typedef multi_index_container<
1001 Value,IndexSpecifierList,Allocator> multi_index_type;
1002 typedef typename nth_index<
1003 multi_index_container<
1004 Value,IndexSpecifierList,Allocator>,
1008 BOOST_STATIC_ASSERT(N>=0&&
1011 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
1014 return detail::converter<multi_index_type,index_type>::index(m);
1017 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
1018 const typename nth_index<
1019 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
1021 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
1024 typedef multi_index_container<
1025 Value,IndexSpecifierList,Allocator> multi_index_type;
1026 typedef typename nth_index<
1027 multi_index_container<
1028 Value,IndexSpecifierList,Allocator>,
1032 BOOST_STATIC_ASSERT(N>=0&&
1035 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
1038 return detail::converter<multi_index_type,index_type>::index(m);
1041 /* retrieval of indices by tag */
1043 template<typename MultiIndexContainer,typename Tag>
1046 typedef typename MultiIndexContainer::index_type_list index_type_list;
1048 typedef typename mpl::find_if<
1050 detail::has_tag<Tag>
1053 BOOST_STATIC_CONSTANT(
1054 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
1055 BOOST_STATIC_ASSERT(index_found);
1057 typedef typename mpl::deref<iter>::type type;
1061 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
1063 typename ::boost::multi_index::index<
1064 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
1066 multi_index_container<Value,IndexSpecifierList,Allocator>& m)BOOST_NOEXCEPT
1068 typedef multi_index_container<
1069 Value,IndexSpecifierList,Allocator> multi_index_type;
1070 typedef typename ::boost::multi_index::index<
1071 multi_index_container<
1072 Value,IndexSpecifierList,Allocator>,
1076 return detail::converter<multi_index_type,index_type>::index(m);
1080 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
1082 const typename ::boost::multi_index::index<
1083 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
1085 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
1088 typedef multi_index_container<
1089 Value,IndexSpecifierList,Allocator> multi_index_type;
1090 typedef typename ::boost::multi_index::index<
1091 multi_index_container<
1092 Value,IndexSpecifierList,Allocator>,
1096 return detail::converter<multi_index_type,index_type>::index(m);
1099 /* projection of iterators by number */
1101 template<typename MultiIndexContainer,int N>
1102 struct nth_index_iterator
1104 typedef typename nth_index<MultiIndexContainer,N>::type::iterator type;
1107 template<typename MultiIndexContainer,int N>
1108 struct nth_index_const_iterator
1110 typedef typename nth_index<MultiIndexContainer,N>::type::const_iterator type;
1114 int N,typename IteratorType,
1115 typename Value,typename IndexSpecifierList,typename Allocator>
1116 typename nth_index_iterator<
1117 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
1119 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
1122 typedef multi_index_container<
1123 Value,IndexSpecifierList,Allocator> multi_index_type;
1124 typedef typename nth_index<multi_index_type,N>::type index_type;
1126 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
1127 BOOST_STATIC_ASSERT((
1129 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
1130 IteratorType>::value));
1133 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
1135 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
1136 typedef detail::converter<
1138 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
1139 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
1142 return detail::converter<multi_index_type,index_type>::iterator(
1143 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
1147 int N,typename IteratorType,
1148 typename Value,typename IndexSpecifierList,typename Allocator>
1149 typename nth_index_const_iterator<
1150 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
1152 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
1155 typedef multi_index_container<
1156 Value,IndexSpecifierList,Allocator> multi_index_type;
1157 typedef typename nth_index<multi_index_type,N>::type index_type;
1159 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
1160 BOOST_STATIC_ASSERT((
1162 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
1163 IteratorType>::value||
1165 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
1166 IteratorType>::value));
1169 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
1171 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
1172 typedef detail::converter<
1174 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
1175 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
1178 return detail::converter<multi_index_type,index_type>::const_iterator(
1179 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
1182 /* projection of iterators by tag */
1184 template<typename MultiIndexContainer,typename Tag>
1185 struct index_iterator
1187 typedef typename ::boost::multi_index::index<
1188 MultiIndexContainer,Tag>::type::iterator type;
1191 template<typename MultiIndexContainer,typename Tag>
1192 struct index_const_iterator
1194 typedef typename ::boost::multi_index::index<
1195 MultiIndexContainer,Tag>::type::const_iterator type;
1199 typename Tag,typename IteratorType,
1200 typename Value,typename IndexSpecifierList,typename Allocator>
1201 typename index_iterator<
1202 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
1204 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
1207 typedef multi_index_container<
1208 Value,IndexSpecifierList,Allocator> multi_index_type;
1209 typedef typename ::boost::multi_index::index<
1210 multi_index_type,Tag>::type index_type;
1212 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
1213 BOOST_STATIC_ASSERT((
1215 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
1216 IteratorType>::value));
1219 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
1221 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
1222 typedef detail::converter<
1224 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
1225 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
1228 return detail::converter<multi_index_type,index_type>::iterator(
1229 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
1233 typename Tag,typename IteratorType,
1234 typename Value,typename IndexSpecifierList,typename Allocator>
1235 typename index_const_iterator<
1236 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
1238 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
1241 typedef multi_index_container<
1242 Value,IndexSpecifierList,Allocator> multi_index_type;
1243 typedef typename ::boost::multi_index::index<
1244 multi_index_type,Tag>::type index_type;
1246 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
1247 BOOST_STATIC_ASSERT((
1249 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
1250 IteratorType>::value||
1252 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
1253 IteratorType>::value));
1256 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
1258 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
1259 typedef detail::converter<
1261 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
1262 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
1265 return detail::converter<multi_index_type,index_type>::const_iterator(
1266 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
1269 /* Comparison. Simple forward to first index. */
1272 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1273 typename Value2,typename IndexSpecifierList2,typename Allocator2
1276 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1277 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1279 return get<0>(x)==get<0>(y);
1283 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1284 typename Value2,typename IndexSpecifierList2,typename Allocator2
1287 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1288 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1290 return get<0>(x)<get<0>(y);
1294 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1295 typename Value2,typename IndexSpecifierList2,typename Allocator2
1298 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1299 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1301 return get<0>(x)!=get<0>(y);
1305 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1306 typename Value2,typename IndexSpecifierList2,typename Allocator2
1309 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1310 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1312 return get<0>(x)>get<0>(y);
1316 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1317 typename Value2,typename IndexSpecifierList2,typename Allocator2
1320 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1321 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1323 return get<0>(x)>=get<0>(y);
1327 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1328 typename Value2,typename IndexSpecifierList2,typename Allocator2
1331 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1332 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1334 return get<0>(x)<=get<0>(y);
1337 /* specialized algorithms */
1339 template<typename Value,typename IndexSpecifierList,typename Allocator>
1341 multi_index_container<Value,IndexSpecifierList,Allocator>& x,
1342 multi_index_container<Value,IndexSpecifierList,Allocator>& y)
1347 } /* namespace multi_index */
1349 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
1350 /* class version = 1 : we now serialize the size through
1351 * boost::serialization::collection_size_type.
1352 * class version = 2 : proper use of {save|load}_construct_data.
1355 namespace serialization {
1356 template<typename Value,typename IndexSpecifierList,typename Allocator>
1358 boost::multi_index_container<Value,IndexSpecifierList,Allocator>
1361 BOOST_STATIC_CONSTANT(int,value=2);
1363 } /* namespace serialization */
1366 /* Associated global functions are promoted to namespace boost, except
1367 * comparison operators and swap, which are meant to be Koenig looked-up.
1370 using multi_index::get;
1371 using multi_index::project;
1373 } /* namespace boost */
1375 #undef BOOST_MULTI_INDEX_CHECK_INVARIANT
1376 #undef BOOST_MULTI_INDEX_CHECK_INVARIANT_OF