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 the documentation for an old version of boost. Click here for the latest Boost documentation.

[Home]insert

Synopsis

template<
      typename Sequence
    , typename Pos
    , typename T
    >
struct insert
{
    typedef unspecified type;
};

Description

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.

Definition

#include "boost/mpl/insert.hpp"

Parameters

 Parameter  Requirement  Description  
SequenceA model of Extensible SequenceA sequence to handle the insert operation.
PosA model of Forward IteratorAn insert position in the Sequence.
TA typeThe element to be inserted.

Expression semantics

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

Complexity

Sequence dependent. Linear in the worst case, or amortized constant time.

Example

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

See also

Extensible Sequence, insert_range, push_front, push_back, erase


Table of Contents
Last edited July 17, 2002 5:17 am