2
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?

das-g
  • 9,718
  • 4
  • 38
  • 80
Maik Klein
  • 15,548
  • 27
  • 101
  • 197

1 Answers1

1

In dmd 2.069.0 and dmd 2.065, it works fine when i is global:

import std.stdio;

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

int i;

void main()
{
  bool b = IsSame!int.As!(i);
  writeln(b); // true
}

The documentation for template alias parameters claims these allow the template to be parameterized with local names, too, but fails to provide an example on how to do that:

Alias parameters enable templates to be parameterized with any type of D symbol, including global names, local names, module names, template names, and template instance names. Literals can also be used as arguments to alias parameters.

(emphasis mine)

das-g
  • 9,718
  • 4
  • 38
  • 80