On Saturday, 7 November 2015 at 15:04:41 UTC, maik klein wrote:
template IsSame(T){
  template As(alias t){
    enum As = is(T : typeof(t));
  }
}
void main()
{
  int i;
  enum b = IsSame!int.As!(i);
}

Err:

Error: template instance As!(i) cannot use local 'i' as parameter to non-global template As(alias t) dmd failed with exit code 1
I don't understand the error message.

I also tried

template IsSame(T){
  enum As(alias t) = is(T : typeof(t));
}

Which results in

Error: template app.IsSame!int.As cannot deduce function from argument types !()(int), candidates are: source/app.d(50,8):
app.IsSame!int.As(alias t)

What am I doing wrong?

Ps: Also posted on SO https://stackoverflow.com/questions/33584130/cannot-use-local-i-as-parameter-to-non-global-template not sure where people usually ask questions about D.

Two ways to go about doing this

template IsSame(T,U)
{
     enum IsSame = is(T : U)
}

or make i a "global" by using a template
alias Identity(T) = T;

 template IsSame(T){
   enum As(alias t) = is(T : typeof(t));
}

enum b = IsSame!int.As!Identity!(i);

Reply via email to