Files
mpl/doc/ref/Reference/insert.html
Dave Abrahams 01d61922bc Added libs/mpl
[SVN r15384]
2002-09-16 19:25:33 +00:00

62 lines
3.7 KiB
HTML

<!doctype html public "-//ietf//dtd html//en">
<html><head><title>boost::mpl::Reference/insert</title>
<link rel="stylesheet" href="../mpl_wiki.css">
</head><body bgcolor="white">
<h1><a href="../Table_of_Content.html"><img src="../mpl_logo.jpg" alt="[Home]" border=0 align="right"></a>insert</h1><h3>Synopsis</h3>
<p>
<pre>
template&lt;
typename Sequence
, typename Pos
, typename T
&gt;
struct insert
{
typedef <em>unspecified</em> type;
};
</pre>
<p>
<h3>Description</h3>
<p>
<code>insert</code> performs an insertion of type <code>T</code> at an arbitrary position in the sequence. The algorithm returns a new sequence which contains all the elements from <code>Sequence</code> plus the type <code>T</code> at the <code>distance&lt; begin&lt;Sequence&gt;::type,Pos &gt;::type</code> position from the beginning. The result sequence preserves all the functional and performance characteristics of the original <code>Sequence</code>, except its size and identity.
<p>
<h3>Definition</h3>
<p>
<pre>
#include "<a href="../../../../../\boost/mpl/insert.hpp">boost/mpl/insert.hpp</a>"
</pre>
<p>
<h3>Parameters</h3>
<table border="1">
<tr><th>&nbsp;Parameter&nbsp;</th><th>&nbsp;Requirement&nbsp;</th><th>&nbsp;Description &nbsp;</th></tr>
<tr><td><code>Sequence</code></td><td>A model of <a href="../Extensible_Sequence.html">Extensible Sequence</a></td><td>A sequence to handle the insert operation. </td></tr>
<tr><td><code>Pos</code></td><td>A model of <a href="../Forward_Iterator.html">Forward Iterator</a></td><td>An insert position in the <code>Sequence</code>. </td></tr>
<tr><td><code>T</code></td><td>A type</td><td>The element to be inserted. </td></tr>
</table>
<p>
<h3>Expression semantics</h3>
<p>
<table border="1">
<tr><th>&nbsp;Expression&nbsp;</th><th>&nbsp;Expression type&nbsp;</th><th>&nbsp;Precondition&nbsp;</th><th>&nbsp;Semantics&nbsp;</th><th>&nbsp;Postcondition&nbsp;</th></tr>
<tr><td><code>typedef insert&lt;Sequence,pos,T&gt;::type s;</code></td><td>A model of <a href="../Extensible_Sequence.html">Extensible Sequence</a></td><td><code>pos</code> is a valid iterator in <code>Sequence</code>.</td><td><code>s</code> contains <code>T</code> at the <code>distance&lt; begin&lt;Sequence&gt;::type,pos &gt;::type</code> position.</td><td><code>size&lt;s&gt;::type::value == size&lt;Sequence&gt;::type::value + 1</code>; <code>at&lt; distance&lt; begin&lt;Sequence&gt;::type,pos &gt;::type, s &gt;::type</code> is identical to <code>T</code>; the relative order of the elements in <code>s</code> is the same as in <code>Sequence</code>. </td></tr>
</table>
<p>
<h3>Complexity</h3>
<p>
Sequence dependent. Linear in the worst case, or amortized constant time.
<p>
<h3>Example</h3>
<p>
<pre>
typedef <a href="../Reference/list_c.html">list_c</a>&lt;int,0,1,3,4,5,6,7,8,9&gt; numbers;
typedef <a href="../Reference/find.html">find</a>&lt; numbers,integral_c&lt;int,3&gt; &gt;::type pos;
typedef insert&lt; numbers,pos,integral_c&lt;int,2&gt; &gt;::type range;
BOOST_STATIC_ASSERT(<a href="../Reference/size.html">size</a>&lt;range&gt;::type::value == 10);
BOOST_STATIC_ASSERT((<a href="../Reference/equal.html">equal</a>&lt; range,<a href="../Reference/range_c.html">range_c</a>&lt;int,0,10&gt; &gt;::type::value));
</pre>
<p>
<h3>See also</h3>
<p>
<a href="../Extensible_Sequence.html">Extensible Sequence</a>, <code><a href="../Reference/insert_range.html">insert_range</a></code>, <code><a href="../Reference/push_front.html">push_front</a></code>, <code><a href="../Reference/push_back.html">push_back</a></code>, <code><a href="../Reference/erase.html">erase</a></code>
<p><hr>
<a href="../Table_of_Content.html">Table of Content</a> | <a href="../Reference.html">Reference</a><br>Last edited July 17, 2002 5:17 am</body></html>