1 /* Multiply indexed container.
3 * Copyright 2003-2020 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/core/addressof.hpp>
21 #include <boost/detail/no_exceptions_support.hpp>
22 #include <boost/detail/workaround.hpp>
23 #include <boost/move/core.hpp>
24 #include <boost/move/utility_core.hpp>
25 #include <boost/mpl/at.hpp>
26 #include <boost/mpl/contains.hpp>
27 #include <boost/mpl/find_if.hpp>
28 #include <boost/mpl/identity.hpp>
29 #include <boost/mpl/int.hpp>
30 #include <boost/mpl/size.hpp>
31 #include <boost/mpl/deref.hpp>
32 #include <boost/multi_index_container_fwd.hpp>
33 #include <boost/multi_index/detail/access_specifier.hpp>
34 #include <boost/multi_index/detail/adl_swap.hpp>
35 #include <boost/multi_index/detail/allocator_traits.hpp>
36 #include <boost/multi_index/detail/base_type.hpp>
37 #include <boost/multi_index/detail/do_not_copy_elements_tag.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/safe_mode.hpp>
43 #include <boost/multi_index/detail/scope_guard.hpp>
44 #include <boost/multi_index/detail/vartempl_support.hpp>
45 #include <boost/static_assert.hpp>
46 #include <boost/type_traits/integral_constant.hpp>
47 #include <boost/type_traits/is_same.hpp>
48 #include <boost/utility/base_from_member.hpp>
50 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
51 #include <initializer_list>
54 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
55 #include <boost/multi_index/detail/archive_constructed.hpp>
56 #include <boost/multi_index/detail/serialization_version.hpp>
57 #include <boost/serialization/collection_size_type.hpp>
58 #include <boost/serialization/nvp.hpp>
59 #include <boost/serialization/split_member.hpp>
60 #include <boost/serialization/version.hpp>
61 #include <boost/throw_exception.hpp>
64 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
65 #include <boost/multi_index/detail/invariant_assert.hpp>
66 #define BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x) \
67 detail::scope_guard BOOST_JOIN(check_invariant_,__LINE__)= \
68 detail::make_obj_guard(x,&multi_index_container::check_invariant_); \
69 BOOST_JOIN(check_invariant_,__LINE__).touch();
70 #define BOOST_MULTI_INDEX_CHECK_INVARIANT \
71 BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(*this)
73 #define BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x)
74 #define BOOST_MULTI_INDEX_CHECK_INVARIANT
79 namespace multi_index{
83 struct unequal_alloc_move_ctor_tag{};
85 } /* namespace multi_index::detail */
87 #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
89 #pragma warning(disable:4522) /* spurious warning on multiple operator=()'s */
92 template<typename Value,typename IndexSpecifierList,typename Allocator>
93 class multi_index_container:
94 private ::boost::base_from_member<
95 typename detail::rebind_alloc_for<
97 typename detail::multi_index_node_type<
98 Value,IndexSpecifierList,Allocator>::type
101 BOOST_MULTI_INDEX_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS detail::header_holder<
102 typename detail::allocator_traits<
103 typename detail::rebind_alloc_for<
105 typename detail::multi_index_node_type<
106 Value,IndexSpecifierList,Allocator>::type
109 multi_index_container<Value,IndexSpecifierList,Allocator> >,
110 public detail::multi_index_base_type<
111 Value,IndexSpecifierList,Allocator>::type
113 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
114 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
115 /* The "ISO C++ Template Parser" option in CW8.3 has a problem with the
116 * lifetime of const references bound to temporaries --precisely what
120 #pragma parse_mfunc_templ off
124 BOOST_COPYABLE_AND_MOVABLE(multi_index_container)
126 #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
127 template <typename,typename,typename> friend class detail::index_base;
128 template <typename,typename> friend struct detail::header_holder;
129 template <typename,typename> friend struct detail::converter;
132 typedef typename detail::multi_index_base_type<
133 Value,IndexSpecifierList,Allocator>::type super;
134 typedef typename detail::rebind_alloc_for<
136 typename super::node_type
137 >::type node_allocator;
138 typedef detail::allocator_traits<node_allocator> node_alloc_traits;
139 typedef typename node_alloc_traits::pointer node_pointer;
140 typedef ::boost::base_from_member<
141 node_allocator> bfm_allocator;
142 typedef detail::header_holder<
144 multi_index_container> bfm_header;
147 /* All types are inherited from super, a few are explicitly
148 * brought forward here to save us some typename's.
151 typedef typename super::ctor_args_list ctor_args_list;
152 typedef IndexSpecifierList index_specifier_type_list;
154 typedef typename super::index_type_list index_type_list;
156 typedef typename super::iterator_type_list iterator_type_list;
157 typedef typename super::const_iterator_type_list const_iterator_type_list;
158 typedef typename super::value_type value_type;
159 typedef typename super::final_allocator_type allocator_type;
160 typedef typename super::size_type size_type;
161 typedef typename super::iterator iterator;
162 typedef typename super::const_iterator const_iterator;
165 detail::no_duplicate_tags_in_index_list<index_type_list>::value);
167 /* global project() needs to see this publicly */
169 typedef typename super::node_type node_type;
171 /* construct/copy/destroy */
173 multi_index_container():
174 bfm_allocator(allocator_type()),
175 super(ctor_args_list(),bfm_allocator::member),
178 BOOST_MULTI_INDEX_CHECK_INVARIANT;
181 explicit multi_index_container(
182 const ctor_args_list& args_list,
184 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
185 /* VisualAge seems to have an ETI issue with the default value for
189 const allocator_type& al=
190 typename mpl::identity<multi_index_container>::type::
193 const allocator_type& al=allocator_type()):
197 super(args_list,bfm_allocator::member),
200 BOOST_MULTI_INDEX_CHECK_INVARIANT;
203 explicit multi_index_container(const allocator_type& al):
205 super(ctor_args_list(),bfm_allocator::member),
208 BOOST_MULTI_INDEX_CHECK_INVARIANT;
211 template<typename InputIterator>
212 multi_index_container(
213 InputIterator first,InputIterator last,
215 #if BOOST_WORKAROUND(__IBMCPP__,<=600)
216 /* VisualAge seems to have an ETI issue with the default values
217 * for arguments args_list and al.
220 const ctor_args_list& args_list=
221 typename mpl::identity<multi_index_container>::type::
223 const allocator_type& al=
224 typename mpl::identity<multi_index_container>::type::
227 const ctor_args_list& args_list=ctor_args_list(),
228 const allocator_type& al=allocator_type()):
232 super(args_list,bfm_allocator::member),
235 BOOST_MULTI_INDEX_CHECK_INVARIANT;
237 iterator hint=super::end();
238 for(;first!=last;++first){
239 hint=super::make_iterator(
240 insert_ref_(*first,hint.get_node()).first);
251 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
252 multi_index_container(
253 std::initializer_list<Value> list,
254 const ctor_args_list& args_list=ctor_args_list(),
255 const allocator_type& al=allocator_type()):
257 super(args_list,bfm_allocator::member),
260 BOOST_MULTI_INDEX_CHECK_INVARIANT;
262 typedef const Value* init_iterator;
264 iterator hint=super::end();
265 for(init_iterator first=list.begin(),last=list.end();
266 first!=last;++first){
267 hint=super::make_iterator(insert_(*first,hint.get_node()).first);
279 multi_index_container(
280 const multi_index_container<Value,IndexSpecifierList,Allocator>& x):
282 node_alloc_traits::select_on_container_copy_construction(
283 x.bfm_allocator::member)),
288 copy_construct_from(x);
291 multi_index_container(BOOST_RV_REF(multi_index_container) x):
292 bfm_allocator(boost::move(x.bfm_allocator::member)),
294 super(x,detail::do_not_copy_elements_tag()),
297 BOOST_MULTI_INDEX_CHECK_INVARIANT;
298 BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x);
302 multi_index_container(
303 const multi_index_container<Value,IndexSpecifierList,Allocator>& x,
304 const allocator_type& al):
310 copy_construct_from(x);
313 multi_index_container(
314 BOOST_RV_REF(multi_index_container) x,const allocator_type& al):
317 super(x,detail::do_not_copy_elements_tag()),
320 BOOST_MULTI_INDEX_CHECK_INVARIANT;
321 BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x);
323 if(al==x.get_allocator()){
327 multi_index_container y(x,al,detail::unequal_alloc_move_ctor_tag());
332 ~multi_index_container()
337 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
338 /* As per http://www.boost.org/doc/html/move/emulation_limitations.html
339 * #move.emulation_limitations.assignment_operator
342 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
343 const multi_index_container<Value,IndexSpecifierList,Allocator>& x)
345 multi_index_container y(
347 node_alloc_traits::propagate_on_container_copy_assignment::value?
348 x.get_allocator():this->get_allocator());
349 swap_(y,boost::true_type() /* swap_allocators */);
354 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
355 BOOST_COPY_ASSIGN_REF(multi_index_container) x)
357 multi_index_container y(
359 node_alloc_traits::propagate_on_container_copy_assignment::value?
360 x.get_allocator():this->get_allocator());
361 swap_(y,boost::true_type() /* swap_allocators */);
365 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
366 BOOST_RV_REF(multi_index_container) x)
368 #if !defined(BOOST_NO_CXX17_IF_CONSTEXPR)
369 #define BOOST_MULTI_INDEX_IF_CONSTEXPR if constexpr
371 #define BOOST_MULTI_INDEX_IF_CONSTEXPR if
372 #if defined(BOOST_MSVC)
373 #pragma warning(push)
374 #pragma warning(disable:4127) /* conditional expression is constant */
378 BOOST_MULTI_INDEX_IF_CONSTEXPR(
379 node_alloc_traits::propagate_on_container_move_assignment::value){
380 swap_(x,boost::true_type() /* swap_allocators */);
382 else if(this->get_allocator()==x.get_allocator()){
383 swap_(x,boost::false_type() /* swap_allocators */);
386 multi_index_container y(boost::move(x),this->get_allocator());
387 swap_(y,boost::false_type() /* swap_allocators */);
391 #undef BOOST_MULTI_INDEX_IF_CONSTEXPR
392 #if defined(BOOST_NO_CXX17_IF_CONSTEXPR)&&defined(BOOST_MSVC)
393 #pragma warning(pop) /* C4127 */
397 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
398 multi_index_container<Value,IndexSpecifierList,Allocator>& operator=(
399 std::initializer_list<Value> list)
401 BOOST_MULTI_INDEX_CHECK_INVARIANT;
402 typedef const Value* init_iterator;
404 multi_index_container x(*this,detail::do_not_copy_elements_tag());
405 iterator hint=x.end();
406 for(init_iterator first=list.begin(),last=list.end();
407 first!=last;++first){
408 hint=x.make_iterator(x.insert_(*first,hint.get_node()).first);
411 x.swap_elements_(*this);
416 allocator_type get_allocator()const BOOST_NOEXCEPT
418 return allocator_type(bfm_allocator::member);
421 /* retrieval of indices by number */
423 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
427 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
428 typedef typename mpl::at_c<index_type_list,N>::type type;
432 typename nth_index<N>::type& get()BOOST_NOEXCEPT
434 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
439 const typename nth_index<N>::type& get()const BOOST_NOEXCEPT
441 BOOST_STATIC_ASSERT(N>=0&&N<mpl::size<index_type_list>::type::value);
446 /* retrieval of indices by tag */
448 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
449 template<typename Tag>
452 typedef typename mpl::find_if<
457 BOOST_STATIC_CONSTANT(
458 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
459 BOOST_STATIC_ASSERT(index_found);
461 typedef typename mpl::deref<iter>::type type;
464 template<typename Tag>
465 typename index<Tag>::type& get()BOOST_NOEXCEPT
470 template<typename Tag>
471 const typename index<Tag>::type& get()const BOOST_NOEXCEPT
477 /* projection of iterators by number */
479 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
481 struct nth_index_iterator
483 typedef typename nth_index<N>::type::iterator type;
487 struct nth_index_const_iterator
489 typedef typename nth_index<N>::type::const_iterator type;
492 template<int N,typename IteratorType>
493 typename nth_index_iterator<N>::type project(IteratorType it)
495 typedef typename nth_index<N>::type index_type;
497 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
499 (mpl::contains<iterator_type_list,IteratorType>::value));
502 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
503 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
504 it,static_cast<typename IteratorType::container_type&>(*this));
506 return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
509 template<int N,typename IteratorType>
510 typename nth_index_const_iterator<N>::type project(IteratorType it)const
512 typedef typename nth_index<N>::type index_type;
514 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
515 BOOST_STATIC_ASSERT((
516 mpl::contains<iterator_type_list,IteratorType>::value||
517 mpl::contains<const_iterator_type_list,IteratorType>::value));
520 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
521 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
522 it,static_cast<const typename IteratorType::container_type&>(*this));
523 return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
527 /* projection of iterators by tag */
529 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
530 template<typename Tag>
531 struct index_iterator
533 typedef typename index<Tag>::type::iterator type;
536 template<typename Tag>
537 struct index_const_iterator
539 typedef typename index<Tag>::type::const_iterator type;
542 template<typename Tag,typename IteratorType>
543 typename index_iterator<Tag>::type project(IteratorType it)
545 typedef typename index<Tag>::type index_type;
547 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
549 (mpl::contains<iterator_type_list,IteratorType>::value));
552 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
553 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
554 it,static_cast<typename IteratorType::container_type&>(*this));
555 return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
558 template<typename Tag,typename IteratorType>
559 typename index_const_iterator<Tag>::type project(IteratorType it)const
561 typedef typename index<Tag>::type index_type;
563 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* fails in Sun C++ 5.7 */
564 BOOST_STATIC_ASSERT((
565 mpl::contains<iterator_type_list,IteratorType>::value||
566 mpl::contains<const_iterator_type_list,IteratorType>::value));
569 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
570 BOOST_MULTI_INDEX_CHECK_IS_OWNER(
571 it,static_cast<const typename IteratorType::container_type&>(*this));
572 return index_type::make_iterator(static_cast<node_type*>(it.get_node()));
576 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
577 typedef typename super::copy_map_type copy_map_type;
579 multi_index_container(
580 multi_index_container<Value,IndexSpecifierList,Allocator>& x,
581 const allocator_type& al,
582 detail::unequal_alloc_move_ctor_tag):
588 BOOST_MULTI_INDEX_CHECK_INVARIANT_OF(x);
590 copy_map_type map(bfm_allocator::member,x.size(),x.header(),header());
591 for(const_iterator it=x.begin(),it_end=x.end();it!=it_end;++it){
592 map.move_clone(it.get_node());
605 /* Not until this point are the indices required to be consistent,
606 * hence the position of the invariant checker.
609 BOOST_MULTI_INDEX_CHECK_INVARIANT;
612 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
613 multi_index_container(
614 const multi_index_container<Value,IndexSpecifierList,Allocator>& x,
615 detail::do_not_copy_elements_tag):
616 bfm_allocator(x.bfm_allocator::member),
618 super(x,detail::do_not_copy_elements_tag()),
621 BOOST_MULTI_INDEX_CHECK_INVARIANT;
625 void copy_construct_from(
626 const multi_index_container<Value,IndexSpecifierList,Allocator>& x)
628 copy_map_type map(bfm_allocator::member,x.size(),x.header(),header());
629 for(const_iterator it=x.begin(),it_end=x.end();it!=it_end;++it){
630 map.copy_clone(it.get_node());
636 /* Not until this point are the indices required to be consistent,
637 * hence the position of the invariant checker.
640 BOOST_MULTI_INDEX_CHECK_INVARIANT;
643 node_type* header()const
645 return &*bfm_header::member;
648 node_type* allocate_node()
650 return &*node_alloc_traits::allocate(bfm_allocator::member,1);
653 void deallocate_node(node_type* x)
655 node_alloc_traits::deallocate(
656 bfm_allocator::member,static_cast<node_pointer>(x),1);
659 void construct_value(node_type* x,const Value& v)
661 node_alloc_traits::construct(
662 bfm_allocator::member,boost::addressof(x->value()),v);
665 void construct_value(node_type* x,BOOST_RV_REF(Value) v)
667 node_alloc_traits::construct(
668 bfm_allocator::member,boost::addressof(x->value()),boost::move(v));
671 BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
672 void,construct_value,vartempl_construct_value_impl,node_type*,x)
674 void destroy_value(node_type* x)
676 node_alloc_traits::destroy(
677 bfm_allocator::member,boost::addressof(x->value()));
682 return node_count==0;
685 size_type size_()const
690 size_type max_size_()const
692 return static_cast<size_type>(-1);
695 template<typename Variant>
696 std::pair<node_type*,bool> insert_(const Value& v,Variant variant)
699 node_type* res=super::insert_(v,x,variant);
702 return std::pair<node_type*,bool>(res,true);
705 return std::pair<node_type*,bool>(res,false);
709 std::pair<node_type*,bool> insert_(const Value& v)
711 return insert_(v,detail::lvalue_tag());
714 std::pair<node_type*,bool> insert_rv_(const Value& v)
716 return insert_(v,detail::rvalue_tag());
720 std::pair<node_type*,bool> insert_ref_(T& t)
722 node_type* x=allocate_node();
724 construct_value(x,t);
726 node_type* res=super::insert_(x->value(),x,detail::emplaced_tag());
729 return std::pair<node_type*,bool>(res,true);
734 return std::pair<node_type*,bool>(res,false);
750 std::pair<node_type*,bool> insert_ref_(const value_type& x)
755 std::pair<node_type*,bool> insert_ref_(value_type& x)
760 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
761 std::pair<node_type*,bool> emplace_(
762 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
764 node_type* x=allocate_node();
766 construct_value(x,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
768 node_type* res=super::insert_(x->value(),x,detail::emplaced_tag());
771 return std::pair<node_type*,bool>(res,true);
776 return std::pair<node_type*,bool>(res,false);
792 template<typename Variant>
793 std::pair<node_type*,bool> insert_(
794 const Value& v,node_type* position,Variant variant)
797 node_type* res=super::insert_(v,position,x,variant);
800 return std::pair<node_type*,bool>(res,true);
803 return std::pair<node_type*,bool>(res,false);
807 std::pair<node_type*,bool> insert_(const Value& v,node_type* position)
809 return insert_(v,position,detail::lvalue_tag());
812 std::pair<node_type*,bool> insert_rv_(const Value& v,node_type* position)
814 return insert_(v,position,detail::rvalue_tag());
818 std::pair<node_type*,bool> insert_ref_(
819 T& t,node_type* position)
821 node_type* x=allocate_node();
823 construct_value(x,t);
825 node_type* res=super::insert_(
826 x->value(),position,x,detail::emplaced_tag());
829 return std::pair<node_type*,bool>(res,true);
834 return std::pair<node_type*,bool>(res,false);
850 std::pair<node_type*,bool> insert_ref_(
851 const value_type& x,node_type* position)
853 return insert_(x,position);
856 std::pair<node_type*,bool> insert_ref_(
857 value_type& x,node_type* position)
859 return insert_(x,position);
862 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
863 std::pair<node_type*,bool> emplace_hint_(
865 BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
867 node_type* x=allocate_node();
869 construct_value(x,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
871 node_type* res=super::insert_(
872 x->value(),position,x,detail::emplaced_tag());
875 return std::pair<node_type*,bool>(res,true);
880 return std::pair<node_type*,bool>(res,false);
896 void erase_(node_type* x)
903 void delete_node_(node_type* x)
905 super::delete_node_(x);
909 void delete_all_nodes_()
911 super::delete_all_nodes_();
921 void swap_(multi_index_container<Value,IndexSpecifierList,Allocator>& x)
925 boost::integral_constant<
926 bool,node_alloc_traits::propagate_on_container_swap::value>());
930 multi_index_container<Value,IndexSpecifierList,Allocator>& x,
931 boost::true_type swap_allocators)
933 detail::adl_swap(bfm_allocator::member,x.bfm_allocator::member);
934 std::swap(bfm_header::member,x.bfm_header::member);
935 super::swap_(x,swap_allocators);
936 std::swap(node_count,x.node_count);
940 multi_index_container<Value,IndexSpecifierList,Allocator>& x,
941 boost::false_type swap_allocators)
943 std::swap(bfm_header::member,x.bfm_header::member);
944 super::swap_(x,swap_allocators);
945 std::swap(node_count,x.node_count);
949 multi_index_container<Value,IndexSpecifierList,Allocator>& x)
951 std::swap(bfm_header::member,x.bfm_header::member);
952 super::swap_elements_(x);
953 std::swap(node_count,x.node_count);
956 bool replace_(const Value& k,node_type* x)
958 return super::replace_(k,x,detail::lvalue_tag());
961 bool replace_rv_(const Value& k,node_type* x)
963 return super::replace_(k,x,detail::rvalue_tag());
966 template<typename Modifier>
967 bool modify_(Modifier& mod,node_type* x)
970 mod(const_cast<value_type&>(x->value()));
979 if(!super::modify_(x)){
994 template<typename Modifier,typename Rollback>
995 bool modify_(Modifier& mod,Rollback& back_,node_type* x)
998 mod(const_cast<value_type&>(x->value()));
1008 b=super::modify_rollback_(x);
1012 back_(const_cast<value_type&>(x->value()));
1013 if(!super::check_rollback_(x))this->erase_(x);
1026 back_(const_cast<value_type&>(x->value()));
1027 if(!super::check_rollback_(x))this->erase_(x);
1039 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
1042 friend class boost::serialization::access;
1044 BOOST_SERIALIZATION_SPLIT_MEMBER()
1046 typedef typename super::index_saver_type index_saver_type;
1047 typedef typename super::index_loader_type index_loader_type;
1049 template<class Archive>
1050 void save(Archive& ar,const unsigned int version)const
1052 const serialization::collection_size_type s(size_());
1053 const detail::serialization_version<value_type> value_version;
1054 ar<<serialization::make_nvp("count",s);
1055 ar<<serialization::make_nvp("value_version",value_version);
1057 index_saver_type sm(bfm_allocator::member,s);
1059 for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){
1060 serialization::save_construct_data_adl(
1061 ar,boost::addressof(*it),value_version);
1062 ar<<serialization::make_nvp("item",*it);
1063 sm.add(it.get_node(),ar,version);
1065 sm.add_track(header(),ar,version);
1067 super::save_(ar,version,sm);
1070 template<class Archive>
1071 void load(Archive& ar,const unsigned int version)
1073 BOOST_MULTI_INDEX_CHECK_INVARIANT;
1076 serialization::collection_size_type s;
1077 detail::serialization_version<value_type> value_version;
1080 ar>>serialization::make_nvp("count",sz);
1081 s=static_cast<serialization::collection_size_type>(sz);
1084 ar>>serialization::make_nvp("count",s);
1090 ar>>serialization::make_nvp("value_version",value_version);
1093 index_loader_type lm(bfm_allocator::member,s);
1095 for(std::size_t n=0;n<s;++n){
1096 detail::archive_constructed<Value> value("item",ar,value_version);
1097 std::pair<node_type*,bool> p=insert_rv_(
1098 value.get(),super::end().get_node());
1099 if(!p.second)throw_exception(
1100 archive::archive_exception(
1101 archive::archive_exception::other_exception));
1102 ar.reset_object_address(
1103 boost::addressof(p.first->value()),boost::addressof(value.get()));
1104 lm.add(p.first,ar,version);
1106 lm.add_track(header(),ar,version);
1108 super::load_(ar,version,lm);
1112 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)
1113 /* invariant stuff */
1115 bool invariant_()const
1117 return super::invariant_();
1120 void check_invariant_()const
1122 BOOST_MULTI_INDEX_INVARIANT_ASSERT(invariant_());
1127 template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
1128 void vartempl_construct_value_impl(
1129 node_type* x,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
1131 node_alloc_traits::construct(
1132 bfm_allocator::member,boost::addressof(x->value()),
1133 BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
1136 size_type node_count;
1138 #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\
1139 BOOST_WORKAROUND(__MWERKS__,<=0x3003)
1140 #pragma parse_mfunc_templ reset
1144 #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
1145 #pragma warning(pop) /* C4522 */
1148 /* retrieval of indices by number */
1150 template<typename MultiIndexContainer,int N>
1153 BOOST_STATIC_CONSTANT(
1155 M=mpl::size<typename MultiIndexContainer::index_type_list>::type::value);
1156 BOOST_STATIC_ASSERT(N>=0&&N<M);
1157 typedef typename mpl::at_c<
1158 typename MultiIndexContainer::index_type_list,N>::type type;
1161 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
1163 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
1165 multi_index_container<Value,IndexSpecifierList,Allocator>& m)BOOST_NOEXCEPT
1167 typedef multi_index_container<
1168 Value,IndexSpecifierList,Allocator> multi_index_type;
1169 typedef typename nth_index<
1170 multi_index_container<
1171 Value,IndexSpecifierList,Allocator>,
1175 BOOST_STATIC_ASSERT(N>=0&&
1178 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
1181 return detail::converter<multi_index_type,index_type>::index(m);
1184 template<int N,typename Value,typename IndexSpecifierList,typename Allocator>
1185 const typename nth_index<
1186 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&
1188 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
1191 typedef multi_index_container<
1192 Value,IndexSpecifierList,Allocator> multi_index_type;
1193 typedef typename nth_index<
1194 multi_index_container<
1195 Value,IndexSpecifierList,Allocator>,
1199 BOOST_STATIC_ASSERT(N>=0&&
1202 BOOST_DEDUCED_TYPENAME multi_index_type::index_type_list
1205 return detail::converter<multi_index_type,index_type>::index(m);
1208 /* retrieval of indices by tag */
1210 template<typename MultiIndexContainer,typename Tag>
1213 typedef typename MultiIndexContainer::index_type_list index_type_list;
1215 typedef typename mpl::find_if<
1217 detail::has_tag<Tag>
1220 BOOST_STATIC_CONSTANT(
1221 bool,index_found=!(is_same<iter,typename mpl::end<index_type_list>::type >::value));
1222 BOOST_STATIC_ASSERT(index_found);
1224 typedef typename mpl::deref<iter>::type type;
1228 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
1230 typename ::boost::multi_index::index<
1231 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
1233 multi_index_container<Value,IndexSpecifierList,Allocator>& m)BOOST_NOEXCEPT
1235 typedef multi_index_container<
1236 Value,IndexSpecifierList,Allocator> multi_index_type;
1237 typedef typename ::boost::multi_index::index<
1238 multi_index_container<
1239 Value,IndexSpecifierList,Allocator>,
1243 return detail::converter<multi_index_type,index_type>::index(m);
1247 typename Tag,typename Value,typename IndexSpecifierList,typename Allocator
1249 const typename ::boost::multi_index::index<
1250 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&
1252 const multi_index_container<Value,IndexSpecifierList,Allocator>& m
1255 typedef multi_index_container<
1256 Value,IndexSpecifierList,Allocator> multi_index_type;
1257 typedef typename ::boost::multi_index::index<
1258 multi_index_container<
1259 Value,IndexSpecifierList,Allocator>,
1263 return detail::converter<multi_index_type,index_type>::index(m);
1266 /* projection of iterators by number */
1268 template<typename MultiIndexContainer,int N>
1269 struct nth_index_iterator
1271 typedef typename nth_index<MultiIndexContainer,N>::type::iterator type;
1274 template<typename MultiIndexContainer,int N>
1275 struct nth_index_const_iterator
1277 typedef typename nth_index<MultiIndexContainer,N>::type::const_iterator type;
1281 int N,typename IteratorType,
1282 typename Value,typename IndexSpecifierList,typename Allocator>
1283 typename nth_index_iterator<
1284 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
1286 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
1289 typedef multi_index_container<
1290 Value,IndexSpecifierList,Allocator> multi_index_type;
1291 typedef typename nth_index<multi_index_type,N>::type index_type;
1293 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
1294 BOOST_STATIC_ASSERT((
1296 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
1297 IteratorType>::value));
1300 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
1302 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
1303 typedef detail::converter<
1305 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
1306 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
1309 return detail::converter<multi_index_type,index_type>::iterator(
1310 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
1314 int N,typename IteratorType,
1315 typename Value,typename IndexSpecifierList,typename Allocator>
1316 typename nth_index_const_iterator<
1317 multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type
1319 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
1322 typedef multi_index_container<
1323 Value,IndexSpecifierList,Allocator> multi_index_type;
1324 typedef typename nth_index<multi_index_type,N>::type index_type;
1326 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
1327 BOOST_STATIC_ASSERT((
1329 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
1330 IteratorType>::value||
1332 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
1333 IteratorType>::value));
1336 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
1338 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
1339 typedef detail::converter<
1341 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
1342 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
1345 return detail::converter<multi_index_type,index_type>::const_iterator(
1346 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
1349 /* projection of iterators by tag */
1351 template<typename MultiIndexContainer,typename Tag>
1352 struct index_iterator
1354 typedef typename ::boost::multi_index::index<
1355 MultiIndexContainer,Tag>::type::iterator type;
1358 template<typename MultiIndexContainer,typename Tag>
1359 struct index_const_iterator
1361 typedef typename ::boost::multi_index::index<
1362 MultiIndexContainer,Tag>::type::const_iterator type;
1366 typename Tag,typename IteratorType,
1367 typename Value,typename IndexSpecifierList,typename Allocator>
1368 typename index_iterator<
1369 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
1371 multi_index_container<Value,IndexSpecifierList,Allocator>& m,
1374 typedef multi_index_container<
1375 Value,IndexSpecifierList,Allocator> multi_index_type;
1376 typedef typename ::boost::multi_index::index<
1377 multi_index_type,Tag>::type index_type;
1379 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
1380 BOOST_STATIC_ASSERT((
1382 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
1383 IteratorType>::value));
1386 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
1388 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
1389 typedef detail::converter<
1391 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
1392 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
1395 return detail::converter<multi_index_type,index_type>::iterator(
1396 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
1400 typename Tag,typename IteratorType,
1401 typename Value,typename IndexSpecifierList,typename Allocator>
1402 typename index_const_iterator<
1403 multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type
1405 const multi_index_container<Value,IndexSpecifierList,Allocator>& m,
1408 typedef multi_index_container<
1409 Value,IndexSpecifierList,Allocator> multi_index_type;
1410 typedef typename ::boost::multi_index::index<
1411 multi_index_type,Tag>::type index_type;
1413 #if !defined(__SUNPRO_CC)||!(__SUNPRO_CC<0x580) /* Sun C++ 5.7 fails */
1414 BOOST_STATIC_ASSERT((
1416 BOOST_DEDUCED_TYPENAME multi_index_type::iterator_type_list,
1417 IteratorType>::value||
1419 BOOST_DEDUCED_TYPENAME multi_index_type::const_iterator_type_list,
1420 IteratorType>::value));
1423 BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(it);
1425 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
1426 typedef detail::converter<
1428 BOOST_DEDUCED_TYPENAME IteratorType::container_type> converter;
1429 BOOST_MULTI_INDEX_CHECK_IS_OWNER(it,converter::index(m));
1432 return detail::converter<multi_index_type,index_type>::const_iterator(
1433 m,static_cast<typename multi_index_type::node_type*>(it.get_node()));
1436 /* Comparison. Simple forward to first index. */
1439 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1440 typename Value2,typename IndexSpecifierList2,typename Allocator2
1443 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1444 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1446 return get<0>(x)==get<0>(y);
1450 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1451 typename Value2,typename IndexSpecifierList2,typename Allocator2
1454 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1455 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1457 return get<0>(x)<get<0>(y);
1461 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1462 typename Value2,typename IndexSpecifierList2,typename Allocator2
1465 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1466 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1468 return get<0>(x)!=get<0>(y);
1472 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1473 typename Value2,typename IndexSpecifierList2,typename Allocator2
1476 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1477 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1479 return get<0>(x)>get<0>(y);
1483 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1484 typename Value2,typename IndexSpecifierList2,typename Allocator2
1487 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1488 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1490 return get<0>(x)>=get<0>(y);
1494 typename Value1,typename IndexSpecifierList1,typename Allocator1,
1495 typename Value2,typename IndexSpecifierList2,typename Allocator2
1498 const multi_index_container<Value1,IndexSpecifierList1,Allocator1>& x,
1499 const multi_index_container<Value2,IndexSpecifierList2,Allocator2>& y)
1501 return get<0>(x)<=get<0>(y);
1504 /* specialized algorithms */
1506 template<typename Value,typename IndexSpecifierList,typename Allocator>
1508 multi_index_container<Value,IndexSpecifierList,Allocator>& x,
1509 multi_index_container<Value,IndexSpecifierList,Allocator>& y)
1514 } /* namespace multi_index */
1516 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
1517 /* class version = 1 : we now serialize the size through
1518 * boost::serialization::collection_size_type.
1519 * class version = 2 : proper use of {save|load}_construct_data.
1522 namespace serialization {
1523 template<typename Value,typename IndexSpecifierList,typename Allocator>
1525 boost::multi_index_container<Value,IndexSpecifierList,Allocator>
1528 BOOST_STATIC_CONSTANT(int,value=2);
1530 } /* namespace serialization */
1533 /* Associated global functions are promoted to namespace boost, except
1534 * comparison operators and swap, which are meant to be Koenig looked-up.
1537 using multi_index::get;
1538 using multi_index::project;
1540 } /* namespace boost */
1542 #undef BOOST_MULTI_INDEX_CHECK_INVARIANT
1543 #undef BOOST_MULTI_INDEX_CHECK_INVARIANT_OF