• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. Sequences/Intrinsic Metafunctions//erase
2
3erase
4=====
5
6Synopsis
7--------
8
9.. parsed-literal::
10
11    template<
12          typename Sequence
13        , typename First
14        , typename Last = |unspecified|
15        >
16    struct erase
17    {
18        typedef |unspecified| type;
19    };
20
21
22
23Description
24-----------
25
26``erase`` performs a removal of one or more adjacent elements in the sequence
27starting from an arbitrary position.
28
29Header
30------
31
32.. parsed-literal::
33
34    #include <boost/mpl/erase.hpp>
35
36
37Model of
38--------
39
40|Tag Dispatched Metafunction|
41
42
43Parameters
44----------
45
46+---------------+-----------------------------------+-----------------------------------------------+
47| Parameter     | Requirement                       | Description                                   |
48+===============+===================================+===============================================+
49| ``Sequence``  | |Extensible Sequence| or          | A sequence to erase from.                     |
50|               | |Extensible Associative Sequence| |                                               |
51+---------------+-----------------------------------+-----------------------------------------------+
52| ``First``     | |Forward Iterator|                | An iterator to the beginning of the range to  |
53|               |                                   | be erased.                                    |
54+---------------+-----------------------------------+-----------------------------------------------+
55| ``Last``      | |Forward Iterator|                | An iterator past-the-end of the range to be   |
56|               |                                   | erased.                                       |
57+---------------+-----------------------------------+-----------------------------------------------+
58
59
60Expression semantics
61--------------------
62
63.. compound::
64    :class: expression-semantics
65
66    For any |Extensible Sequence| ``s``, and iterators ``pos``, ``first`` and ``last`` into ``s``:
67
68
69    .. parsed-literal::
70
71        typedef erase<s,first,last>::type r;
72
73    :Return type:
74        |Extensible Sequence|.
75
76    :Precondition:
77        ``[first,last)`` is a valid range in ``s``.
78
79    :Semantics:
80        ``r`` is a new sequence, |concept-identical| to ``s``, of the following elements:
81        [``begin<s>::type``, ``pos``), [``last``, ``end<s>::type``).
82
83    :Postcondition:
84        The relative order of the elements in ``r`` is the same as in ``s``;
85
86        .. parsed-literal::
87
88           size<r>::value == size<s>::value - distance<first,last>::value
89
90
91    .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92
93    .. parsed-literal::
94
95        typedef erase<s,pos>::type r;
96
97    :Return type:
98        |Extensible Sequence|.
99
100    :Precondition:
101        ``pos`` is a dereferenceable iterator in ``s``.
102
103    :Semantics:
104        Equivalent to
105
106        .. parsed-literal::
107
108           typedef erase< s,pos,next<pos>::type >::type r;
109
110
111
112.. compound::
113    :class: expression-semantics
114
115    For any |Extensible Associative Sequence| ``s``, and iterator ``pos`` into ``s``:
116
117    .. parsed-literal::
118
119        typedef erase<s,pos>::type r;
120
121    :Return type:
122        |Extensible Sequence|.
123
124    :Precondition:
125        ``pos`` is a dereferenceable iterator to ``s``.
126
127    :Semantics:
128        Erases the element at a specific position ``pos``; equivalent to
129        ``erase_key<s, deref<pos>::type >::type``.
130
131    :Postcondition:
132        ``size<r>::value == size<s>::value - 1``.
133
134
135Complexity
136----------
137
138+---------------------------------------+-----------------------------------------------+
139| Sequence archetype                    | Complexity (the range form)                   |
140+=======================================+===============================================+
141| |Extensible Associative Sequence|     | Amortized constant time.                      |
142+---------------------------------------+-----------------------------------------------+
143| |Extensible Sequence|                 | Quadratic in the worst case, linear at best.  |
144+---------------------------------------+-----------------------------------------------+
145
146
147Example
148-------
149
150.. parsed-literal::
151
152    typedef vector_c<int,1,0,5,1,7,5,0,5> values;
153    typedef find< values, integral_c<int,7> >::type pos;
154    typedef erase<values,pos>::type result;
155
156    BOOST_MPL_ASSERT_RELATION( size<result>::value, ==, 7 );
157
158    typedef find<result, integral_c<int,7> >::type iter;
159    BOOST_MPL_ASSERT(( is_same< iter, end<result>::type > ));
160
161
162See also
163--------
164
165|Extensible Sequence|, |Extensible Associative Sequence|, |erase_key|, |pop_front|, |pop_back|, |insert|
166
167
168.. copyright:: Copyright �  2001-2009 Aleksey Gurtovoy and David Abrahams
169   Distributed under the Boost Software License, Version 1.0. (See accompanying
170   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
171