How to get compatible symbol names and runtime typeid names for templated classes?

H. S. Teoh hsteoh at quickfur.ath.cx
Tue May 3 16:51:33 UTC 2022


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

-- 
Never step over a puddle, always step around it. Chances are that whatever made it is still dripping.


More information about the Digitalmars-d-learn mailing list