Why this template code does not compile?
Paul Backus
snarwin at gmail.com
Wed Mar 13 20:14:00 UTC 2019
On Wednesday, 13 March 2019 at 17:38:02 UTC, Victor Porton wrote:
> Why this template code does not compile?
>
> ///
> module runnable;
>
> import std.meta;
> import std.typecons;
>
> template FieldInfo(argT, string argName) {
> template FieldInfo(Nullable!argT argDefault =
> Nullable!argT()) {
> }
> }
>
> alias processFields(T, string name) =
> AliasSeq!(FieldInfo!(T, name)());
>
The inner `FieldInfo` template isn't a function, but by adding a
second set of parentheses after `(T, name)`, you're attempting to
call it as one.
If you want to instantiate the inner template with its default
argument, you can use `std.meta.Instantiate`:
alias processFields(T, string name) =
AliasSeq!(Instantiate!(FieldInfo!(T, name)));
More information about the Digitalmars-d-learn
mailing list