#include<initializer_list>namespaceboost{namespacemulti_index{template<typenameValue,typenameIndexSpecifierList,typenameAllocator>classmulti_index_container;// multi_index_container associated global class templates:template<typenameMultiIndexContainer,intN>structnth_index;template<typenameMultiIndexContainer,typenameTag>structindex;template<typenameMultiIndexContainer,intN>structnth_index_iterator;// deprecatedtemplate<typenameMultiIndexContainer,intN>structnth_index_const_iterator;// deprecatedtemplate<typenameMultiIndexContainer,typenameTag>structindex_iterator;// deprecatedtemplate<typenameMultiIndexContainer,typenameTag>structindex_const_iterator;// deprecated// multi_index_container global functions for index retrieval:template<intN,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenamenth_index<multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&get(multi_index_container<Value,IndexSpecifierList,Allocator>&m)noexcept;template<intN,typenameValue,typenameIndexSpecifierList,typenameAllocator>consttypenamenth_index<multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&get(constmulti_index_container<Value,IndexSpecifierList,Allocator>&m)noexcept;template<typenameTag,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenameindex<multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&get(multi_index_container<Value,IndexSpecifierList,Allocator>&m)noexcept;template<typenameTag,typenameValue,typenameIndexSpecifierList,typenameAllocator>consttypenameindex<multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&get(constmulti_index_container<Value,IndexSpecifierList,Allocator>&m)noexcept;// multi_index_container global functions for projection of iterators:template<intN,typenameIteratorType,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenamenth_index<multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type::iteratorproject(multi_index_container<Value,IndexSpecifierList,Allocator>&m,IteratorTypeit);template<intN,typenameIteratorType,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenamenth_index<multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type::const_iteratorproject(constmulti_index_container<Value,IndexSpecifierList,Allocator>&m,IteratorTypeit);template<typenameTag,typenameIteratorType,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenameindex<multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type::iteratorproject(multi_index_container<Value,IndexSpecifierList,Allocator>&m,IteratorTypeit);template<typenameTag,typenameIteratorType,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenameindex<multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type::const_iteratorproject(constmulti_index_container<Value,IndexSpecifierList,Allocator>&m,IteratorTypeit);// comparison:// OP is any of ==,<,!=,>,>=,<=template<typenameValue1,typenameIndexSpecifierList1,typenameAllocator1,typenameValue2,typenameIndexSpecifierList2,typenameAllocator2>booloperatorOP(constmulti_index_container<Value1,IndexSpecifierList1,Allocator1>&x,constmulti_index_container<Value2,IndexSpecifierList2,Allocator2>&y);// specialized algorithms:template<typenameValue,typenameIndexSpecifierList,typenameAllocator>voidswap(multi_index_container<Value,IndexSpecifierList,Allocator>&x,multi_index_container<Value,IndexSpecifierList,Allocator>&y);}// namespace boost::multi_indexusingmulti_index::multi_index_container;usingmulti_index::get;usingmulti_index::project;}// namespace boost
Это основной компонент Boost. MultiIndex.<multi_index_container>представляет собой шаблон класса контейнеров, содержащий определенный пользователем списокиндексов. Эти индексы обеспечивают различные интерфейсы для управления элементами<multi_index_container>. Сама по себе<multi_index_container>обеспечивает только базовую функциональность для строительства и для доступа к удерживаемым индексам.
Тип<multi_index_container>инстанциируется с типом содержащихся элементов и непустым<MPL Forward Sequence>, определяющим, какие индексы соответствуют классу.
Для удобства использования все публичные методы и виды указанного первого индекса наследуются по<multi_index_container>. Сюда же относятся глобальные операторы и функции, связанные с индексом (vg. comparison и<swap>).
template<typenameValue,typenameIndexSpecifierList=indexed_by<ordered_unique<identity<Value>>>,typenameAllocator=std::allocator<Value>>classmulti_index_container{public:// types:typedefimplementation definedctor_args_list;typedefimplementation definedindex_specifier_type_list;typedefimplementation definedindex_type_list;typedefimplementation definediterator_type_list;typedefimplementation definedconst_iterator_type_list;typedefAllocatorallocator_type;// nested class templates:template<intN>structnth_index{typedefimplementation definedtype;};template<typenameTag>structindex{typedefimplementation definedtype;};template<intN>structnth_index_iterator// deprecated{typedefimplementationdefinedtype;};template<intN>structnth_index_const_iterator// deprecated{typedefimplementationdefinedtype;};template<typenameTag>structindex_iterator// deprecated{typedefimplementationdefinedtype;};template<typenameTag>structindex_const_iterator// deprecated{typedefimplementationdefinedtype;};// construct/copy/destroy:explicitmulti_index_container(
constctor_args_list&args_list=ctor_args_list(),
constallocator_type&al=allocator_type());explicitmulti_index_container(constallocator_type&al);template<typenameInputIterator>multi_index_container(InputIteratorfirst,InputIteratorlast,constctor_args_list&args_list=ctor_args_list(),
constallocator_type&al=allocator_type());multi_index_container(std::initializer_list<Value>list,constctor_args_list&args_list=ctor_args_list(),constallocator_type&al=allocator_type());multi_index_container(constmulti_index_container<Value,IndexSpecifierList,Allocator>&x);multi_index_container(multi_index_container<Value,IndexSpecifierList,Allocator>&&x);~multi_index_container();multi_index_container<Value,IndexSpecifierList,Allocator>&operator=(constmulti_index_container<Value,IndexSpecifierList,Allocator>&x);multi_index_container<Value,IndexSpecifierList,Allocator>&operator=(multi_index_container<Value,IndexSpecifierList,Allocator>&&x);multi_index_container<Value,IndexSpecifierList,Allocator>&operator=(std::initializer_list<Value>list)allocator_typeget_allocator()constnoexcept;// retrieval of indicestemplate<intN>typenamenth_index<N>::type&get()noexcept;template<intN>consttypenamenth_index<N>::type&get()constnoexcept;template<typenameTag>typenameindex<Tag>::type&get()noexcept;template<typenameTag>consttypenameindex<Tag>::type&get()constnoexcept;// projection of iteratorstemplate<intN,typenameIteratorType>typenamenth_index<N>::type::iteratorproject(IteratorTypeit);template<intN,typenameIteratorType>typenamenth_index<N>::type::const_iteratorproject(IteratorTypeit)const;template<typenameTag,typenameIteratorType>typenameindex<Tag>::type::iteratorproject(IteratorTypeit);template<typenameTag,typenameIteratorType>typenameindex<Tag>::type::const_iteratorproject(IteratorTypeit)const;};// multi_index_container associated global class templates:template<typenameMultiIndexContainer,intN>structnth_index{typedeftypenameMultiIndexContainer::nth_index<N>::typetype;};template<typenameMultiIndexContainer,typenameTag>structindex{typedeftypenameMultiIndexContainer::index<Tag>::typetype;};template<typenameMultiIndexContainer,intN>structnth_index_iterator// deprecated{typedeftypenameMultiIndexContainer::nth_index_iterator<N>::typetype;};template<typenameMultiIndexContainer,intN>structnth_index_const_iterator// deprecated{typedeftypenameMultiIndexContainer::nth_index_const_iterator<N>::typetype;};template<typenameMultiIndexContainer,typenameTag>structindex_iterator// deprecated{typedeftypenameMultiIndexContainer::index_iterator<Tag>::typetype;};template<typenameMultiIndexContainer,typenameTag>structindex_const_iterator// deprecated{typedeftypenameMultiIndexContainer::index_const_iterator<Tag>::typetype;};// multi_index_container global functions for index retrieval:template<intN,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenamenth_index<multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&get(multi_index_container<Value,IndexSpecifierList,Allocator>&m)noexcept{returnm.get<N>();}template<intN,typenameValue,typenameIndexSpecifierList,typenameAllocator>consttypenamenth_index<multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type&get(constmulti_index_container<Value,IndexSpecifierList,Allocator>&m)noexcept{returnm.get<N>();}template<typenameTag,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenameindex<multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&get(multi_index_container<Value,IndexSpecifierList,Allocator>&m)noexcept{returnm.get<Tag>();}template<typenameTag,typenameValue,typenameIndexSpecifierList,typenameAllocator>consttypenameindex<multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type&get(constmulti_index_container<Value,IndexSpecifierList,Allocator>&m)noexcept{returnm.get<Tag>();}// multi_index_container global functions for projection of iterators:template<intN,typenameIteratorType,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenamenth_index<multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type::iteratorproject(multi_index_container<Value,IndexSpecifierList,Allocator>&m,IteratorTypeit){returnm.templateproject<N>(it);}template<intN,typenameIteratorType,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenamenth_index<multi_index_container<Value,IndexSpecifierList,Allocator>,N>::type::const_iteratorproject(constmulti_index_container<Value,IndexSpecifierList,Allocator>&m,IteratorTypeit){returnm.templateproject<N>(it);}template<typenameTag,typenameIteratorType,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenameindex<multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type::iteratorproject(multi_index_container<Value,IndexSpecifierList,Allocator>&m,IteratorTypeit){returnm.templateproject<Tag>(it);}template<typenameTag,typenameIteratorType,typenameValue,typenameIndexSpecifierList,typenameAllocator>typenameindex<multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type::const_iteratorproject(constmulti_index_container<Value,IndexSpecifierList,Allocator>&m,IteratorTypeit){returnm.templateproject<Tag>(it);}// comparison:// OP is any of ==,<,!=,>,>=,<=template<typenameValue1,typenameIndexSpecifierList1,typenameAllocator1,typenameValue2,typenameIndexSpecifierList2,typenameAllocator2>booloperatorOP(constmulti_index_container<Value1,IndexSpecifierList1,Allocator1>&x,constmulti_index_container<Value2,IndexSpecifierList2,Allocator2>&y){returnget<0>(x)OPget<0>(y);}// specialized algorithms:template<typenameValue,typenameIndexSpecifierList,typenameAllocator>voidswap(multi_index_container<Value,IndexSpecifierList,Allocator>&x,multi_index_container<Value,IndexSpecifierList,Allocator>&y){x.swap(y);}}// namespace boost::multi_index}// namespace boost
Индексы данной<multi_index_container>инстанциации не могут иметь дубликатовметок, ни в пределах одного индекса, ни в двух разных индексах.Value— тип элементов, содержащихся в них.Valueдолжно бытьErasableотmulti_index_container.
IndexSpecifierListуказывает индексы, из которых состоитmulti_index_container. Он должен быть непустымMPL Forward Sequence(и, предпочтительно,MPL Random Access Sequence) указателей индекса. Для синтаксического удобстваindexed_byМожно использовать последовательность MPL.
Allocatorдолжен быть распределителемValueобъектов, удовлетворяющих соответствующим требованиям C++ по[allocator.requirements]. Допускаются следующие изменения стандартных требований:
Поддерживаются экземпляры с неравным распределением: замена двух экземпляров с неравным распределением не должна приводить к каким-либо исключениям.
Для каждого типаTтипAllocator::rebind<T>::other::pointerможет быть любым типом итератора случайного доступа, при условии, что он явно конструируется из буквального0(стоящего здесь в качестве нулевого указателя) или из любогоpтипаT*, указывающего на область, выделенную некоторым экземпляромAllocatorили каким-либо другим типом распределителя, отскакивающим отAllocator.pointer, построенный изp, должен относиться к*p.
Indices of a given multi_index_container instantiation cannot have
duplicate tags, either within a single
index or in two different indices.
[ORIG_END] -->
Although the exact definition of ctor_args_list is
implementation defined, from the user point of view this type can be
treated as equivalent to
::boost::tuple<C0,...,CI-1>,
where Ci is the ctor_args type of the
i-th index held by the multi_index_container, in the
same order as they were specified. Strictly speaking, there is an
implicit conversion from
const ::boost::tuple<C0,...,CI-1>&
to const ctor_args_list&. This type is used for
providing the construction arguments of the indices of the
multi_index_container. ctor_args_list is
DefaultConstructible, provided that all ctor_args types
involved are DefaultConstructible.
Model of
MPL Random Access Sequence and
MPL Extensible Sequence containing the types of the constant
iterators of the indices held by the multi_index_container, in the same order
as they were specified.
nth_index<N>::type yields the type of the
N-th (0-based) index held by the multi_index_container, in
the same order as they were specified. Requires:0 <= N < I.
template<typename Tag> struct index
index<Tag>::type yields the type of the index which
has Tag as an associated tag type. Requires: Some index of the multi_index_container has Tag
as an associated tag type.
template<int N> struct nth_index_iterator
nth_index_iterator<N>::type is equivalent to
nth_index<N>::type::iterator. Note: The use of nth_index_iterator is deprecated.
template<int N> struct nth_index_const_iterator
nth_index_const_iterator<N>::type is equivalent to
nth_index<N>::type::const_iterator. Note: The use of nth_index_const_iterator is deprecated.
template<typename Tag> struct index_iterator
index_iterator<Tag>::type is equivalent to
index<Tag>::type::iterator. Note: The use of index_iterator is deprecated.
Requires:InputIterator is an input iterator.
Value is
EmplaceConstructible into multi_index_container
from *first.
last is reachable from first. Effects: Constructs and empty multi_index_container using the
specified argument list and allocator and fills it with
the elements in the range [first,last).
Insertion of each element may or may not succeed depending
on the acceptance by all the indices of the multi_index_container. Complexity:O(m*H(m)), where m is
the number of elements in [first,last).
Requires:Value is CopyInsertable into
multi_index_container. Effects: Constructs a copy of x, copying its
elements as well as its internal objects (those specified
in ctor_args_list and the allocator.) Postconditions:*this==x. The order on every index
of the multi_index_container is preserved as well. Complexity:O(x.size()*log(x.size()) + C(x.size())).
Effects: Constructs a multi_index_container by moving the
elements of x and copying its internal objects (those specified
in ctor_args_list and the allocator.) Postconditions: If x==y just
before the movement, *this==y. The order on every index
of the multi_index_container is preserved as well. Complexity: Constant.
~multi_index_container()
Effects: Destroys the multi_index_container and all the elements
contained. The order in which the elements are destroyed is not specified. Complexity:O(n).
Requires:Value is CopyInsertable into
multi_index_container. Effects: Replaces the elements and internal objects of the multi_index_container
with copies from x. Postconditions:*this==x. The order on every index
of the multi_index_container is preserved as well. Returns:*this. Complexity:O(n + x.size()*log(x.size()) +
C(x.size())). Exception safety: Strong, provided the copy and assignment operations
of the types of ctor_args_list do not throw.
Effects: Replaces the elements of multi_index_container
with those of x and its internal objects with copies from the
corresponding objects in x. Postconditions: If x==y just
before the movement, *this==y. The order on every index
of the multi_index_container is preserved as well. Returns:*this. Complexity:O(n). Exception safety: Strong, provided the copy and assignment operations
of the types of ctor_args_list do not throw.
Requires:Value is CopyInsertable into
multi_index_container. Effects: Replaces the elements the multi_index_container
with copies of the elements of list, inserted in the specified order.
Insertion of each element may or may not succeed depending
on the acceptance by all the indices of the multi_index_container. Returns:*this. Complexity:O(n + I(m)), where m is the
number of elements of list. Exception safety: Strong, provided the copy and assignment operations
of the types of ctor_args_list do not throw.
allocator_type get_allocator()const noexcept;
Returns a copy of the allocator_type object used to construct
the multi_index_container. Complexity: Constant.
Requires:Tag is such that index<Tag>::type
is valid. Effects: Returns a const reference to the
index<Tag>::type index held by
*this. Complexity: Constant.
Requires:0 <= N < I. IteratorType
belongs to iterator_type_list. it is a valid
iterator of some index of *this (i.e. does not refer to some
other multi_index_container.) Effects: Returns an nth_index<N>::type::iterator
equivalent to it. Complexity: Constant. Exception safety:nothrow.
Requires:0 <= N < I. IteratorType
belongs to const_iterator_type_list or
iterator_type_list. it is a
valid (constant or non-constant) iterator of some index of *this
(i.e. does not refer to some other multi_index_container.) Effects: Returns an nth_index<N>::type::const_iterator
equivalent to it. Complexity: Constant. Exception safety:nothrow.
Requires:Tag is such that
index<Tag>::type is valid. IteratorType
belongs to iterator_type_list. it is a valid
iterator of some index of *this (i.e. does not refer to some
other multi_index_container.) Effects: Returns an index<Tag>::type::iterator
equivalent to it. Complexity: Constant. Exception safety:nothrow.
Requires:Tag is such that
index<Tag>::type is valid. IteratorType
belongs to const_iterator_type_list or
iterator_type_list. it is a valid
(constant or non-constant) iterator of some index of *this
(i.e. does not refer to some other multi_index_container.) Effects: Returns an index<Tag>::type::const_iterator
iterator equivalent to it. Complexity: Constant. Exception safety:nothrow.
<multi_index_container>s может быть заархивировано / извлечено с помощьюBoost.Serialization. Повышаю. MultiIndex не раскрывает интерфейс публичной сериализации, как это предусмотрено Boost. Сама сериализация. Поддерживаются как обычные, так и XML-архивы.
Каждый из индексов, включающих данный<multi_index_container>, вносит свои собственные предварительные условия, а также гарантии на извлеченные контейнеры. При их описании используются следующие понятия. Тип<T>являетсясериализуемым(resp. XML-сериализируемым), если любой объект типа<T>может быть сохранен в выходной архив (архив XML) и позже извлечен из входного архива (архив XML), связанного с тем же хранилищем. Если<x'>типа<T>загружается из информации о сериализации, сохраненной от другого объекта<x>, мы говорим, что<x'>являетсявосстановленной копией<x>. Учитывая двоичный предикат<Pred>над<T>,<T>и объекты<p>и<q>типа<Pred>, мы говорим, что<q>являетсясериализацией-совместимойс<p>, если
<p(x,y) == q(x',y')>
для каждого<x>и<y>типа<T>и<x'>и<y'>восстанавливаются копии<x>и<y>соответственно.
Operation: saving of a multi_index_containerm to an
output archive (XML archive) ar.
Requires:Value is serializable (XML-serializable). Additionally,
each of the indices of m can impose another requirements. Exception safety: Strong with respect to m. If an exception
is thrown, ar may be left in an inconsistent state.
Operation: loading of a multi_index_containerm' from an
input archive (XML archive) ar.
Requires:Value is serializable (XML-serializable). Additionally,
each of the indices of m' can impose another requirements. Exception safety: Basic. If an exception is thrown, ar may be
left in an inconsistent state.
Статья Boost.MultiIndex Documentation - multi_index_container reference раздела Boost.MultiIndex Documentation - Reference может быть полезна для разработчиков на c++ и boost.
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.