.. Sequences/Intrinsic Metafunctions//insert insert ====== Synopsis -------- .. parsed-literal:: template< typename Sequence , typename Pos , typename T > struct insert { typedef |unspecified| type; }; template< typename Sequence , typename T > struct insert { typedef |unspecified| type; }; Description ----------- ``insert`` is an |overloaded name|: * ``insert`` performs an insertion of type ``T`` at an arbitrary position ``Pos`` in ``Sequence``. ``Pos`` is ignored is ``Sequence`` is a model of |Extensible Associative Sequence|. * ``insert`` is a shortcut notation for ``insert`` for the case when ``Sequence`` is a model of |Extensible Associative Sequence|. Header ------ .. parsed-literal:: #include Model of -------- |Tag Dispatched Metafunction| Parameters ---------- +---------------+-----------------------------------+-----------------------------------------------+ | Parameter | Requirement | Description | +===============+===================================+===============================================+ | ``Sequence`` | |Extensible Sequence| or | A sequence to insert into. | | | |Extensible Associative Sequence| | | +---------------+-----------------------------------+-----------------------------------------------+ | ``Pos`` | |Forward Iterator| | An iterator in ``Sequence`` specifying the | | | | insertion position. | +---------------+-----------------------------------+-----------------------------------------------+ | ``T`` | Any type | The element to be inserted. | +---------------+-----------------------------------+-----------------------------------------------+ Expression semantics -------------------- .. compound:: :class: expression-semantics For any |Extensible Sequence| ``s``, iterator ``pos`` in ``s``, and arbitrary type ``x``: .. parsed-literal:: typedef insert::type r; :Return type: |Extensible Sequence| :Precondition: ``pos`` is an iterator in ``s``. :Semantics: ``r`` is a sequence, |concept-identical| to ``s``, of the following elements: [``begin::type``, ``pos``), ``x``, [``pos``, ``end::type``). :Postcondition: The relative order of the elements in ``r`` is the same as in ``s``. .. parsed-literal:: at< r, distance< begin::type,pos >::type >::type is identical to ``x``; .. parsed-literal:: size::value == size::value + 1; .. compound:: :class: expression-semantics For any |Extensible Associative Sequence| ``s``, iterator ``pos`` in ``s``, and arbitrary type ``x``: .. parsed-literal:: typedef insert::type r; :Return type: |Extensible Associative Sequence| :Semantics: ``r`` is |concept-identical| and equivalent to ``s``, except that ``at< r, key_type::type >::type`` is identical to ``value_type::type``. :Postcondition: ``size::value == size::value + 1``. .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. parsed-literal:: typedef insert::type r; :Return type: |Extensible Associative Sequence| :Precondition: ``pos`` is an iterator in ``s``. :Semantics: Equivalent to ``typedef insert::type r``; ``pos`` is ignored. Complexity ---------- +---------------------------------------+-----------------------------------------------+ | Sequence archetype | Complexity | +=======================================+===============================================+ | |Extensible Associative Sequence| | Amortized constant time. | +---------------------------------------+-----------------------------------------------+ | |Extensible Sequence| | Linear in the worst case, or amortized | | | constant time. | +---------------------------------------+-----------------------------------------------+ Example ------- .. parsed-literal:: typedef vector_c numbers; typedef find< numbers,integral_c >::type pos; typedef insert< numbers,pos,integral_c >::type range; BOOST_MPL_ASSERT_RELATION( size::value, ==, 10 ); BOOST_MPL_ASSERT(( equal< range,range_c > )); .. parsed-literal:: typedef map< mpl::pair > m; typedef insert >::type m1; BOOST_MPL_ASSERT_RELATION( size::value, ==, 2 ); BOOST_MPL_ASSERT(( is_same< at::type,unsigned > )); BOOST_MPL_ASSERT(( is_same< at::type,long > )); See also -------- |Extensible Sequence|, |Extensible Associative Sequence|, |insert_range|, |push_front|, |push_back|, |erase|