Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-09-19 17:07:26


Richard Crossley wrote:
> > Unless there's something obvious I've missed, I think the
> > fact that it's hard to write one of the simplest
> > metafunctions, factorial, using "eva," could mean that it
> > could be hard to use this solution.
>
> Doesn't look difficult to me but that may just be familiarity
> with eva.
>
> Taking it a bit further something like this could be used:
>
> template <typename T>
> struct id{typedef T type;};
>
> template <typename T>
> struct eval{typedef T::type type;};
>
> template <typename T>
> struct eval<id<T> > : id<T>{};
>
> template <template <typename> class F,typename A0>
> struct eval<F<A0> > : F<typename eval<A0>::type>{};
>
> template <template <typename,typename> class F,typename
> A0,typename A1>
> struct eval<F<A0,A1> > : F<typename eval<A0>::type,typename
> eval<A1>::type>{};
>
> Etc...
>
> template <typename N = _>
> struct factorial : apply_if<equal_to<N,int_c<1>
> >,N,eval<mul<factorial<prior<N> >,N> > >{};

Yep, we seem to think along the same lines :).

Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk