Files
mpl/doc/ref/Reference/size.html
Aleksey Gurtovoy a69baa5eae update the docs
[SVN r17836]
2003-03-12 13:29:12 +00:00

60 lines
3.0 KiB
HTML

<!doctype html public "-//ietf//dtd html//en">
<html><head><title>boost::mpl::size</title>
<link rel="stylesheet" href="../mpl_wiki.css">
</head><body bgcolor="white">
<h1><a href="../Table_of_Contents.html"><img src="../mpl_logo.jpg" alt="[Home]" border=0 align="right"></a>size</h1><h3>Synopsis</h3>
<p>
<pre>
template&lt;
typename Sequence
&gt;
struct size
{
typedef <em>unspecified</em> type;
};
</pre>
<p>
<h3>Description</h3>
<p>
<code>size</code> returns the number of elements in the sequence, that is, the number of elements in the range <code>[begin&lt;Sequence&gt;::type,end&lt;Sequence&gt;::type)</code>.
<p>
<h3>Definition</h3>
<p>
<pre>
#include "<a href="../../../../../boost/mpl/size.hpp">boost/mpl/size.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="../Sequence.html">Sequence</a></td><td></td></tr>
</table>
<p>
<h3>Expression semantics</h3>
<p>
<table border="1">
<tr><th>&nbsp;Expression&nbsp;</th><th>&nbsp;Expression&nbsp;type&nbsp;</th><th>&nbsp;Precondition&nbsp;</th><th>&nbsp;Semantics&nbsp;</th><th>&nbsp;Postcondition&nbsp;</th></tr>
<tr><td><code>typedef size&lt;Sequence&gt;::type s;</code></td><td>A model of <a href="../Integral_Constant.html">Integral Constant</a></td><td></td><td>Equivalent to <code>typedef distance&lt; begin&lt;Sequence&gt;::type,end&lt;Sequence&gt;::type &gt;::type s;</code></td><td><code>s::value &gt;= 0</code> </td></tr>
</table>
<p>
<h3>Complexity</h3>
<p>
The complexity of the <code>size</code> algorithm directly depends on the implementation of the particular sequence it is applied to. In the worst case <code>size</code> has a linear complexity. As a general rule, if the <code>Sequence</code> is a <a href="../Random_Access_Sequence.html">Random Access Sequence</a>, you can be certain that <code>size&lt;Sequence&gt;::type</code> is an amortized constant time operation. The opposite is not necessary true - for example, a model of <a href="../Forward_Sequence.html">Forward Sequence</a> still can guarantee you an amortized constant time <code>size</code> complexity. Please refer the documentation page of the concrete sequence type for further information.
<p>
<h3>Example</h3>
<p>
<pre>
typedef list0&lt;&gt; empty_list;
typedef vector_c&lt;int,0,1,2,3,4,5&gt; numbers;
typedef range_c&lt;int,0,100&gt; more_numbers;
<p>
BOOST_STATIC_ASSERT(size&lt;list&gt;::type::value == 0);
BOOST_STATIC_ASSERT(size&lt;numbers&gt;::type::value == 5);
BOOST_STATIC_ASSERT(size&lt;more_numbers&gt;::type::value == 100);
</pre>
<p>
<h3>See also</h3>
<p>
<a href="../Sequence.html">Sequence</a>, <code><a href="../Reference/empty.html">empty</a></code>, <code><a href="../Reference/begin.html">begin</a></code>, <code><a href="../Reference/end.html">end</a></code>
<p><hr>
<a href="../Table_of_Contents.html">Table of Contents</a><br>Last edited July 17, 2002 3:51 am</body></html>