From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-09-19 17:01:19
Terje Slettebø wrote:
> Consider the "factorial" metafunction, again:
> template<class V>
> struct factorial
> typedef typename V::type Value;
> typedef typename apply_if<equal_to<Value,value<Value,0> >,
> mul<Value,factorial<prior<Value> > >
> >::type type;
> I had first planned to look at a comparison with using "eva,"
> but I realized that I had a hard time finding out how I could
> write the above, using "eva," since the call to factorial is used
> as a parameter to "mul," and unlike apply_if, that doesn't evaluate
> its arguments, which is what makes your first "eva" example work.
Here's how you could write it with lazy-lambda:
template< typename N >
typedef typename apply_if<
equal_to< N, int_c<0> >
multiplies< N, factorial< prior<N> > >
It even works :).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk