Boost logo

Boost :

Subject: Re: [boost] "Simple C++11 metaprogramming"
From: pfultz2 (pfultz2_at_[hidden])
Date: 2015-05-31 14:05:31


> If one day we have static constexpr lambdas, wouldn't we be able to use
> some kind of lambda meta-functions

We don't need constexpr lambdas to achieve this. We can do higher-order type
computations using dependent typing. I show here how to implement boost
fusion
filter so it will take a lambda rather than a MPL placeholder expression:

http://pfultz2.com/blog/2015/01/24/dependent-typing/

Which is based on the ideas presented by Zach Laine and Matt Calabrese
several
years ago at boostcon. So in essence you can write this in C++14:

    auto numbers = simple_filter(some_fusion_sequence, [](auto x)
    {
        return is_integral<decltype(x)>() or
is_floating_point<decltype(x)>();
    });

There is no `constexpr` required by the user. It all happens through
dependent
typing. This is how Boost.Hana works as well. Furthermore, Boost.Hana is not
`constexpr`-metaprogramming(athough it makes use of `constexpr`), it is
actually
dependently-typed metaprogramming, which is much more powerful in current
C++.

> Is not that what the proposed Boost.Hana and Boost.Fit do already using
> a specific trick?

That trick, in general, is only used to achieve `constexpr` initialization
of
lambdas, which is necessary when declaring global lambdas. In can be used in
other ways to allow type deduction of lambdas in a `constexpr` context.
However,
in general, with dependently-typed metaprogramming this isn't necessary.

Paul

--
View this message in context: http://boost.2283326.n4.nabble.com/Simple-C-11-metaprogramming-tp4676344p4676404.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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