On Fri, Nov 20, 2020 at 02:52:41PM +0000, Adam D. Ruppe via Digitalmars-d-learn 
wrote:
> On Friday, 20 November 2020 at 14:47:52 UTC, Paul Backus wrote:
> > There is no way to create an anonymous template in D.
> 
> I wish there was, maybe some day we can think of a way to add it to
> the language.

Wouldn't it be just syntactic sugar for a manually-declared helper
template?  We could just adapt the syntax for anonymous classes and
combine it with the syntax for lambdas, something like this:

        template(T) => ... /* compile-time expression */

So for example:

        auto myFunc(Args...)(Args args)
                if (allSatisfy!(template(T) => is(T : double)))
        { ... }

The template keyword is to differentiate between an actual lambda vs. a
"template lambda".  Not sure if we can leave out the (), it may be
necessary to diambiguate it from a named template declaration?

Implementation-wise, it would of course just lower to an injected helper
template declaration.


T

-- 
It is impossible to make anything foolproof because fools are so ingenious. -- 
Sammy

Reply via email to