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 #ifndef BOOST_MULTI_INDEX_DISABLE_SERIALIZATION
19 #define BOOST_MULTI_INDEX_DISABLE_SERIALIZATION 1
22 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
24 #include <boost/detail/allocator_utilities.hpp>
25 #include <boost/detail/no_exceptions_support.hpp>
26 #include <boost/detail/workaround.hpp>
27 #include <boost/mpl/at.hpp>
28 #include <boost/mpl/contains.hpp>
29 #include <boost/mpl/find_if.hpp>
30 #include <boost/mpl/identity.hpp>
31 #include <boost/mpl/int.hpp>
32 #include <boost/mpl/size.hpp>
33 #include <boost/mpl/deref.hpp>
34 #include <boost/multi_index_container_fwd.hpp>
35 #include <boost/multi_index/detail/access_specifier.hpp>
36 #include <boost/multi_index/detail/adl_swap.hpp>
37 #include <boost/multi_index/detail/base_type.hpp>
38 #include <boost/multi_index/detail/converter.hpp>
39 #include <boost/multi_index/detail/header_holder.hpp>
40 #include <boost/multi_index/detail/has_tag.hpp>
41 #include <boost/multi_index/detail/no_duplicate_tags.hpp>
42 #include <boost/multi_index/detail/prevent_eti.hpp>
43 #include <boost/multi_index/detail/safe_mode.hpp>
44 #include <boost/multi_index/detail/scope_guard.hpp>
45 #include <boost/static_assert.hpp>
46 #include <boost/type_traits/is_same.hpp>
47 #include <boost/utility/base_from_member.hpp>
49 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
50 #include <boost/multi_index/detail/archive_constructed.hpp>
51 #include <boost/serialization/nvp.hpp>
52 #include <boost/serialization/split_member.hpp>
53 #include <boost/throw_exception.hpp>
56 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
57 #include <boost/multi_index/detail/invariant_assert.hpp>
58 #define BOOST_MULTI_INDEX_CHECK_INVARIANT \
59 detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
60 detail::make_obj_guard(*this,&multi_index_container::check_invariant_); \
61 BOOST_JOIN(check_invariant_,__LINE__).touch();
63 #define BOOST_MULTI_INDEX_CHECK_INVARIANT
68 namespace multi_index{
70 template<typename Value,typename IndexSpecifierList,typename Allocator>
71 class multi_index_container:
72 private ::boost::base_from_member<
73 typename boost::detail::allocator::rebind_to<
75 typename detail::multi_index_node_type<
76 Value,IndexSpecifierList,Allocator>::type
78 BOOST_MULTI_INDEX_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS detail::header_holder<
79 typename detail::prevent_eti<
81 typename boost::detail::allocator::rebind_to<
83 typename detail::multi_index_node_type<
84 Value,IndexSpecifierList,Allocator>::type
87 multi_index_container<Value,IndexSpecifierList,Allocator> >,
88 public detail::multi_index_base_type<
89 Value,IndexSpecifierList,Allocator>::type
91 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
92 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
93 /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
94 * lifetime of const references bound to temporaries --precisely what
98 #pragma parse_mfunc_templ off
102 #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
103 template <typename,typename,typename> friend class detail::index_base;
104 template <typename,typename> friend struct detail::header_holder;
105 template <typename,typename> friend struct detail::converter;
108 typedef typename detail::multi_index_base_type<
109 Value,IndexSpecifierList,Allocator>::type super;
111 boost::detail::allocator::rebind_to<
113 typename super::node_type
114 >::type node_allocator;
115 typedef ::boost::base_from_member<
116 node_allocator> bfm_allocator;
117 typedef detail::header_holder<
118 typename detail::prevent_eti<
122 multi_index_container> bfm_header;
124 #if BOOST_WORKAROUND(BOOST_MSVC,<1300)
125 /* see definition of index_type_list below */
126 typedef typename super::index_type_list super_index_type_list;
130 /* All types are inherited from super, a few are explicitly
131 * brought forward here to save us some typename's.
134 typedef typename super::ctor_args_list ctor_args_list;
135 typedef IndexSpecifierList index_specifier_type_list;
137 #if BOOST_WORKAROUND(BOOST_MSVC,<1300)
138 /* MSVC++ 6.0 chokes on moderately long index lists (around 6 indices
139 * or more), with errors ranging from corrupt exes to duplicate
140 * comdats. The following type hiding hack alleviates this condition;
141 * best results combined with type hiding of the indexed_by construct
142 * itself, as explained in the "Compiler specifics" section of
146 struct index_type_list:super_index_type_list
148 typedef index_type_list type;
149 typedef typename super_index_type_list::back back;
150 typedef mpl::v_iter<type,0> begin;
153 mpl::size<super_index_type_list>::value> end;
156 typedef typename super::index_type_list index_type_list;
159 typedef typename super::iterator_type_list iterator_type_list;
160 typedef typename super::const_iterator_type_list const_iterator_type_list;
161 typedef typename super::value_type value_type;
162 typedef typename super::final_allocator_type allocator_type;
163 typedef typename super::iterator iterator;
164 typedef typename super::const_iterator const_iterator;
167 detail::no_duplicate_tags_in_index_list<index_type_list>::value);
169 /* global project() needs to see this publicly */
171 typedef typename super::node_type node_type;
173 /* construct/copy/destroy */
175 explicit multi_index_container(
177 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
178 /* VisualAge seems to have an ETI issue with the default values
179 * for arguments args_list and al.
182 const ctor_args_list& args_list=
183 typename mpl::identity<multi_index_container>::type::
185 const allocator_type& al=
186 typename mpl::identity<multi_index_container>::type::
189 const ctor_args_list& args_list=ctor_args_list(),
190 const allocator_type& al=allocator_type()):
194 super(args_list,bfm_allocator::member),
197 BOOST_MULTI_INDEX_CHECK_INVARIANT;
200 template<typename InputIterator>
201 multi_index_container(
202 InputIterator first,InputIterator last,
204 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
205 /* VisualAge seems to have an ETI issue with the default values
206 * for arguments args_list and al.
209 const ctor_args_list& args_list=
210 typename mpl::identity<multi_index_container>::type::
212 const allocator_type& al=
213 typename mpl::identity<multi_index_container>::type::
216 const ctor_args_list& args_list=ctor_args_list(),
217 const allocator_type& al=allocator_type()):
221 super(args_list,bfm_allocator::member),
224 BOOST_MULTI_INDEX_CHECK_INVARIANT;
226 iterator hint=super::end();
227 for(;first!=last;++first){
228 hint=super::make_iterator(insert_(*first,hint.get_node()).first);
238 multi_index_container(
239 const multi_index_container<Value,IndexSpecifierList,Allocator>& x):
240 bfm_allocator(x.bfm_allocator::member),
245 copy_map_type map(bfm_allocator::member,x.size(),x.header(),header());
246 for(const_iterator it=x.begin(),it_end=x.end();it!=it_end;++it){
247 map.clone(it.get_node());
253 /* Not until this point are the indices required to be consistent,
254 * hence the position of the invariant checker.
257 BOOST_MULTI_INDEX_CHECK_INVARIANT;
260 ~multi_index_container()
265 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
266 const multi_index_container<Value,IndexSpecifierList,Allocator>& x)
268 BOOST_MULTI_INDEX_CHECK_INVARIANT;
269 multi_index_container<Value,IndexSpecifierList,Allocator> tmp(x);
274 allocator_type get_allocator()const
276 return allocator_type(bfm_allocator::member);
279 /* retrieval of indices by number */
281 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
285 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
286 typedef typename mpl::at_c<index_type_list,N>::type type;
290 typename nth_index<N>::type& get(BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
292 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
297 const typename nth_index<N>::type& get(
298 BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int,N))const
300 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
305 /* retrieval of indices by tag */
307 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
308 template<typename Tag>
311 typedef typename mpl::find_if<
316 BOOST_STATIC_CONSTANT(
317 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
318 BOOST_STATIC_ASSERT(index_found);
320 typedef typename mpl::deref<iter>::type type;
323 template<typename Tag>
324 typename index<Tag>::type& get(BOOST_EXPLICIT_TEMPLATE_TYPE(Tag))
329 template<typename Tag>
330 const typename index<Tag>::type& get(
331 BOOST_EXPLICIT_TEMPLATE_TYPE(Tag))const
337 /* projection of iterators by number */
339 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
341 struct nth_index_iterator
343 typedef typename nth_index<N>::type::iterator type;
347 struct nth_index_const_iterator
349 typedef typename nth_index<N>::type::const_iterator type;
352 template<int N,typename IteratorType>
353 typename nth_index_iterator<N>::type project(
355 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
357 typedef typename nth_index<N>::type index;
359 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
361 (mpl::contains<iterator_type_list,IteratorType>::value));
364 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
365 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
366 it,static_cast<typename IteratorType::container_type&>(*this));
368 return index::make_iterator(static_cast<node_type*>(it.get_node()));
371 template<int N,typename IteratorType>
372 typename nth_index_const_iterator<N>::type project(
374 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))const
376 typedef typename nth_index<N>::type index;
378 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
379 BOOST_STATIC_ASSERT((
380 mpl::contains<iterator_type_list,IteratorType>::value||
381 mpl::contains<const_iterator_type_list,IteratorType>::value));
384 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
385 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
386 it,static_cast<const typename IteratorType::container_type&>(*this));
387 return index::make_iterator(static_cast<node_type*>(it.get_node()));
391 /* projection of iterators by tag */
393 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
394 template<typename Tag>
395 struct index_iterator
397 typedef typename index<Tag>::type::iterator type;
400 template<typename Tag>
401 struct index_const_iterator
403 typedef typename index<Tag>::type::const_iterator type;
406 template<typename Tag,typename IteratorType>
407 typename index_iterator<Tag>::type project(
409 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
411 typedef typename index<Tag>::type index;
413 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
415 (mpl::contains<iterator_type_list,IteratorType>::value));
418 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
419 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
420 it,static_cast<typename IteratorType::container_type&>(*this));
421 return index::make_iterator(static_cast<node_type*>(it.get_node()));
424 template<typename Tag,typename IteratorType>
425 typename index_const_iterator<Tag>::type project(
427 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))const
429 typedef typename index<Tag>::type index;
431 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
432 BOOST_STATIC_ASSERT((
433 mpl::contains<iterator_type_list,IteratorType>::value||
434 mpl::contains<const_iterator_type_list,IteratorType>::value));
437 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
438 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
439 it,static_cast<const typename IteratorType::container_type&>(*this));
440 return index::make_iterator(static_cast<node_type*>(it.get_node()));
444 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
445 typedef typename super::copy_map_type copy_map_type;
447 node_type* header()const
449 return &*bfm_header::member;
452 node_type* allocate_node()
454 return &*bfm_allocator::member.allocate(1);
457 void deallocate_node(node_type* x)
459 typedef typename node_allocator::pointer node_pointer;
460 bfm_allocator::member.deallocate(static_cast<node_pointer>(x),1);
465 return node_count==0;
468 std::size_t size_()const
473 std::size_t max_size_()const
475 return static_cast<std::size_t >(-1);
478 std::pair<node_type*,bool> insert_(const Value& v)
480 node_type* x=allocate_node();
482 node_type* res=super::insert_(v,x);
485 return std::pair<node_type*,bool>(res,true);
489 return std::pair<node_type*,bool>(res,false);
499 std::pair<node_type*,bool> insert_(const Value& v,node_type* position)
501 node_type* x=allocate_node();
503 node_type* res=super::insert_(v,position,x);
506 return std::pair<node_type*,bool>(res,true);
510 return std::pair<node_type*,bool>(res,false);
520 void erase_(node_type* x)
527 void delete_node_(node_type* x)
529 super::delete_node_(x);
533 void delete_all_nodes_()
535 super::delete_all_nodes_();
545 void swap_(multi_index_container<Value,IndexSpecifierList,Allocator>& x)
547 if(bfm_allocator::member!=x.bfm_allocator::member){
548 detail::adl_swap(bfm_allocator::member,x.bfm_allocator::member);
550 std::swap(bfm_header::member,x.bfm_header::member);
552 std::swap(node_count,x.node_count);
555 bool replace_(const Value& k,node_type* x)
557 return super::replace_(k,x);
560 template<typename Modifier>
561 bool modify_(Modifier& mod,node_type* x)
563 mod(const_cast<value_type&>(x->value()));
566 if(!super::modify_(x)){
581 template<typename Modifier,typename Rollback>
582 bool modify_(Modifier& mod,Rollback& back,node_type* x)
584 mod(const_cast<value_type&>(x->value()));
588 b=super::modify_rollback_(x);
592 back(const_cast<value_type&>(x->value()));
605 back(const_cast<value_type&>(x->value()));
617 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
620 friend class boost::serialization::access;
622 BOOST_SERIALIZATION_SPLIT_MEMBER()
624 typedef typename super::index_saver_type index_saver_type;
625 typedef typename super::index_loader_type index_loader_type;
627 template<class Archive>
628 void save(Archive& ar,const unsigned int version)const
630 const std::size_t s=size_();
631 ar<<serialization::make_nvp("count",s);
632 index_saver_type sm(bfm_allocator::member,s);
634 for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){
635 ar<<serialization::make_nvp("item",*it);
636 sm.add(it.get_node(),ar,version);
638 sm.add_track(header(),ar,version);
640 super::save_(ar,version,sm);
643 template<class Archive>
644 void load(Archive& ar,const unsigned int version)
646 BOOST_MULTI_INDEX_CHECK_INVARIANT;
651 ar>>serialization::make_nvp("count",s);
652 index_loader_type lm(bfm_allocator::member,s);
654 for(std::size_t n=0;n<s;++n){
655 detail::archive_constructed<Value> value("item",ar,version);
656 std::pair<node_type*,bool> p=insert_(
657 value.get(),super::end().get_node());
658 if(!p.second)throw_exception(
659 archive::archive_exception(
660 archive::archive_exception::other_exception));
661 ar.reset_object_address(&p.first->value(),&value.get());
662 lm.add(p.first,ar,version);
664 lm.add_track(header(),ar,version);
666 super::load_(ar,version,lm);
670 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
671 /* invariant stuff */
673 bool invariant_()const
675 return super::invariant_();
678 void check_invariant_()const
680 BOOST_MULTI_INDEX_INVARIANT_ASSERT(invariant_());
685 std::size_t node_count;
687 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
688 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
689 #pragma parse_mfunc_templ reset
693 /* retrieval of indices by number */
695 template<typename MultiIndexContainer,int N>
698 BOOST_STATIC_CONSTANT(
700 M=mpl::size<typename MultiIndexContainer::index_type_list>::type::value);
701 BOOST_STATIC_ASSERT(N>=0&&N<M);
702 typedef typename mpl::at_c<
703 typename MultiIndexContainer::index_type_list,N>::type type;
706 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
708 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
710 multi_index_container<Value,IndexSpecifierList,Allocator>& m
711 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
713 typedef multi_index_container<
714 Value,IndexSpecifierList,Allocator> multi_index_type;
715 typedef typename nth_index<
716 multi_index_container<
717 Value,IndexSpecifierList,Allocator>,
721 BOOST_STATIC_ASSERT(N>=0&&
724 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
727 return detail::converter<multi_index_type,index>::index(m);
730 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
731 const typename nth_index<
732 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
734 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
735 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
737 typedef multi_index_container<
738 Value,IndexSpecifierList,Allocator> multi_index_type;
739 typedef typename nth_index<
740 multi_index_container<
741 Value,IndexSpecifierList,Allocator>,
745 BOOST_STATIC_ASSERT(N>=0&&
748 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
751 return detail::converter<multi_index_type,index>::index(m);
754 /* retrieval of indices by tag */
756 template<typename MultiIndexContainer,typename Tag>
759 typedef typename MultiIndexContainer::index_type_list index_type_list;
761 typedef typename mpl::find_if<
766 BOOST_STATIC_CONSTANT(
767 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
768 BOOST_STATIC_ASSERT(index_found);
770 typedef typename mpl::deref<iter>::type type;
774 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
776 typename ::boost::multi_index::index<
777 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
779 multi_index_container<Value,IndexSpecifierList,Allocator>& m
780 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
782 typedef multi_index_container<
783 Value,IndexSpecifierList,Allocator> multi_index_type;
784 typedef typename ::boost::multi_index::index<
785 multi_index_container<
786 Value,IndexSpecifierList,Allocator>,
790 return detail::converter<multi_index_type,index>::index(m);
794 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
796 const typename ::boost::multi_index::index<
797 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
799 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
800 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
802 typedef multi_index_container<
803 Value,IndexSpecifierList,Allocator> multi_index_type;
804 typedef typename ::boost::multi_index::index<
805 multi_index_container<
806 Value,IndexSpecifierList,Allocator>,
810 return detail::converter<multi_index_type,index>::index(m);
813 /* projection of iterators by number */
815 template<typename MultiIndexContainer,int N>
816 struct nth_index_iterator
818 typedef typename detail::prevent_eti<
819 nth_index<MultiIndexContainer,N>,
820 typename nth_index<MultiIndexContainer,N>::type>::type::iterator type;
823 template<typename MultiIndexContainer,int N>
824 struct nth_index_const_iterator
826 typedef typename detail::prevent_eti<
827 nth_index<MultiIndexContainer,N>,
828 typename nth_index<MultiIndexContainer,N>::type
829 >::type::const_iterator type;
833 int N,typename IteratorType,
834 typename Value,typename IndexSpecifierList,typename Allocator>
835 typename nth_index_iterator<
836 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
838 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
840 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
842 typedef multi_index_container<
843 Value,IndexSpecifierList,Allocator> multi_index_type;
844 typedef typename nth_index<multi_index_type,N>::type index;
846 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
847 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
848 BOOST_STATIC_ASSERT((
850 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
851 IteratorType>::value));
854 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
856 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
857 typedef detail::converter<
859 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
860 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
863 return detail::converter<multi_index_type,index>::iterator(
864 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
868 int N,typename IteratorType,
869 typename Value,typename IndexSpecifierList,typename Allocator>
870 typename nth_index_const_iterator<
871 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
873 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
875 BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int,N))
877 typedef multi_index_container<
878 Value,IndexSpecifierList,Allocator> multi_index_type;
879 typedef typename nth_index<multi_index_type,N>::type index;
881 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
882 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
883 BOOST_STATIC_ASSERT((
885 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
886 IteratorType>::value||
888 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
889 IteratorType>::value));
892 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
894 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
895 typedef detail::converter<
897 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
898 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
901 return detail::converter<multi_index_type,index>::const_iterator(
902 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
905 /* projection of iterators by tag */
907 template<typename MultiIndexContainer,typename Tag>
908 struct index_iterator
910 typedef typename ::boost::multi_index::index<
911 MultiIndexContainer,Tag>::type::iterator type;
914 template<typename MultiIndexContainer,typename Tag>
915 struct index_const_iterator
917 typedef typename ::boost::multi_index::index<
918 MultiIndexContainer,Tag>::type::const_iterator type;
922 typename Tag,typename IteratorType,
923 typename Value,typename IndexSpecifierList,typename Allocator>
924 typename index_iterator<
925 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
927 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
929 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
931 typedef multi_index_container<
932 Value,IndexSpecifierList,Allocator> multi_index_type;
933 typedef typename ::boost::multi_index::index<
934 multi_index_type,Tag>::type index;
936 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
937 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
938 BOOST_STATIC_ASSERT((
940 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
941 IteratorType>::value));
944 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
946 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
947 typedef detail::converter<
949 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
950 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
953 return detail::converter<multi_index_type,index>::iterator(
954 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
958 typename Tag,typename IteratorType,
959 typename Value,typename IndexSpecifierList,typename Allocator>
960 typename index_const_iterator<
961 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
963 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
965 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Tag))
967 typedef multi_index_container<
968 Value,IndexSpecifierList,Allocator> multi_index_type;
969 typedef typename ::boost::multi_index::index<
970 multi_index_type,Tag>::type index;
972 #if (!defined(BOOST_MSVC)||!(BOOST_MSVC<1310))&& /* MSVC++ 6.0/7.0 fails */\
973 (!defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580)) /* as does Sun C++ 5.7 */
974 BOOST_STATIC_ASSERT((
976 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
977 IteratorType>::value||
979 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
980 IteratorType>::value));
983 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
985 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
986 typedef detail::converter<
988 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
989 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
992 return detail::converter<multi_index_type,index>::const_iterator(
993 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
996 /* Comparison. Simple forward to first index. */
999 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1000 typename Value2,typename IndexSpecifierList2,typename Allocator2
1003 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1004 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1006 return get<0>(x)==get<0>(y);
1010 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1011 typename Value2,typename IndexSpecifierList2,typename Allocator2
1014 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1015 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1017 return get<0>(x)<get<0>(y);
1021 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1022 typename Value2,typename IndexSpecifierList2,typename Allocator2
1025 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1026 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1028 return get<0>(x)!=get<0>(y);
1032 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1033 typename Value2,typename IndexSpecifierList2,typename Allocator2
1036 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1037 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1039 return get<0>(x)>get<0>(y);
1043 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1044 typename Value2,typename IndexSpecifierList2,typename Allocator2
1047 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1048 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1050 return get<0>(x)>=get<0>(y);
1054 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1055 typename Value2,typename IndexSpecifierList2,typename Allocator2
1058 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1059 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1061 return get<0>(x)<=get<0>(y);
1064 /* specialized algorithms */
1066 template<typename Value,typename IndexSpecifierList,typename Allocator>
1068 multi_index_container<Value,IndexSpecifierList,Allocator>& x,
1069 multi_index_container<Value,IndexSpecifierList,Allocator>& y)
1074 } /* namespace multi_index */
1076 /* Associated global functions are promoted to namespace boost, except
1077 * comparison operators and swap, which are meant to be Koenig looked-up.
1080 using multi_index::get;
1081 using multi_index::project;
1083 } /* namespace boost */
1085 #undef BOOST_MULTI_INDEX_CHECK_INVARIANT