Boost logo

Boost :

Subject: Re: [boost] [mpl] multiset
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2015-03-12 20:05:40


Eric Niebler <eniebler <at> boost.org> writes:

> [...]
>
> using factorial_ = lambda_rec<_a,
> lazy::if_<lazy::greater<_a, meta::size_t<0>>,
> lazy::multiplies<_a, lazy::apply<_self, lazy::dec<_a>>>,
> meta::size_t<1>>>;
> template<std::size_t N>
> using factorial = apply<factorial_, meta::size_t<N>>;
>
> Metafunctions? We don't need no stinkin' metafunctions!

FWIW, here's how you can implement a factorial with lazy
metafunctions, here done with MPL11:

    template <typename N>
    struct fact
        : if_c<N::value == 0,
            ullong<1>,
            mult<N, fact<pred<N>>>
>
     { };

Lambda expressions are a nice hammer, but a factorial metafunction
is seemingly not a nail.

Regards,
Louis


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