Dynamic templated virtuals - I still often want them
Tove
tove at fransson.se
Fri Jul 24 21:04:56 UTC 2020
On Thursday, 23 July 2020 at 15:00:59 UTC, Max Samukha wrote:
>
> FWIW, a more general way to initialize an object with static
> type data would be (currently it fails for indirectly derived
> classes due to a compiler bug):
>
> class Base {
> this(this This)() {
> _serialize = function(Base base) {
> // base can be safely reinterpreted into This here
> if needed
>
> return This.stringof; // just for example
> };
> }
>
> final string serialize() {
> return _serialize(this);
> }
>
> private string function(Base) _serialize;
> }
>
> class Derived: Base {
> }
>
class GrandChild : Derived {}
Please file a bug/enhancement report that 'this(this This)()' in
Base doesn't work intuitively for GrandChild.
It would give a lot of expressive power with a very small
fix/change... small enough that it wouldn't require a DIP, at
least not in my opinion.
More information about the Digitalmars-d
mailing list