"boost/multi_index/ordered_index_fwd.hpp"
synopsis"boost/multi_index/ordered_index.hpp"
synopsis
"boost/multi_index/ordered_index_fwd.hpp"
synopsisnamespace boost{ namespace multi_index{ // index specifiers ordered_unique and ordered_non_unique template<consult ordered_unique reference for arguments> struct ordered_unique; template<consult ordered_non_unique reference for arguments> struct ordered_non_unique; // indices namespace detail{ template<implementation defined> class index name is implementation defined; } // namespace boost::multi_index::detail } // namespace boost::multi_index } // namespace boost
ordered_index_fwd.hpp provides forward declarations for index specifiers
ordered_unique and
ordered_non_unique and
their associated ordered index classes.
"boost/multi_index/ordered_index.hpp"
synopsisnamespace boost{ namespace multi_index{ // index specifiers ordered_unique and ordered_non_unique template<consult ordered_unique reference for arguments> struct ordered_unique; template<consult ordered_non_unique reference for arguments> struct ordered_non_unique; // indices namespace detail{ template<implementation defined> class index class name implementation defined; // index comparison: // OP is any of ==,<,!=,>,>=,<= template<arg set 1,arg set 2> bool operator OP( const index class name<arg set 1>& x,const index class name<arg set 2>& y); // index specialized algorithms: template<implementation defined> void swap(index class name& x,index class name& y); } // namespace boost::multi_index::detail } // namespace boost::multi_index } // namespace boost
ordered_unique and ordered_non_unique
These index specifiers allow for insertion of ordered indices without and with allowance of duplicate elements, respectively. The syntax of ordered_unique and ordered_non_unique coincide, thus describe them in a grouped manner. ordered_unique and ordered_non_unique can be instantiated in two different forms, according to whether a tag list for the index is provided or not:
template< typename KeyFromValue, typename Compare=std::less<KeyFromValue::result_type> > struct (ordered_unique | ordered_non_unique); template< typename TagList, typename KeyFromValue, typename Compare=std::less<KeyFromValue::result_type> > struct (ordered_unique | ordered_non_unique);
If provided,
TagList must be an instantiation of the class template
tag.
The template arguments are used by the corresponding index implementation,
refer to the ordered indices reference section for further
explanations on their acceptable type values.
An ordered index provides a set-like interface to the underlying heap of
elements contained in a multi_index_container.
An ordered index is
particularized according to a given
Key Extractor
that retrieves keys from elements of multi_index_container
and a comparison
predicate.
There are two variants of ordered indices: unique, which do not allow duplicate elements (with respect to its associated comparison predicate) and non-unique, which accept those duplicates. The interface of these two variants is the same, so they are documented together, with minor differences explicitly stated when they exist.
Except where noted, ordered indices (both unique and non-unique) are models of
Sorted Associative Container and
Unique Associative Container, much as
std::sets
are. Accordingly, validity of iterators and references to elements is
preserved. Provide descriptions of those types and operations that are
either not present in the concepts modeled or do not exactly conform to the
requirements for these types of containers.
namespace boost{ namespace multi_index{ namespace{ implementation defined unbounded; } // see range() namespace detail{ template<implementation defined: dependent on types Value, Allocator, TagList, KeyFromValue, Compare> class name is implementation defined { public: // types: typedef typename KeyFromValue::result_type key_type; typedef Value value_type; typedef KeyFromValue key_from_value; typedef Compare key_compare; typedef implementation defined value_compare; typedef tuple<key_from_value,key_compare> ctor_args; typedef Allocator allocator_type; typedef typename Allocator::reference reference; typedef typename Allocator::const_reference const_reference; typedef implementation defined iterator; typedef implementation defined const_iterator; typedef implementation defined size_type; typedef implementation defined difference_type; typedef typename Allocator::pointer pointer; typedef typename Allocator::const_pointer const_pointer; typedef equivalent to std::reverse_iterator<iterator> reverse_iterator; typedef equivalent to std::reverse_iterator<const_iterator> const_reverse_iterator; // construct/copy/destroy: index class name& operator=(const index class name& x); allocator_type get_allocator()const; // iterators: iterator begin(); const_iterator begin()const; iterator end(); const_iterator end()const; reverse_iterator rbegin(); const_reverse_iterator rbegin()const; reverse_iterator rend(); const_reverse_iterator rend()const; // capacity: bool empty()const; size_type size()const; size_type max_size()const; // modifiers: std::pair<iterator,bool> insert(const value_type& x); iterator insert(iterator position,const value_type& x); template<typename InputIterator> void insert(InputIterator first,InputIterator last); iterator erase(iterator position); size_type erase(const key_type& x); iterator erase(iterator first,iterator last); bool replace(iterator position,const value_type& x); template<typename Modifier> bool modify(iterator position,Modifier mod); template<typename Modifier> bool modify_key(iterator position,Modifier mod); void swap(index class name& x); void clear(); // observers: key_from_value key_extractor()const; key_compare key_comp()const; value_compare value_comp()const; // set operations: template<typename CompatibleKey> iterator find(const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> iterator find( const CompatibleKey& x,const CompatibleCompare& comp)const; template<typename CompatibleKey> size_type count(const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> size_type count(const CompatibleKey& x,const CompatibleCompare& comp)const; template<typename CompatibleKey> iterator lower_bound(const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> iterator lower_bound( const CompatibleKey& x,const CompatibleCompare& comp)const; template<typename CompatibleKey> iterator upper_bound(const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> iterator upper_bound( const CompatibleKey& x,const CompatibleCompare& comp)const; template<typename CompatibleKey> std::pair<iterator,iterator> equal_range( const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> std::pair<iterator,iterator> equal_range( const CompatibleKey& x,const CompatibleCompare& comp)const; // range: template<typename LowerBounder,typename UpperBounder> std::pair<iterator,iterator> range( LowerBounder lower,UpperBounder upper)const; }; // index comparison: template<arg set 1,arg set 2> bool operator==( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return x.size()==y.size()&&std::equal(x.begin(),x.end(),y.begin()); } template<arg set 1,arg set 2> bool operator<( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()); } template<arg set 1,arg set 2> bool operator!=( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return !(x==y); } template<arg set 1,arg set 2> bool operator>( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return y<x; } template<arg set 1,arg set 2> bool operator>=( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return !(x<y); } template<arg set 1,arg set 2> bool operator<=( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return !(x>y); } // index specialized algorithms: template<implementation defined> void swap(index class name& x,index class name& y); } // namespace boost::multi_index::detail } // namespace boost::multi_index } // namespace boost
Here and in the descriptions of operations of ordered indices, we adopt the scheme outlined in the complexity signature section. The complexity signature of ordered indices is:
Ordered indices are instantiated internally to multi_index_container and
specified by means of indexed_by
with
index specifiers ordered_unique
and ordered_non_unique. Instantiations are dependent on the
following types:
Value from
multi_index_container,Compare from the index specifier.tag. The type KeyFromValue,
which determines the mechanism for extracting a key from
Value,
must be a model of
Key Extractor from Value. Compare is a
Strict Weak Ordering on elements of
KeyFromValue::result_type.
As explained in the index concepts section, indices do not have public constructors or destructors. Assignment, on the other hand, is provided.
index class name& operator=(const index class name& x);
Effects:where a and b are the multi_index_container objects to which *this and x belong, respectively.a=b;
Returns: *this.
Effects: Insertsiterator insert(iterator position,const value_type& x);xinto the multi_index_container to which the index belongs ifReturns: The return value is a pair
- the index is non-unique OR no other element exists with equivalent key,
- AND insertion is allowed by all other indices of the multi_index_container.
p. p.second is true if and only if insertion took place. On successful insertion, p.first points to the element inserted; otherwise, p.first points to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
Complexity: O(I(n)).
Exception safety: Strong.
Requires:template<typename InputIterator>positionis a valid iterator of the index. Effects: Insertsxinto the multi_index_container to which the index belongs if
- the index is non-unique OR no other element exists with equivalent key,
- AND insertion is allowed by all other indices of the multi_index_container.
positionis used as a hint to improve the efficiency of the operation.
Returns: On successful insertion, an iterator to the newly inserted element. Otherwise, an iterator to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
Complexity: O(H(n)).
Exception safety: Strong.
Requires:iterator erase(iterator position);InputIteratoris a model ofInput Iteratorover elements of type value_type or a type convertible to value_type.firstandlastare not iterators into any index of the multi_index_container to which this index belongs.lastis reachable fromfirst. Effects:Complexity: O(m*H(n+m)), whereiterator hint=end(); while(first!=last)hint=insert(hint,*first++);mis the number of elements in [first, last).
Exception safety: Basic.
Requires: position is a valid dereferenceable iterator of the index. Effects: Deletes the element pointed to bysize_type erase(const key_type& x);position.
Returns: An iterator pointing to the element immediately following the one that was deleted, orend()if no such element exists.
Complexity: O(D(n)).
Exception safety: nothrow.
Effects: Deletes the elements with key equivalent toiterator erase(iterator first,iterator last);x.
Returns: Number of elements deleted.
Complexity: O(log(n) + m*D(n)), wheremis the number of elements deleted.
Exception safety: Basic.
Requires: [first,last) is a valid range of the index.bool replace(iterator position,const value_type& x);
Effects: Deletes the elements in [first,last).
Returns: last.
Complexity: O(log(n) + m*D(n)), wheremis the number of elements in [first,last).
Exception safety: nothrow.
Requires:template<typename Modifier> bool modify(iterator position,Modifier mod);positionis a valid dereferenceable iterator of the index. Effects: Assigns the valuexto the element pointed to bypositioninto the multi_index_container to which the index belongs if, for the valuexPostconditions: Validity of
- the index is non-unique OR no other element exists (except possibly *position) with equivalent key,
- AND replacing is allowed by all other indices of the multi_index_container.
positionis preserved in all cases.
Returns:trueif the replacement took place, false otherwise.
Complexity: O(R(n)).
Exception safety: Strong. If an exception is thrown by some user-provided operation the multi_index_container to which the index belongs remains in its original state.
Requires: Modifier is a model oftemplate<typename Modifier> bool modify_key(iterator position,Modifier mod);Unary Functionaccepting arguments of type value_type&.positionis a valid dereferenceable iterator of the index. Effects: Calls mod(e) whereeis the element pointed to bypositionand rearranges*positioninto all the indices of the multi_index_container. Rearrangement is successful ifIf the rearrangement fails, the element is erased.
- the index is non-unique OR no other element exists with equivalent key,
- AND rearrangement is allowed by all other indices of the multi_index_container.
Postconditions: Validity of position is preserved if the operation succeeds.
Returns:trueif the operation succeeded, false otherwise.
Complexity: O(M(n)).
Exception safety: Basic. If an exception is thrown by some user-provided operation (except possiblymod), then the element pointed to bypositionis erased.
Requires: key_from_value is a read/writeKey Extractorfrom value_type.Modifieris a model ofUnary Functionaccepting arguments of type key_type&.positionis a valid dereferenceable iterator of the index. Effects: Callsmod(k)wherekis the key obtained by the internalKeyFromValue object of the index from the element pointed to byposition, and rearranges*positioninto all the indices of the multi_index_container. Rearrangement is successful ifIf the rearrangement fails, the element is erased.
- the index is non-unique OR no other element exists with equivalent key,
- AND rearrangement is allowed by all other indices of the multi_index_container.
Postconditions: Validity of position is preserved if the operation succeeds.
Returns:trueif the operation succeeded, false otherwise.
Complexity: O(M(n)).
Exception safety: Basic. If an exception is thrown by some user-provided operation (except possibly mod), then the element pointed to by position is erased.
Apart from standard key_comp and value_comp, ordered indices have a member function for retrieving the internal key extractor used.
key_from_value key_extractor()const;Returns a copy of the key_from_value object used to construct the index.
Complexity: Constant.
Ordered indices provide the full lookup functionality required by
Sorted Associative Containers and
Unique Associative Containers, namely
find,
count, lower_bound, upper_bound
and equal_range. Additionally, these member functions are templatized to allow for non-standard arguments, so extending
the types of search operations allowed. The kind of arguments permissible
when invoking the lookup member functions is defined by the following
concept.
Consider a
Strict Weak Ordering Compare
over values
of type Key. A pair of types
(CompatibleKey,
CompatibleCompare) is said to be a compatible
extension of Compare if
CompatibleCompare is a
Binary Predicate over
(Key,
CompatibleKey),CompatibleCompare is a
Binary Predicate over (CompatibleKey,
Key),!c_comp(k1,ck),
Compare, ck
of type
CompatibleKey and
k1, k2
of type Key.
Additionally, a type
CompatibleKey is said to be a
compatible key of Compare if
(CompatibleKey,
Compare) is a compatible extension of
Compare.
This implies that Compare,
as well as being a strict
weak ordering, accepts arguments of type
CompatibleKey,
which usually means it has several overloads of
operator().
In the context of a compatible extension or a compatible key, the expressions "equivalent", "less than" and "greater than" take on their obvious interpretations.
template<typename CompatibleKey> iterator find(const CompatibleKey& x)const;Requires: CompatibleKey is a compatible key of key_compare. Effects: Returns a pointer to an element whose key is equivalent to x, or end() if such an element does not exist.template<typename CompatibleKey,typename CompatibleCompare>
Complexity: O(log(n)).
Requires: (CompatibleKey, CompatibleCompare) is a compatible extension of key_compare. Effects: Returns a pointer to an element whose key is equivalent tox, orend()if such an element does not exist.
Complexity: O(log(n)).
template<typename CompatibleKey> size_type
count(const CompatibleKey& x)const;
Requires: CompatibleKey is a compatible key of key_compare. Effects: Returns the number of elements with key equivalent to x.template<typename CompatibleKey,typename CompatibleCompare>
Complexity: O(log(n) + count(x)).
Requires: (CompatibleKey, CompatibleCompare) is a compatible extension of key_compare. Effects: Returns the number of elements with key equivalent totemplate<typename CompatibleKey>x.
Complexity: O(log(n) + count(x,comp)).
Requires: CompatibleKey is a compatible key of key_compare. Effects: Returns an iterator pointing to the first element with key not less thantemplate<typename CompatibleKey,typename CompatibleCompare>x, orend()if such an element does not exist.
Complexity: O(log(n)).
Requires: (CompatibleKey, CompatibleCompare) is a compatible extension of key_compare. Effects: Returns an iterator pointing to the first element with key not less than x, or end() if such an element does not exist.template<typename CompatibleKey>
Complexity: O(log(n)).
Requires: CompatibleKey is a compatible key of key_compare. Effects: Returns an iterator pointing to the first element with key greater thantemplate<typename CompatibleKey,typename CompatibleCompare>x, orend()if such an element does not exist.
Complexity: O(log(n)).
Requires: (CompatibleKey, CompatibleCompare) is a compatible extension of key_compare. Effects: Returns an iterator pointing to the first element with key greater than x, or end() if such an element does not exist.template<typename CompatibleKey>
Complexity: O(log(n)).
Requires: CompatibleKey is a compatible key of key_compare. Effects: Equivalent to make_pair(lower_bound(x),upper_bound(x)).template<typename CompatibleKey,typename CompatibleCompare>
Complexity: O(log(n)).
Requires: (CompatibleKey, CompatibleCompare) is a compatible extension of key_compare. Effects: Equivalent to make_pair(lower_bound(x,comp),upper_bound(x,comp)).
Complexity: O(log(n)).
The member function range is not defined for sorted associative
containers, but ordered indices provide it as a convenient utility. A range
or interval is defined by two conditions for the lower and upper bounds, which
are modeled after the following concepts.
Consider a
Strict Weak Ordering Compare
over values
of type Key. A type LowerBounder is said to be
a lower bounder of Compare if
LowerBounder is a
Predicate over Key,
UpperBounder
is a
Predicate over Key,
upper(k1) and
!comp(k1,k2)
then
upper(k2),
UpperBounder,
comp of type
Compare,
and k1,
k2 of type Key.
Requires:LowerBounder and UpperBounder are a lower and upper bounder of key_compare,respectively. Effects: Returns a pair of iterators pointing to thebeginningand one past the end of the subsequence of elements satisfying lower and upper simultaneously. If no such elements exist, the iterators both point to the first element satisfyinglower, or else are equal toend()if this latter element does not exist.
Complexity: O(log(n)).
Variants: In place of lower or upper (or both), the singular value boost::multi_index::unbounded can be provided. This acts as a predicate which all values of type key_type satisfy.
Indices cannot be serialized on their own, but only as part of the multi_index_container into which they are embedded. In describing the additional preconditions and guarantees associated to ordered indices with respect to serialization of their embedding containers, Use the concepts defined in the multi_index_container serialization section.
Operation: saving of a multi_index_container m to an output archive (XML archive) ar.Requires: No additional requirements to those imposed by the container.Operation: loading of a multi_index_container m' from an input archive (XML archive) ar.
Requires: Additionally to the general requirements, value_comp() must be serialization-compatible withOperation: saving of an iterator or const_iteratorm.get<i>().value_comp(), whereiis the position of the ordered index in the container.
Postconditions: On succesful loading, each of the elements of [begin(), end()) is a restored copy of the corresponding element in [m.get<i>().begin(), m.get<i>().end()).
it to an output archive (XML archive)
ar.
Requires: it is a valid iterator of the index. The associated multi_index_container has been previously saved.
Operation: loading of an
iterator or const_iterator it' from an input archive (XML archive)
ar.
Postconditions: On succesful loading, ifitwas dereferenceable then *it' is the restored copy of *it, otherwise it'==end().
Note: It is allowed thatitbe a const_iterator and the restored it' an iterator, or viceversa.
|
Revised July 13th 2006© Copyright 2003-2006 Joaquín M López Muñoz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.html or copy at http://www.boost.org/LICENSE_1_0.txt) |