Automatic return type covariance for functions that return this?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Sep 15 15:07:16 PDT 2012
On 9/15/12, Ben Davis <entheh at cantab.net> wrote:
> Never mind, I found the answer in the 'templates' page of the spec:
>
> class Super {
> T doStuff(this T)() { ...; return cast(T)this; }
> }
>
> Sub x = (new Sub()).doStuff();
>
> It seems a bit of a shame that I need the cast, but it's a small thing :)
Ah the template this solution, I always forget about that little
trick! Nicely done. :)
More information about the Digitalmars-d-learn
mailing list