On Tuesday, 3 May 2022 at 16:51:33 UTC, H. S. Teoh wrote:
On Tue, May 03, 2022 at 04:38:23PM +0000, cc via
Digitalmars-d-learn wrote:
On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote:
> class Base : Serializable!(Base) { ... }
> class Derived : Serializable!(Base, Derived) { ... }
This is really interesting syntax, I'm surprised that works!
https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
It's a bit counterintuitive at first, but once you "get" how it
works, it's an extremely powerful technique for leveraging D's
compile-time introspection capabilities. And translating
compile-time information into runtime using static this(). ;-)
T
Hm although I am having trouble with that particular
implementation:
```d
class Base : Serializable!(Base) {}
class Derived : Serializable!(Base, Derived) {}
class Serializable(Base, Derived = Base) : Base {}
```
```
Error: class `test.Base` circular inheritance
Error: template instance `test.Serializable!(Base, Base)` error
instantiating
```