Getting around the non-virtuality of templates

Artur Skawina art.08.09 at gmail.com
Tue Mar 27 08:25:21 PDT 2012


On 03/27/12 17:12, Stewart Gordon wrote:
> On 26/03/2012 14:37, Steven Schveighoffer wrote:
> <snip>
>> So for now, I use the undocumented old-style functions. One other thing that this
>> "wrapper" method loses is covariance, which I use a lot in dcollections. I haven't filed a
>> bug on it, but there is at least a workaround on this one -- the template can capture the
>> type of "this" from the call site as a template parameter.
> 
> I can't seem to get this to work at the moment:
> ----------
> class Base {
>     T method(T = typeof(this))() {
>         return this;
>     }
> }

class Base {
    T method(this T)() {
        return cast(T)this;
    }
}

artur


More information about the Digitalmars-d mailing list