Re: Why this template code does not compile?

2019-03-13 Thread Paul Backus via Digitalmars-d-learn

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)));


Why this template code does not compile?

2019-03-13 Thread Victor Porton via Digitalmars-d-learn

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)());

void main(string[] args)
{
alias Fields = processFields!(int, "x");
}
///

/tmp/temp_7F58BE2F0150.d(12,34): Error: template 
`runnable.FieldInfo!(int, "x").FieldInfo` cannot deduce function 
from argument types `!()()`, candidates are:
/tmp/temp_7F58BE2F0150.d(7,5):`runnable.FieldInfo!(int, 
"x").FieldInfo(Nullable!int argDefault = Nullable!argT())`
/tmp/temp_7F58BE2F0150.d(16,20): Error: template instance 
`runnable.processFields!(int, "x")` error instantiating


LDC - the LLVM D compiler (1.11.0):
  based on DMD v2.081.2 and LLVM 6.0.1