1 /* Multiply indexed container.
3 * Copyright 2003-2007 Joaquín M López Muñoz.
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
14 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
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/mpl/at.hpp>
24 #include <boost/mpl/contains.hpp>
25 #include <boost/mpl/find_if.hpp>
26 #include <boost/mpl/identity.hpp>
27 #include <boost/mpl/int.hpp>
28 #include <boost/mpl/size.hpp>
29 #include <boost/mpl/deref.hpp>
30 #include <boost/multi_index_container_fwd.hpp>
31 #include <boost/multi_index/detail/access_specifier.hpp>
32 #include <boost/multi_index/detail/adl_swap.hpp>
33 #include <boost/multi_index/detail/base_type.hpp>
34 #include <boost/multi_index/detail/converter.hpp>
35 #include <boost/multi_index/detail/header_holder.hpp>
36 #include <boost/multi_index/detail/has_tag.hpp>
37 #include <boost/multi_index/detail/no_duplicate_tags.hpp>
38 #include <boost/multi_index/detail/prevent_eti.hpp>
39 #include <boost/multi_index/detail/safe_mode.hpp>
40 #include <boost/multi_index/detail/scope_guard.hpp>
41 #include <boost/static_assert.hpp>
42 #include <boost/type_traits/is_same.hpp>
43 #include <boost/utility/base_from_member.hpp>
45 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
46 #include <boost/multi_index/detail/archive_constructed.hpp>
47 #include <boost/serialization/nvp.hpp>
48 #include <boost/serialization/split_member.hpp>
49 #include <boost/throw_exception.hpp>
52 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
53 #include <boost/multi_index/detail/invariant_assert.hpp>
54 #define BOOST_MULTI_INDEX_CHECK_INVARIANT \
55 detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
56 detail::make_obj_guard(*this,&multi_index_container::check_invariant_); \
57 BOOST_JOIN(check_invariant_,__LINE__).touch();
59 #define BOOST_MULTI_INDEX_CHECK_INVARIANT
64 namespace multi_index{
66 template<typename Value,typename IndexSpecifierList,typename Allocator>
67 class multi_index_container:
68 private ::boost::base_from_member<
69 typename boost::detail::allocator::rebind_to<
71 typename detail::multi_index_node_type<
72 Value,IndexSpecifierList,Allocator>::type
74 BOOST_MULTI_INDEX_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS detail::header_holder<
75 typename detail::prevent_eti<
77 typename boost::detail::allocator::rebind_to<
79 typename detail::multi_index_node_type<
80 Value,IndexSpecifierList,Allocator>::type
83 multi_index_container<Value,IndexSpecifierList,Allocator> >,
84 public detail::multi_index_base_type<
85 Value,IndexSpecifierList,Allocator>::type
87 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
88 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
89 /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
90 * lifetime of const references bound to temporaries --precisely what
94 #pragma parse_mfunc_templ off
98 #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
99 template <typename,typename,typename> friend class detail::index_base;
100 template <typename,typename> friend struct detail::header_holder;
101 template <typename,typename> friend struct detail::converter;
104 typedef typename detail::multi_index_base_type<
105 Value,IndexSpecifierList,Allocator>::type super;
107 boost::detail::allocator::rebind_to<
109 typename super::node_type
110 >::type node_allocator;
111 typedef ::boost::base_from_member<
112 node_allocator> bfm_allocator;
113 typedef detail::header_holder<
114 typename detail::prevent_eti<
118 multi_index_container> bfm_header;
120 #if BOOST_WORKAROUND(BOOST_MSVC,<1300)
121 /* see definition of index_type_list below */
122 typedef typename super::index_type_list super_index_type_list;
126 /* All types are inherited from super, a few are explicitly
127 * brought forward here to save us some typename's.
130 typedef typename super::ctor_args_list ctor_args_list;
131 typedef IndexSpecifierList index_specifier_type_list;
133 #if BOOST_WORKAROUND(BOOST_MSVC,<1300)
134 /* MSVC++ 6.0 chokes on moderately long index lists (around 6 indices
135 * or more), with errors ranging from corrupt exes to duplicate
136 * comdats. The following type hiding hack alleviates this condition;
137 * best results combined with type hiding of the indexed_by construct
138 * itself, as explained in the "Compiler specifics" section of
142 struct index_type_list:super_index_type_list
144 typedef index_type_list type;
145 typedef typename super_index_type_list::back back;
146 typedef mpl::v_iter<type,0> begin;
149 mpl::size<super_index_type_list>::value> end;
152 typedef typename super::index_type_list index_type_list;
155 typedef typename super::iterator_type_list iterator_type_list;
156 typedef typename super::const_iterator_type_list const_iterator_type_list;
157 typedef typename super::value_type value_type;
158 typedef typename super::final_allocator_type allocator_type;
159 typedef typename super::iterator iterator;
160 typedef typename super::const_iterator const_iterator;
163 detail::no_duplicate_tags_in_index_list<index_type_list>::value);
165 /* global project() needs to see this publicly */
167 typedef typename super::node_type node_type;
169 /* construct/copy/destroy */
171 explicit multi_index_container(
173 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
174 /* VisualAge seems to have an ETI issue with the default values
175 * for arguments args_list and al.
178 const ctor_args_list& args_list=
179 typename mpl::identity<multi_index_container>::type::
181 const allocator_type& al=
182 typename mpl::identity<multi_index_container>::type::
185 const ctor_args_list& args_list=ctor_args_list(),
186 const allocator_type& al=allocator_type()):
190 super(args_list,bfm_allocator::member),
193 BOOST_MULTI_INDEX_CHECK_INVARIANT;
196 template<typename InputIterator>
197 multi_index_container(
198 InputIterator first,InputIterator last,
200 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
201 /* VisualAge seems to have an ETI issue with the default values
202 * for arguments args_list and al.
205 const ctor_args_list& args_list=
206 typename mpl::identity<multi_index_container>::type::
208 const allocator_type& al=
209 typename mpl::identity<multi_index_container>::type::
212 const ctor_args_list& args_list=ctor_args_list(),
213 const allocator_type& al=allocator_type()):
217 super(args_list,bfm_allocator::member),
220 BOOST_MULTI_INDEX_CHECK_INVARIANT;
222 iterator hint=super::end();
223 for(;first!=last;++first){
224 hint=super::make_iterator(insert_(*first,hint.get_node()).first);
234 multi_index_container(
235 const multi_index_container<Value,IndexSpecifierList,Allocator>& x):
236 bfm_allocator(x.bfm_allocator::member),
241 copy_map_type map(bfm_allocator::member,x.size(),x.header(),header());
242 for(const_iterator it=x.begin(),it_end=x.end();it!=it_end;++it){
243 map.clone(it.get_node());
249 /* Not until this point are the indices required to be consistent,
250 * hence the position of the invariant checker.
253 BOOST_MULTI_INDEX_CHECK_INVARIANT;
256 ~multi_index_container()
261 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
262 const multi_index_container<Value,IndexSpecifierList,Allocator>& x)
264 BOOST_MULTI_INDEX_CHECK_INVARIANT;
265 multi_index_container<Value,IndexSpecifierList,Allocator> tmp(x);
270 allocator_type get_allocator()const
272 return allocator_type(bfm_allocator::member);
275 /* retrieval of indices by number */
277 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
281 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
282 typedef typename mpl::at_c<index_type_list,N>::type type;
286 typename nth_index<N>::type& get(BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
288 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
293 const typename nth_index<N>::type& get(
294 BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int,N))const
296 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
301 /* retrieval of indices by tag */
303 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
304 template<typename Tag>
307 typedef typename mpl::find_if<
312 BOOST_STATIC_CONSTANT(
313 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
314 BOOST_STATIC_ASSERT(index_found);
316 typedef typename mpl::deref<iter>::type type;
319 template<typename Tag>
320 typename index<Tag>::type& get(BOOST_EXPLICIT_TEMPLATE_TYPE(Tag))
325 template<typename Tag>
326 const typename index<Tag>::type& get(
327 BOOST_EXPLICIT_TEMPLATE_TYPE(Tag))const
333 /* projection of iterators by number */
335 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
337 struct nth_index_iterator
339 typedef typename nth_index<N>::type::iterator type;
343 struct nth_index_const_iterator
345 typedef typename nth_index<N>::type::const_iterator type;
348 template<int N,typename IteratorType>
349 typename nth_index_iterator<N>::type project(
351 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
353 typedef typename nth_index<N>::type index;
355 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
357 (mpl::contains<iterator_type_list,IteratorType>::value));
360 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
361 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
362 it,static_cast<typename IteratorType::container_type&>(*this));
364 return index::make_iterator(static_cast<node_type*>(it.get_node()));
367 template<int N,typename IteratorType>
368 typename nth_index_const_iterator<N>::type project(
370 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))const
372 typedef typename nth_index<N>::type index;
374 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
375 BOOST_STATIC_ASSERT((
376 mpl::contains<iterator_type_list,IteratorType>::value||
377 mpl::contains<const_iterator_type_list,IteratorType>::value));
380 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
381 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
382 it,static_cast<const typename IteratorType::container_type&>(*this));
383 return index::make_iterator(static_cast<node_type*>(it.get_node()));
387 /* projection of iterators by tag */
389 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
390 template<typename Tag>
391 struct index_iterator
393 typedef typename index<Tag>::type::iterator type;
396 template<typename Tag>
397 struct index_const_iterator
399 typedef typename index<Tag>::type::const_iterator type;
402 template<typename Tag,typename IteratorType>
403 typename index_iterator<Tag>::type project(
405 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
407 typedef typename index<Tag>::type index;
409 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
411 (mpl::contains<iterator_type_list,IteratorType>::value));
414 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
415 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
416 it,static_cast<typename IteratorType::container_type&>(*this));
417 return index::make_iterator(static_cast<node_type*>(it.get_node()));
420 template<typename Tag,typename IteratorType>
421 typename index_const_iterator<Tag>::type project(
423 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))const
425 typedef typename index<Tag>::type index;
427 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
428 BOOST_STATIC_ASSERT((
429 mpl::contains<iterator_type_list,IteratorType>::value||
430 mpl::contains<const_iterator_type_list,IteratorType>::value));
433 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
434 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
435 it,static_cast<const typename IteratorType::container_type&>(*this));
436 return index::make_iterator(static_cast<node_type*>(it.get_node()));
440 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
441 typedef typename super::copy_map_type copy_map_type;
443 node_type* header()const
445 return &*bfm_header::member;
448 node_type* allocate_node()
450 return &*bfm_allocator::member.allocate(1);
453 void deallocate_node(node_type* x)
455 typedef typename node_allocator::pointer node_pointer;
456 bfm_allocator::member.deallocate(static_cast<node_pointer>(x),1);
461 return node_count==0;
464 std::size_t size_()const
469 std::size_t max_size_()const
471 return static_cast<std::size_t >(-1);
474 std::pair<node_type*,bool> insert_(const Value& v)
476 node_type* x=allocate_node();
478 node_type* res=super::insert_(v,x);
481 return std::pair<node_type*,bool>(res,true);
485 return std::pair<node_type*,bool>(res,false);
495 std::pair<node_type*,bool> insert_(const Value& v,node_type* position)
497 node_type* x=allocate_node();
499 node_type* res=super::insert_(v,position,x);
502 return std::pair<node_type*,bool>(res,true);
506 return std::pair<node_type*,bool>(res,false);
516 void erase_(node_type* x)
523 void delete_node_(node_type* x)
525 super::delete_node_(x);
529 void delete_all_nodes_()
531 super::delete_all_nodes_();
541 void swap_(multi_index_container<Value,IndexSpecifierList,Allocator>& x)
543 if(bfm_allocator::member!=x.bfm_allocator::member){
544 detail::adl_swap(bfm_allocator::member,x.bfm_allocator::member);
546 std::swap(bfm_header::member,x.bfm_header::member);
548 std::swap(node_count,x.node_count);
551 bool replace_(const Value& k,node_type* x)
553 return super::replace_(k,x);
556 template<typename Modifier>
557 bool modify_(Modifier& mod,node_type* x)
559 mod(const_cast<value_type&>(x->value()));
562 if(!super::modify_(x)){
577 template<typename Modifier,typename Rollback>
578 bool modify_(Modifier& mod,Rollback& back,node_type* x)
580 mod(const_cast<value_type&>(x->value()));
584 b=super::modify_rollback_(x);
588 back(const_cast<value_type&>(x->value()));
601 back(const_cast<value_type&>(x->value()));
613 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
616 friend class boost::serialization::access;
618 BOOST_SERIALIZATION_SPLIT_MEMBER()
620 typedef typename super::index_saver_type index_saver_type;
621 typedef typename super::index_loader_type index_loader_type;
623 template<class Archive>
624 void save(Archive& ar,const unsigned int version)const
626 const std::size_t s=size_();
627 ar<<serialization::make_nvp("count",s);
628 index_saver_type sm(bfm_allocator::member,s);
630 for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){
631 ar<<serialization::make_nvp("item",*it);
632 sm.add(it.get_node(),ar,version);
634 sm.add_track(header(),ar,version);
636 super::save_(ar,version,sm);
639 template<class Archive>
640 void load(Archive& ar,const unsigned int version)
642 BOOST_MULTI_INDEX_CHECK_INVARIANT;
647 ar>>serialization::make_nvp("count",s);
648 index_loader_type lm(bfm_allocator::member,s);
650 for(std::size_t n=0;n<s;++n){
651 detail::archive_constructed<Value> value("item",ar,version);
652 std::pair<node_type*,bool> p=insert_(
653 value.get(),super::end().get_node());
654 if(!p.second)throw_exception(
655 archive::archive_exception(
656 archive::archive_exception::other_exception));
657 ar.reset_object_address(&p.first->value(),&value.get());
658 lm.add(p.first,ar,version);
660 lm.add_track(header(),ar,version);
662 super::load_(ar,version,lm);
666 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
667 /* invariant stuff */
669 bool invariant_()const
671 return super::invariant_();
674 void check_invariant_()const
676 BOOST_MULTI_INDEX_INVARIANT_ASSERT(invariant_());
681 std::size_t node_count;
683 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
684 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
685 #pragma parse_mfunc_templ reset
689 /* retrieval of indices by number */
691 template<typename MultiIndexContainer,int N>
694 BOOST_STATIC_CONSTANT(
696 M=mpl::size<typename MultiIndexContainer::index_type_list>::type::value);
697 BOOST_STATIC_ASSERT(N>=0&&N<M);
698 typedef typename mpl::at_c<
699 typename MultiIndexContainer::index_type_list,N>::type type;
702 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
704 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
706 multi_index_container<Value,IndexSpecifierList,Allocator>& m
707 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
709 typedef multi_index_container<
710 Value,IndexSpecifierList,Allocator> multi_index_type;
711 typedef typename nth_index<
712 multi_index_container<
713 Value,IndexSpecifierList,Allocator>,
717 BOOST_STATIC_ASSERT(N>=0&&
720 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
723 return detail::converter<multi_index_type,index>::index(m);
726 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
727 const typename nth_index<
728 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
730 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
731 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
733 typedef multi_index_container<
734 Value,IndexSpecifierList,Allocator> multi_index_type;
735 typedef typename nth_index<
736 multi_index_container<
737 Value,IndexSpecifierList,Allocator>,
741 BOOST_STATIC_ASSERT(N>=0&&
744 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
747 return detail::converter<multi_index_type,index>::index(m);
750 /* retrieval of indices by tag */
752 template<typename MultiIndexContainer,typename Tag>
755 typedef typename MultiIndexContainer::index_type_list index_type_list;
757 typedef typename mpl::find_if<
762 BOOST_STATIC_CONSTANT(
763 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
764 BOOST_STATIC_ASSERT(index_found);
766 typedef typename mpl::deref<iter>::type type;
770 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
772 typename ::boost::multi_index::index<
773 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
775 multi_index_container<Value,IndexSpecifierList,Allocator>& m
776 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
778 typedef multi_index_container<
779 Value,IndexSpecifierList,Allocator> multi_index_type;
780 typedef typename ::boost::multi_index::index<
781 multi_index_container<
782 Value,IndexSpecifierList,Allocator>,
786 return detail::converter<multi_index_type,index>::index(m);
790 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
792 const typename ::boost::multi_index::index<
793 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
795 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
796 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
798 typedef multi_index_container<
799 Value,IndexSpecifierList,Allocator> multi_index_type;
800 typedef typename ::boost::multi_index::index<
801 multi_index_container<
802 Value,IndexSpecifierList,Allocator>,
806 return detail::converter<multi_index_type,index>::index(m);
809 /* projection of iterators by number */
811 template<typename MultiIndexContainer,int N>
812 struct nth_index_iterator
814 typedef typename detail::prevent_eti<
815 nth_index<MultiIndexContainer,N>,
816 typename nth_index<MultiIndexContainer,N>::type>::type::iterator type;
819 template<typename MultiIndexContainer,int N>
820 struct nth_index_const_iterator
822 typedef typename detail::prevent_eti<
823 nth_index<MultiIndexContainer,N>,
824 typename nth_index<MultiIndexContainer,N>::type
825 >::type::const_iterator type;
829 int N,typename IteratorType,
830 typename Value,typename IndexSpecifierList,typename Allocator>
831 typename nth_index_iterator<
832 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
834 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
836 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
838 typedef multi_index_container<
839 Value,IndexSpecifierList,Allocator> multi_index_type;
840 typedef typename nth_index<multi_index_type,N>::type index;
842 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
843 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
844 BOOST_STATIC_ASSERT((
846 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
847 IteratorType>::value));
850 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
852 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
853 typedef detail::converter<
855 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
856 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
859 return detail::converter<multi_index_type,index>::iterator(
860 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
864 int N,typename IteratorType,
865 typename Value,typename IndexSpecifierList,typename Allocator>
866 typename nth_index_const_iterator<
867 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
869 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
871 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
873 typedef multi_index_container<
874 Value,IndexSpecifierList,Allocator> multi_index_type;
875 typedef typename nth_index<multi_index_type,N>::type index;
877 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
878 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
879 BOOST_STATIC_ASSERT((
881 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
882 IteratorType>::value||
884 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
885 IteratorType>::value));
888 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
890 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
891 typedef detail::converter<
893 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
894 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
897 return detail::converter<multi_index_type,index>::const_iterator(
898 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
901 /* projection of iterators by tag */
903 template<typename MultiIndexContainer,typename Tag>
904 struct index_iterator
906 typedef typename ::boost::multi_index::index<
907 MultiIndexContainer,Tag>::type::iterator type;
910 template<typename MultiIndexContainer,typename Tag>
911 struct index_const_iterator
913 typedef typename ::boost::multi_index::index<
914 MultiIndexContainer,Tag>::type::const_iterator type;
918 typename Tag,typename IteratorType,
919 typename Value,typename IndexSpecifierList,typename Allocator>
920 typename index_iterator<
921 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
923 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
925 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
927 typedef multi_index_container<
928 Value,IndexSpecifierList,Allocator> multi_index_type;
929 typedef typename ::boost::multi_index::index<
930 multi_index_type,Tag>::type index;
932 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
933 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
934 BOOST_STATIC_ASSERT((
936 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
937 IteratorType>::value));
940 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
942 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
943 typedef detail::converter<
945 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
946 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
949 return detail::converter<multi_index_type,index>::iterator(
950 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
954 typename Tag,typename IteratorType,
955 typename Value,typename IndexSpecifierList,typename Allocator>
956 typename index_const_iterator<
957 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
959 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
961 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
963 typedef multi_index_container<
964 Value,IndexSpecifierList,Allocator> multi_index_type;
965 typedef typename ::boost::multi_index::index<
966 multi_index_type,Tag>::type index;
968 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
969 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
970 BOOST_STATIC_ASSERT((
972 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
973 IteratorType>::value||
975 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
976 IteratorType>::value));
979 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
981 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
982 typedef detail::converter<
984 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
985 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
988 return detail::converter<multi_index_type,index>::const_iterator(
989 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
992 /* Comparison. Simple forward to first index. */
995 typename Value1,typename IndexSpecifierList1,typename Allocator1,
996 typename Value2,typename IndexSpecifierList2,typename Allocator2
999 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1000 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1002 return get<0>(x)==get<0>(y);
1006 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1007 typename Value2,typename IndexSpecifierList2,typename Allocator2
1010 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1011 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1013 return get<0>(x)<get<0>(y);
1017 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1018 typename Value2,typename IndexSpecifierList2,typename Allocator2
1021 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1022 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1024 return get<0>(x)!=get<0>(y);
1028 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1029 typename Value2,typename IndexSpecifierList2,typename Allocator2
1032 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1033 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1035 return get<0>(x)>get<0>(y);
1039 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1040 typename Value2,typename IndexSpecifierList2,typename Allocator2
1043 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1044 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1046 return get<0>(x)>=get<0>(y);
1050 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1051 typename Value2,typename IndexSpecifierList2,typename Allocator2
1054 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1055 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1057 return get<0>(x)<=get<0>(y);
1060 /* specialized algorithms */
1062 template<typename Value,typename IndexSpecifierList,typename Allocator>
1064 multi_index_container<Value,IndexSpecifierList,Allocator>& x,
1065 multi_index_container<Value,IndexSpecifierList,Allocator>& y)
1070 } /* namespace multi_index */
1072 /* Associated global functions are promoted to namespace boost, except
1073 * comparison operators and swap, which are meant to be Koenig looked-up.
1076 using multi_index::get;
1077 using multi_index::project;
1079 } /* namespace boost */
1081 #undef BOOST_MULTI_INDEX_CHECK_INVARIANT