Function template as template parameter

Salih Dincer salihdb at hotmail.com
Sun Dec 11 13:54:34 UTC 2022


On Sunday, 11 December 2022 at 09:43:34 UTC, Andrey Zherikov 
wrote:
> Note that callback parameter must be compile-time parameter as 
> it represents a member of a type during introspection done by 
> `foo`.

I can't quite understand the question, this already works:

```d
void foo(alias callback)()
{
     import std.stdio : writefln;
     callback.writefln!"%s";
}

void main()
{
   auto i = [ 1, 2, 3 ];
   auto s = ["foo", "bar", "zoo"];

   foo!i;
   foo!s;

   foo!"hello, world!";

   enum a = 11, b = 22;
   foo!(a + b);
} /*
   [1, 2, 3]
   ["foo", "bar", "zoo"]
   hello, world!
   33
*/
```


More information about the Digitalmars-d-learn mailing list