<p>We can <em>generate</em> a metafunction class from
<ttclass="literal"><spanclass="pre">boost::add_pointer<_1></span></tt>, using MPL's <ttclass="literal"><spanclass="pre">lambda</span></tt> metafunction:</p>
<tr><tdclass="label"><aclass="fn-backref"href="#id10"name="lambda">[4]</a></td><td>See <aclass="reference"href="http://en.wikipedia.org/wiki/Lambda_calculus"target="_top">http://en.wikipedia.org/wiki/Lambda_calculus</a> for
an in-depth treatment, including a reference to Church's paper
proving that the equivalence of lambda expressions is in general
not decidable.</td></tr>
</tbody>
</table>
<p>Although its primary purpose is to turn placeholder expressions
into metafunction classes, <ttclass="literal"><spanclass="pre">mpl::lambda</span></tt> can accept any lambda
expression, even if it's already a metafunction class. In that
case, <ttclass="literal"><spanclass="pre">lambda</span></tt> returns its argument unchanged. MPL algorithms
like <ttclass="literal"><spanclass="pre">transform</span></tt> call <ttclass="literal"><spanclass="pre">lambda</span></tt> internally, before invoking the
resulting metafunction class, so that they work equally well with
either kind of lambda expression. We can apply the same strategy
to <ttclass="literal"><spanclass="pre">twice</span></tt>:</p>
<preclass="literal-block">
template <class F, class X>
struct twice
: apply1<
typename mpl::lambda<F>::type
, typename apply1<
typename mpl::lambda<F>::type
, X
>::type
>
{};
</pre>
<p>Now we can use <ttclass="literal"><spanclass="pre">twice</span></tt> with metafunction classes <em>and</em>
placeholder expressions:</p>
<preclass="literal-block">
int* x;
twice<<strong>add_pointer_f</strong>, int>::type p = &x;