mirror of
https://github.com/boostorg/mpl.git
synced 2026-01-26 17:02:20 +01:00
60 lines
3.0 KiB
HTML
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<
|
|
typename Sequence
|
|
>
|
|
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<Sequence>::type,end<Sequence>::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> Parameter </th><th> Requirement </th><th> Description </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> Expression </th><th> Expression type </th><th> Precondition </th><th> Semantics </th><th> Postcondition </th></tr>
|
|
<tr><td><code>typedef size<Sequence>::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< begin<Sequence>::type,end<Sequence>::type >::type s;</code></td><td><code>s::value >= 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<Sequence>::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<> empty_list;
|
|
typedef vector_c<int,0,1,2,3,4,5> numbers;
|
|
typedef range_c<int,0,100> more_numbers;
|
|
<p>
|
|
BOOST_STATIC_ASSERT(size<list>::type::value == 0);
|
|
BOOST_STATIC_ASSERT(size<numbers>::type::value == 5);
|
|
BOOST_STATIC_ASSERT(size<more_numbers>::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> |