Turns out you can pretty easily spoof a (limited to templated class scope)
`Self` type similar to what appears in Rust through a bit of template
tomfoolery, which I think is really neat and probably already known but I'm
happy about it so :3
Since a base class' templates are resolved effectively "inside" the derived
class, you can have a template default argument like `typename Self = [:
std::meta::current_class() :]` and have it properly resolved to the derived
class. There are some actually useful applications of this, such as for an
object whose methods are intended for chaining, that also inherits from
another class to avoid rewriting similar code, without having to suffer
through casts and pointers along the way. I realized this while messing
around with creating a Java-like factory for annotations, which in and of
itself is already kind of a crime but I like me some good ol'
abstraction, bite me.
Anyway, made a quick example on godbolt and I think it's neat so I wanna
share it:
https://godbolt.org/z/K3zr1o6f3

Is it really necessary to send this to a mailing list? Probably not, it's
certainly not gcc dev focused, but I'm kinda proud of figuring it out so I
wanna brag a tiny bit, sorta like a kid finding a cool rock.

- October

Reply via email to