...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 Pos , typename T > struct insert { typedef unspecified type; };
insert
performs an insertion of type T
at an arbitrary position in the sequence. The algorithm returns a new sequence which contains all the elements from Sequence
plus the type T
at the distance< begin<Sequence>::type,Pos >::type
position from the beginning. The result sequence preserves all the functional and performance characteristics of the original Sequence
, except its size and identity.
#include "boost/mpl/insert.hpp"
Parameter | Requirement | Description |
---|---|---|
Sequence | A model of Extensible Sequence | A sequence to handle the insert operation. |
Pos | A model of Forward Iterator | An insert position in the Sequence . |
T | A type | The element to be inserted. |
Expression | Expression type | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typedef insert<Sequence,pos,T>::type s; | A model of Extensible Sequence | pos is a valid iterator in Sequence . | s contains T at the distance< begin<Sequence>::type,pos >::type position. | size<s>::type::value == size<Sequence>::type::value + 1 ; at< distance< begin<Sequence>::type,pos >::type, s >::type is identical to T ; the relative order of the elements in s is the same as in Sequence . |
Sequence dependent. Linear in the worst case, or amortized constant time.
typedef list_c<int,0,1,3,4,5,6,7,8,9> numbers; typedef find< numbers,integral_c<int,3> >::type pos; typedef insert< numbers,pos,integral_c<int,2> >::type range; BOOST_STATIC_ASSERT(size<range>::type::value == 10); BOOST_STATIC_ASSERT((equal< range,range_c<int,0,10> >::type::value));
Extensible Sequence, insert_range
, push_front
, push_back
, erase