Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.

[Home]erase

Synopsis

template<
      typename Sequence
    , typename First
    , typename Last = typename First::next
    >
struct erase
{
    typedef unspecified type;
};

Description

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.

Definition

#include "boost/mpl/erase.hpp"

Parameters

 Parameter  Requirement  Description  Default value  
SequenceA model of Extensible SequenceA sequence to handle the erase operation.
FirstA model of Forward IteratorIterator to the beginning of the range to be erased.
LastA model of Forward IteratorPast-the-end iterator of the range to be erased.typename First::next

Expression semantics

 Expression  Expression type  Precondition  Semantics  Postcondition 
typedef erase<Sequence,pos>::type s;A model of Extensible Sequencepos 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.

Complexity

The range form has linear complexity. The complexity of single-element erase is sequence dependent (linear in the worst case, or amortized constant time).

Example

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);

See also

Extensible Sequence, pop_front, pop_back, insert


Table of Contents
Last edited July 17, 2002 3:59 am