1 .. Sequences/Intrinsic Metafunctions//insert
18 typedef |unspecified| type;
28 typedef |unspecified| type;
35 ``insert`` is an |overloaded name|:
37 * ``insert<Sequence,Pos,T>`` performs an insertion of
38 type ``T`` at an arbitrary position ``Pos`` in ``Sequence``. ``Pos`` is ignored is
39 ``Sequence`` is a model of |Extensible Associative Sequence|.
41 * ``insert<Sequence,T>`` is a shortcut notation for ``insert<Sequence,Pos,T>`` for the
42 case when ``Sequence`` is a model of |Extensible Associative Sequence|.
50 #include <boost/mpl/insert.hpp>
56 |Tag Dispatched Metafunction|
62 +---------------+-----------------------------------+-----------------------------------------------+
63 | Parameter | Requirement | Description |
64 +===============+===================================+===============================================+
65 | ``Sequence`` | |Extensible Sequence| or | A sequence to insert into. |
66 | | |Extensible Associative Sequence| | |
67 +---------------+-----------------------------------+-----------------------------------------------+
68 | ``Pos`` | |Forward Iterator| | An iterator in ``Sequence`` specifying the |
69 | | | insertion position. |
70 +---------------+-----------------------------------+-----------------------------------------------+
71 | ``T`` | Any type | The element to be inserted. |
72 +---------------+-----------------------------------+-----------------------------------------------+
79 :class: expression-semantics
81 For any |Extensible Sequence| ``s``, iterator ``pos`` in ``s``, and arbitrary type ``x``:
85 typedef insert<s,pos,x>::type r;
91 ``pos`` is an iterator in ``s``.
94 ``r`` is a sequence, |concept-identical| to ``s``, of the following elements:
95 [``begin<s>::type``, ``pos``), ``x``, [``pos``, ``end<s>::type``).
98 The relative order of the elements in ``r`` is the same as in ``s``.
102 at< r, distance< begin<s>::type,pos >::type >::type
104 is identical to ``x``;
108 size<r>::value == size<s>::value + 1;
113 :class: expression-semantics
116 For any |Extensible Associative Sequence| ``s``, iterator ``pos`` in ``s``,
117 and arbitrary type ``x``:
122 typedef insert<s,x>::type r;
125 |Extensible Associative Sequence|
128 ``r`` is |concept-identical| and equivalent to ``s``, except that
129 ``at< r, key_type<s,x>::type >::type`` is identical to ``value_type<s,x>::type``.
132 ``size<r>::value == size<s>::value + 1``.
135 .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139 typedef insert<s,pos,x>::type r;
142 |Extensible Associative Sequence|
145 ``pos`` is an iterator in ``s``.
148 Equivalent to ``typedef insert<s,x>::type r``; ``pos`` is ignored.
155 +---------------------------------------+-----------------------------------------------+
156 | Sequence archetype | Complexity |
157 +=======================================+===============================================+
158 | |Extensible Associative Sequence| | Amortized constant time. |
159 +---------------------------------------+-----------------------------------------------+
160 | |Extensible Sequence| | Linear in the worst case, or amortized |
162 +---------------------------------------+-----------------------------------------------+
170 typedef vector_c<int,0,1,3,4,5,6,7,8,9> numbers;
171 typedef find< numbers,integral_c<int,3> >::type pos;
172 typedef insert< numbers,pos,integral_c<int,2> >::type range;
174 BOOST_MPL_ASSERT_RELATION( size<range>::value, ==, 10 );
175 BOOST_MPL_ASSERT(( equal< range,range_c<int,0,10> > ));
180 typedef map< mpl::pair<int,unsigned> > m;
181 typedef insert<m,mpl::pair<char,long> >::type m1;
183 BOOST_MPL_ASSERT_RELATION( size<m1>::value, ==, 2 );
184 BOOST_MPL_ASSERT(( is_same< at<m1,int>::type,unsigned > ));
185 BOOST_MPL_ASSERT(( is_same< at<m1,char>::type,long > ));
191 |Extensible Sequence|, |Extensible Associative Sequence|, |insert_range|, |push_front|, |push_back|, |erase|
194 .. copyright:: Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams
195 Distributed under the Boost Software License, Version 1.0. (See accompanying
196 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)