Is there a plan to add support for closures in CTFE?

Andrey Zherikov andrey.zherikov at gmail.com
Sat Aug 13 01:55:28 UTC 2022


I want to do string processing pipeline is a way that one 
delegate calls another one and so on. This works perfectly except 
the case when I want to get a result at compile time.
So I wonder is there a plan to add support for closures at 
compile time in foreseeable future?

Here is a simple example:
```d
string delegate(string) f1()
{
     return str => "f1 " ~ str;
}

string delegate(string) f2(string delegate(string) dg)
{
     return str => dg("f2 " ~ str);
}

string f3(string delegate(string) dg, string str)
{
     return dg("f3 " ~ str);
}

void main()
{
     import std.stdio;
     writeln(f1.f2.f3("text"));    // works perfectly

     enum s = f1.f2.f3("text");    // Error: closures are not yet 
supported in CTFE
}
```

Note: I'm not asking for workarounds (I know how to do that), I'm 
asking about the plan to fix this.


More information about the Digitalmars-d mailing list