Boost logo

Boost :

Subject: Re: [boost] Stupid Constexpr Lambda Trick
From: Paul Fultz II (pfultz2_at_[hidden])
Date: 2015-06-23 22:55:29


> I just wanted to share a C++14 emulation of the feature. The emulation
> uses both the already known conditional operator trick to allow
> constepr function objects to be initialized from lambda expressions,
> plus what I think is a novel trick to allow the actual function object
> operator() to be constexpr.
>
> Implementation + example is here:
>
> https://github.com/gpderetta/libtask/blob/master/lambda.cpp
>

That looks pretty awesome. Of course, the body of the lambda has to be
defined
inside of a macro. Either way, this could also add extra weight to persuade
the committee to consider adding constexpr lambdas to the standard, since
compilers can already do it with a little preprocessor work.

> I came up with the trick when trying to implement an emulation of
> N3617 (Lifting overload sets into function objects). Turns out that
> implementing the 'quote' syntax is almost trivial in C++14 with
> generic lambdas, but making it constexpr reliably has so far eluded
> me as all implementations I have tried ICE both gcc and clang. Still
> the constexpr lambda emulation itself seems to work.

So it ICEs when doing constexpr lambda emulation to lift overloads?

Paul

--
View this message in context: http://boost.2283326.n4.nabble.com/Stupid-Constexpr-Lambda-Trick-tp4677494p4677495.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