...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
template< typename Sequence , typename First , typename Last = typename First::next > struct erase { typedef unspecified type; };
erase
performs a removal of one or several consequent elements in the sequence starting from an arbitrary position. The algorithm returns a new sequence which contains all the elements in the ranges [begin<Sequence>::type, First)
and [Last, end<Sequence>::type)
. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
#include "boost/mpl/erase.hpp"
Parameter | Requirement | Description | Default value |
---|---|---|---|
Sequence | A model of Extensible Sequence | A sequence to handle the erase operation. | |
First | A model of Forward Iterator | Iterator to the beginning of the range to be erased. | |
Last | A model of Forward Iterator | Past-the-end iterator of the range to be erased. | typename First::next |
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef erase<Sequence,pos>::type s; | A model of Extensible Sequence | pos is a dereferenceable iterator in Sequence . | Returns a new sequence which contains all the elements in the ranges [begin<Sequence>::type, pos) and [next<pos>::type, end<Sequence>::type) . | size<s>::type::value == size<Sequence>::type::value - 1 ; the relative order of the elements in s is the same as in Sequence . |
typedef erase<Sequence,first,last>::type s; | A model of Extensible Sequence | [first,last) is a valid range in Sequence . | Returns a new sequence which contains all the elements in the ranges [begin<Sequence>::type, first) and [last, end<Sequence>::type) . | size<s>::type::value == size<Sequence>::type::value - distance<first,last>::type::value ; the relative order of the elements in s is the same as in Sequence . |
The range form has linear complexity. The complexity of single-element erase is sequence dependent (linear in the worst case, or amortized constant time).
typedef list_c<int,1,0,5,1,7,5,0,5> values; typedef find< values, integral_c<int,7> >::type pos; typedef erase<values,pos>::type result_seq; BOOST_STATIC_ASSERT(size<result_seq>::type::value == 7);typedef find<result, integral_c<int,7> >::type result_iter; BOOST_MPL_ASSERT_IS_SAME(result_iter, end<result_seq>::type);
Extensible Sequence, pop_front
, pop_back
, insert