mirror of
https://github.com/boostorg/mpl.git
synced 2026-01-26 17:02:20 +01:00
67 lines
3.2 KiB
HTML
67 lines
3.2 KiB
HTML
<!doctype html public "-//ietf//dtd html//en">
|
|
<html><head><title>boost::mpl::Metafunction Class</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>Metafunction Class</h1><h3>Description</h3>
|
|
<p>
|
|
A <em>metafunction class</em> is a certain form of metafunction representation that enables higher-order metaprogramming. In particular, a non-nullary metafunction class is a type with a nested class template member <code>apply</code>. A nullary metafunction class has the form of a <a href="./Metafunction.html">nullary metafunction</a>. A metafunction class invocation is defined as invocation of its nested <code>apply</code> <a href="./Metafunction.html">metafunction</a>.
|
|
<p>
|
|
<h3>Valid expressions</h3>
|
|
<p>
|
|
<table border="1">
|
|
<tr><th> Expression </th><th> Expression type </th></tr>
|
|
<tr><td><code>typename f::type</code></td><td>A type </td></tr>
|
|
<tr><td><code>typename f::template apply<a1,..,an>::type</code></td><td>A type </td></tr>
|
|
</table>
|
|
<p>
|
|
<h3>Expression semantics</h3>
|
|
<p>
|
|
<table border="1">
|
|
<tr><th> Expression </th><th> Complexity </th><th> Precondition </th><th> Semantics </th><th> Postcondition </th></tr>
|
|
<tr><td><code>typename f::type</code></td><td>unspecified</td><td><code>f</code> is a nullary metafunction class; <code>f::type</code> is a <em>type-name</em></td><td><code>f::type</code> is the result of the metafunction class invocation</td><td></td></tr>
|
|
<tr><td><code>typename f::template apply<a1,..,an>::type</code></td><td>unspecified</td><td><code>f</code> is an <code>n</code>-ary metafunction class; <code>apply</code> is a <a href="./Metafunction.html">metafunction</a></td><td><code>typename f::template apply<a1,..,an>::type</code> is the result of the metafunction class invocation with the actual arguments <code>a1,..,an</code></td><td></td></tr>
|
|
</table>
|
|
<p>
|
|
<p>
|
|
<h3>Example</h3>
|
|
<p>
|
|
<pre>
|
|
<span class="cxx-comment">// nullary metafunction class</span>
|
|
struct always_true { typedef true_ type; };
|
|
<p>
|
|
template< long N > struct le
|
|
{
|
|
template< typename M > struct apply
|
|
{
|
|
typedef bool_< (M::value < N) > type;
|
|
};
|
|
};
|
|
<p>
|
|
<span class="cxx-comment">// unary metafunction class</span>
|
|
typedef le<5> less_than_5;
|
|
<p>
|
|
<span class="cxx-comment">// binary metafunction class</span>
|
|
struct less_than
|
|
{
|
|
template< typename N1, typename N2 > struct apply
|
|
{
|
|
typedef bool_< (N1::value < N2::value) > type;
|
|
};
|
|
};
|
|
<p>
|
|
<span class="cxx-comment">// invocations</span>
|
|
typedef always_true::type t1;
|
|
typedef less_than_5::apply< int_<7> >::type t2;
|
|
typedef less_than::apply< int_<5>,int_<7> >::type t3;
|
|
<p>
|
|
<span class="cxx-comment">// results checks</span>
|
|
BOOST_STATIC_ASSERT(t1::value);
|
|
BOOST_STATIC_ASSERT(!t2::value);
|
|
BOOST_STATIC_ASSERT(t3::value);
|
|
</pre>
|
|
<p>
|
|
<h3>See also</h3>
|
|
<p>
|
|
<a href="./Metafunctions.html">Metafunctions</a>, <a href="./Metafunction.html">Metafunction</a>
|
|
<p><hr>
|
|
<a href="./Table_of_Contents.html">Table of Contents</a><br>Last edited March 10, 2003 4:16 am</body></html> |