Something like ADL from C++?
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Thu Dec 5 21:58:14 UTC 2024
On 06/12/2024 8:07 AM, Derek Fawcus wrote:
> It is using run time reflection, but I see no obvious reason why compile
> time reflection could not be used instead, since that is what D has.
I said this over in ideas, but the problem isn't controlling
serialization, but the entry point into it.
Ideal:
```d
class Parent {
void serialize() {
// An implementation based upon typeof(this) goes here,
// currently this could only be Parent
}
}
class Child : Parent {
}
```
How it has to be implemented today to work:
```d
class Parent {
abstract void serialize();
protected void serialize_(T:Parent)(T self) {
}
}
class Child : Parent {
void serialize() {
super.serialize_(this);
}
}
```
If you are forcing users of a parent class to add the call explicitly
into the parent, its a major pain that other languages simply do not
have. Not to mention easily forgotten.
This is what my attribute that I said I'm thinking about
``@reinterptAsChild`` would solve.
More information about the Digitalmars-d
mailing list