Something like ADL from C++?
Arafel
er.krali at gmail.com
Fri Dec 6 07:59:53 UTC 2024
On 6/12/24 2:18, Richard (Rikki) Andrew Cattermole wrote:
> We do not have runtime reflection. We cannot copy languages that do,
> including for your example that isn't an alternative to runtime reflection.
>
> ```d
> interface ISerialize {
> void serialize();
> }
>
> class SerializableRoot {
> void serialize() {
> // serialize here
> }
> }
>
> class MyType : SerializableRoot {
> @thing int field;
>
> ...
> }
> ```
>
> Some how SerializableRoot.serialize has to be able to see the child
> MyType class. We have no good way of handling that currently.
```d
import std;
interface ISerialize {
void serialize();
}
struct thing{ }
class SerializableRoot {
void serialize(this T)() {
// serialize here, possibly using __traits to introspect on T
writeln("Serializing ", typeid(T));
}
}
class MyType : SerializableRoot {
@thing int field;
}
void main() {
MyType c = new MyType;
c.serialize;
}
```
More information about the Digitalmars-d
mailing list