Dynamic templated virtuals - I still often want them
Arafel
er.krali at gmail.com
Wed Jul 29 13:37:22 UTC 2020
On 29/7/20 15:04, Alexandru Ermicioi wrote:
> imho, this feature can be lowered to code in example above, instead of
> generating new body for each derived class.
Sure, I was just making an example to show how it would work. I leave
the inner details on how it would be implemented to more knowledgeable
people than me :-)
Still, in your version, at the end of the day you're instantiating
anyway the template at each class, so the code will also be generated,
and even with an indirection (ok, it should be optimized / inlined).
Also it could be tricky with things such as attributes, etc.
One possible issue I see is what would happen with template-specific
features, like `auto ref`, that wouldn't be available in this case, for
instance:
```
class Base {
virtual foo(this This)(auto ref bar) { }
}
```
or if you use This as the type of a parameter:
```
class Base {
virtual foo(this This)(This bar) { }
}
class Derived : Base { }
void main() {
Base b = new Derived;
b.foo(new Base); // Fails to compile?
}
```
You could of course special-case the syntax to disable these cases, but
for the users it would be an unexpected outlier in how the templates work.
More information about the Digitalmars-d
mailing list