Getting around the non-virtuality of templates

Stewart Gordon smjg_1998 at yahoo.com
Tue Mar 27 08:26:08 PDT 2012


On 27/03/2012 16: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:
<snip>

Just figured how to do it.

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

Talk about having not got into D2 programming before....

Stewart.


More information about the Digitalmars-d mailing list