namespace boost { namespace bimaps { template< class KeyType > struct list_of; struct list_of_relation; } // namespace bimap } // namespace boost
A list_of set view is a std::list signature compatible interface to the
underlying heap of elements contained in a bimap.
If you look the bimap by a side, you will use a map view and if you looked it as a whole you will be using a set view.
Elements in a list_of view are by default sorted according to their order
of insertion: this means that new elements inserted through a different
view of the bimap are appended
to the end of the list_of view. Additionally, the view allows for free
reordering of elements in the same vein as std::list
does. Validity of iterators and references to elements is preserved in
all operations.
There are a number of differences with respect to std::lists:
- list_of views are not Assignable (like any other view.)
-
Unlike as in
std::list, insertions into a list_of view may fail due to clashings with other views. This alters the semantics of the operations provided with respect to their analogues instd::list. -
Elements in a list_of view are not mutable, and can only be changed by
means of
replaceandmodifymember functions.
Having these restrictions into account, list_of views are models of Reversible Container, Front Insertion Sequence and Back Insertion Sequence. We only 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 bimaps { namespace views { template< -implementation defined parameter list- > class -implementation defined view name- { public: // types typedef -unspecified- value_type; typedef -unspecified- allocator_type; typedef -unspecified- reference; typedef -unspecified- const_reference; typedef -unspecified- iterator; typedef -unspecified- const_iterator; typedef -unspecified- size_type; typedef -unspecified- difference_type; typedef -unspecified- pointer; typedef -unspecified- const_pointer; typedef -unspecified- reverse_iterator; typedef -unspecified- const_reverse_iterator; typedef -unspecified- info_type; // construct/copy/destroy this_type & operator=(const this_type & x); template< class InputIterator > void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type & value); 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; void resize(size_type n, const value_type & x = value_type()); // access const_reference front() const; const_reference back() const; // modifiers std::pair<iterator,bool> push_front(const value_type & x); void pop_front(); std::pair<iterator,bool> push_back(const value_type & x); void pop_back(); std::pair<iterator,bool> insert(iterator position, const value_type & x); void insert(iterator position, size_type n, const value_type & x); template< class InputIterator > void insert(iterator position, InputIterator first, InputIterator last); iterator erase(iterator position); iterator erase(iterator first, iterator last); bool replace(iterator position, const value_type & x); // Only in map views // { template< class CompatibleKey > bool replace_key(iterator position, const CompatibleKey & x); template< class CompatibleData > bool replace_data(iterator position, const CompatibleData & x); template< class KeyModifier > bool modify_key(iterator position, KeyModifier mod); template< class DataModifier > bool modify_data(iterator position, DataModifier mod); // } void clear(); // list operations void splice(iterator position, this_type & x); void splice(iterator position, this_type & x, iterator i); void splice( iterator position, this_type & x, iterator first, iterator last); void remove(const value_type & value); template< class Predicate > void remove_if(Predicate pred); void unique(); template< class BinaryPredicate > void unique(BinaryPredicate binary_pred); void merge(this_type & x); template< class Compare > void merge(this_type & x,Compare comp); void sort(); template< class Compare > void sort(Compare comp); void reverse(); // rearrange operations void relocate(iterator position, iterator i); void relocate(iterator position, iterator first, iterator last); } // view comparison bool operator==(const this_type & v1, const this_type & v2 ); bool operator< (const this_type & v1, const this_type & v2 ); bool operator!=(const this_type & v1, const this_type & v2 ); bool operator> (const this_type & v1, const this_type & v2 ); bool operator>=(const this_type & v1, const this_type & v2 ); bool operator<=(const this_type & v1, const this_type & v2 ); } // namespace views } // namespace bimap } // namespace boost
In the case of a bimap< list_of<Left>, ... >
In the set view:
typedef signature-compatible with relation< Left, ... > key_type; typedef signature-compatible with relation< Left, ... > value_type;
In the left map view:
typedef Left key_type; typedef ... data_type; typedef signature-compatible with std::pair< Left, ... > value_type;
In the right map view:
typedef ... key_type; typedef Left data_type; typedef signature-compatible with std::pair< ... , Left > value_type;
Here and in the descriptions of operations of list_of
views, we adopt the scheme outlined in the complexity
signature section. The complexity signature of a list_of view is:
-
copying:
c(n) = n * log(n), -
insertion:
i(n) = 1(constant), -
hinted insertion:
h(n) = 1(constant), -
deletion:
d(n) = 1(constant), -
replacement:
r(n) = 1(constant), -
modifying:
m(n) = 1(constant).
list_of views are instantiated
internally to bimap and
specified by means of the collection type specifiers and the bimap itself.
Instantiations are dependent on the following types:
-
Valuefromlist_of, -
Allocatorfrombimap,
As explained in the view concepts section, views do not have public constructors or destructors. Assignment, on the other hand, is provided.
this_type & operator=(const this_type & x);
-
Effects:
a = b;where a and b are thebimapobjects to which*thisandxbelong, respectively. -
Returns:
*this.
template< class InputIterator > void assign(InputIterator first, InputIterator last);
-
Requires:
InputIteratoris a model of Input Iterator over elements of typevalue_typeor a type convertible tovalue_type. first and last are not iterators into any views of thebimapto which this view belongs.lastis reachable fromfirst. -
Effects:
clear(); insert(end(),first,last);
void assign(size_type n, const value_type & value);
-
Effects:
clear(); for(size_type i = 0; i < n ; ++n) push_back(v);
void resize(size_type n,const value_type& x=value_type());
-
Effects:
if( n > size() ) insert(end(), n - size(), x);else if( n < size() ) {iterator it = begin();std::advance(it, n);erase(it, end());} - Note: If an expansion is requested, the size of the view is not guaranteed to be n after this operation (other views may ban insertions.)
std::pair<iterator,bool> push_front(const value_type& x);
-
Effects: Inserts
xat the beginning of the sequence if no other views of thebimapbans the insertion. -
Returns: The return value is a pair
p.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints 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.
std::pair<iterator,bool> push_back(const value_type & x);
-
Effects: Inserts
xat the end of the sequence if no other views of thebimapbans the insertion. -
Returns: The return value is a pair
p.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints 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.
std::pair<iterator,bool> insert(iterator position, const value_type & x);
-
Requires:
positionis a validiteratorof the view. -
Effects: Inserts
xbefore position if insertion is allowed by all other views of thebimap. -
Returns: The return value is a pair
p.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints 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.
void insert(iterator position, size_type n, const value_type & x);
-
Requires:
positionis a validiteratorof the view. -
Effects:
for(size_type i = 0; i < n; ++i) insert(position, x);
template< class InputIterator> void insert(iterator position,InputIterator first,InputIterator last);
-
Requires:
positionis a validiteratorof the view.InputIteratoris a model of Input Iterator over elements of typevalue_type.firstandlastare not iterators into any view of thebimapto which this view belongs.lastis reachable fromfirst. -
Effects:
while(first != last) insert(position, *first++); -
Complexity:
O(m*I(n+m)), where m is the number of elements in
[first,last). - Exception safety: Basic.
iterator erase(iterator position);
-
Requires:
positionis a valid dereferenceableiteratorof the view. -
Effects: Deletes the element pointed
to by
position. -
Returns: An iterator pointing to the
element immediately following the one that was deleted, or
end()if no such element exists. - Complexity: O(D(n)).
- Exception safety: nothrow.
iterator erase(iterator first, iterator last);
-
Requires:
[first,last)is a valid range of the view. -
Effects: Deletes the elements in
[first,last). -
Returns:
last. -
Complexity:
O(m*D(n)), where m is the number of elements in
[first,last). - Exception safety: nothrow.
bool replace(iterator position,const value_type& x);
-
Requires:
positionis a valid dereferenceable iterator of the view. -
Effects: Assigns the value
xto the element pointed to bypositioninto thebimapto which the view belongs if replacing is allowed by all other views of thebimap. -
Postconditions: Validity of
positionis preserved in all cases. -
Returns:
trueif the replacement took place,falseotherwise. - Complexity: O(R(n)).
-
Exception safety: Strong. If an exception
is thrown by some user-provided operation the
bimapto which the view belongs remains in its original state.
template< class CompatibleKey > bool replace_key(iterator position, const CompatibleKey & x);
-
Requires:
positionis a valid dereferenceable iterator of the set view.CompatibleKeycan be assigned tokey_type. -
Effects: Assigns the value
xtoe.first, whereeis the element pointed to bypositioninto thebimapto which the set view belongs if replacing is allowed by all other views of thebimap. - Postconditions: Validity of position is preserved in all cases.
-
Returns:
trueif the replacement took place,falseotherwise. - Complexity: O(R(n)).
-
Exception safety: Strong. If an exception
is thrown by some user-provided operation, the
bimapto which the set view belongs remains in its original state.
template< class CompatibleData > bool replace_data(iterator position, const CompatibleData & x);
-
Requires:
positionis a valid dereferenceable iterator of the set view.CompatibleKeycan be assigned todata_type. -
Effects: Assigns the value
xtoe.second, whereeis the element pointed to bypositioninto thebimapto which the set view belongs if replacing is allowed by all other views of thebimap. - Postconditions: Validity of position is preserved in all cases.
-
Returns:
trueif the replacement took place,falseotherwise. - Complexity: O(R(n)).
-
Exception safety: Strong. If an exception
is thrown by some user-provided operation, the
bimapto which the set view belongs remains in its original state.
template< class KeyModifier > bool modify_key(iterator position, KeyModifier mod);
-
Requires:
KeyModifieris a model of Unary Function accepting arguments of type:key_type&;positionis a valid dereferenceable iterator of the view. -
Effects: Calls
mod(e.first)where e is the element pointed to by position and rearranges*positioninto all the views of thebimap. If the rearrangement fails, the element is erased. It is successful if the rearrangement is allowed by all other views of thebimap. -
Postconditions: Validity of
positionis preserved if the operation succeeds. -
Returns:
trueif the operation succeeded,falseotherwise. - 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.
- Note: Only provided for map views.
template< class DataModifier > bool modify_data(iterator position, DataModifier mod);
-
Requires:
DataModifieris a model of Unary Function accepting arguments of type:data_type&;positionis a valid dereferenceable iterator of the view. -
Effects: Calls
mod(e.second)where e is the element pointed to by position and rearranges*positioninto all the views of thebimap. If the rearrangement fails, the element is erased. It is successful if the rearrangement is allowed by all other views of thebimap. -
Postconditions: Validity of
positionis preserved if the operation succeeds. -
Returns:
trueif the operation succeeded,falseotherwise. - 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.
- Note: Only provided for map views.
list_of views provide
the full set of list operations found in std::list;
the semantics of these member functions, however, differ from that of
std::list in some cases as insertions might
not succeed due to banning by other views. Similarly, the complexity
of the operations may depend on the other views belonging to the same
bimap.
void splice(iterator position, this_type & x);
-
Requires:
positionis a valid iterator of the view.&x!=this. -
Effects: Inserts the contents of
xbefore position, in the same order as they were inx. Those elements successfully inserted are erased fromx. -
Complexity:
O(
x.size()*I(n+x.size()) +x.size()*D(x.size())). - Exception safety: Basic.
void splice(iterator position, this_type & x,iterator i);
-
Requires:
positionis a valid iterator of the view.iis a valid dereferenceable iteratorx. -
Effects: Inserts the element pointed
to by
ibefore position: if insertion is successful, the element is erased fromx. In the special case&x==this, no copy or deletion is performed, and the operation is always successful. Ifposition==i, no operation is performed. -
Postconditions: If
&x==this, no iterator or reference is invalidated. -
Complexity:
If
&x==this, constant; otherwise O(I(n) + D(n)). -
Exception safety: If
&x==this, nothrow; otherwise, strong.
void splice(iterator position, this_type & x, iterator first, iterator last);
-
Requires:
positionis a valid iterator of the view.firstandlastare valid iterators ofx. last is reachable fromfirst. position is not in the range[first,last). -
Effects: For each element in the range
[first,last), insertion is tried before position; if the operation is successful, the element is erased from x. In the special case&x==this, no copy or deletion is performed, and insertions are always successful. -
Postconditions: If
&x==this, no iterator or reference is invalidated. -
Complexity:
If
&x==this, constant; otherwise O(m*I(n+m) + m*D(x.size())) where m is the number of elements in[first,last). -
Exception safety: If
&x==this, nothrow; otherwise, basic.
void remove(const value_type & value);
-
Effects: Erases all elements of the
view which compare equal to
value. - Complexity: O(n + m*D(n)), where m is the number of elements erased.
- Exception safety: Basic.
template< class Predicate > void remove_if(Predicate pred);
-
Effects: Erases all elements
xof the view for whichpred(x)holds. - Complexity: O(n + m*D(n)), where m is the number of elements erased.
- Exception safety: Basic.
void unique();
-
Effects: Eliminates all but the first
element from every consecutive group of equal elements referred to
by the iterator
iin the range[first+1,last)for which*i==*(i-1). - Complexity: O(n + m*D(n)), where m is the number of elements erased.
- Exception safety: Basic.
template< class BinaryPredicate > void unique(BinaryPredicate binary_pred);
-
Effects: Eliminates all but the first
element from every consecutive group of elements referred to by the
iterator i in the range [first+1,last) for which
binary_pred(*i,*(i-1))holds. - Complexity: O(n + m*D(n)), where m is the number of elements erased.
- Exception safety: Basic.
void merge(this_type & x);
-
Requires:
std::less<value_type>is a Strict Weak Ordering overvalue_type. Both the view andxare sorted according tostd::less<value_type>. -
Effects: Attempts to insert every
element of
xinto the corresponding position of the view (according to the order). Elements successfully inserted are erased fromx. The resulting sequence is stable, i.e. equivalent elements of either container preserve their relative position. In the special case&x==this, no operation is performed. -
Postconditions: Elements in the view
and remaining elements in
xare sorted. Validity of iterators to the view and of non-erased elements ofxreferences is preserved. -
Complexity:
If
&x==this, constant; otherwise O(n +x.size()*I(n+x.size()) +x.size()*D(x.size())). -
Exception safety: If
&x==this, nothrow; otherwise, basic.
template< class Compare > void merge(this_type & x, Compare comp);
-
Requires: Compare is a Strict
Weak Ordering over
value_type. Both the view andxare sorted according tocomp. -
Effects: Attempts to insert every
element of
xinto the corresponding position of the view (according tocomp). Elements successfully inserted are erased fromx. The resulting sequence is stable, i.e. equivalent elements of either container preserve their relative position. In the special case&x==this, no operation is performed. -
Postconditions: Elements in the view
and remaining elements in
xare sorted according tocomp. Validity of iterators to the view and of non-erased elements ofxreferences is preserved. -
Complexity:
If
&x==this, constant; otherwise O(n +x.size()*I(n+x.size()) +x.size()*D(x.size())). -
Exception safety: If
&x==this, nothrow; otherwise, basic.
void sort();
-
Requires:
std::less<value_type>is a Strict Weak Ordering over value_type. -
Effects: Sorts the view according
to
std::less<value_type>. The sorting is stable, i.e. equivalent elements preserve their relative position. - Postconditions: Validity of iterators and references is preserved.
- Complexity: O(n*log(n)).
-
Exception safety: nothrow if
std::less<value_type>does not throw; otherwise, basic.
template< typename Compare > void sort(Compare comp);
- Requires: Compare is a Strict Weak Ordering over value_type.
- Effects: Sorts the view according to comp. The sorting is stable, i.e. equivalent elements preserve their relative position.
- Postconditions: Validity of iterators and references is preserved.
- Complexity: O(n*log(n)).
- Exception safety: nothrow if comp does not throw; otherwise, basic.
void reverse();
- Effects: Reverses the order of the elements in the view.
- Postconditions: Validity of iterators and references is preserved.
- Complexity: O(n).
- Exception safety: nothrow.
These operations, without counterpart in std::list
(although splice provides partially overlapping functionality), perform
individual and global repositioning of elements inside the index.
void relocate(iterator position, iterator i);
-
Requires:
positionis a valid iterator of the view.iis a valid dereferenceable iterator of the view. -
Effects: Inserts the element pointed
to by
ibeforeposition. Ifposition==i, no operation is performed. - Postconditions: No iterator or reference is invalidated.
- Complexity: Constant.
- Exception safety: nothrow.
void relocate(iterator position, iterator first, iterator last);
-
Requires:
positionis a valid iterator of the view.firstandlastare valid iterators of the view.lastis reachable fromfirst.positionis not in the range[first,last). -
Effects: The range of elements
[first,last)is repositioned just beforeposition. - Postconditions: No iterator or reference is invalidated.
- Complexity: Constant.
- Exception safety: nothrow.
Views cannot be serialized on their own, but only as part of the bimap into which they are embedded.
In describing the additional preconditions and guarantees associated
to list_of views with
respect to serialization of their embedding containers, we use the concepts
defined in the bimap
serialization section.
- Requires: No additional requirements to those imposed by the container.
-
Requires: No additional requirements
to those imposed by the container. Postconditions:
On successful 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()), whereiis the position of thelist_ofview in the container.
-
Requires:
itis a valid iterator of the view. The associatedbimaphas been previously saved.
-
Postconditions: On successful loading,
if it was dereferenceable then
*it' is the restored copy of*it, otherwiseit'== end(). -
Note: It is allowed that
itbe aconst_iteratorand the restoredit' an iterator, or viceversa.
