Bug 18732 – Can use template as type in a templatized class
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-04-05T08:28:57Z
Last change time
2018-04-06T20:43:21Z
Assigned to
No Owner
Creator
Basile-z
Comments
Comment #0 by b2.temp — 2018-04-05T08:28:57Z
---
class Foo(bool b)
{
// can use Foo without template param
static assert(__traits(compiles, new Foo)); // 1
// because
static assert(is(Foo == Foo!false));
}
void main()
{
Foo!false foo;
}
---
The Q is: is line before comment 1 accepted on purpose ?
Comment #1 by ag0aep6g — 2018-04-06T20:43:21Z
Working as intended.
class Foo(bool b) { .... }
is equivalent to
template Foo(bool b)
{
class Foo { ... }
}
https://dlang.org/spec/template.html#aggregate_templates
Inside the class, the name "Foo" refers to the class itself. To refer to the template, you have to use `.Foo`. However, you can use `Foo!false`, because the compiler is being nice. I don't know if that's in the spec, or if it's just a welcome quirk.
Closing as invalid. Feel free to reopen if I'm missing something here.