Automatic return type covariance for functions that return this?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Sep 15 15:11:26 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; }
> }
Btw I think that's a dynamic cast, unless the compiler can optimize it
(I mean it should since it's a template function right?). I saw this
static cast thingy laying around somewhere:
auto static_cast(T,U)(U source)
{
return cast(T)(cast(void*)source);
}
More information about the Digitalmars-d-learn
mailing list