On Thu, 17 Dec 2009 13:03:51 -0500, Bill Baxter <wbax...@gmail.com> wrote:

This 'auto ref' stuff and the multi-flavor 'vconst' functions are
basically templates with a known list of instantiations (ref /no-ref,
and const/immutable/plain)
In theory there's no reason you couldn't allow templates to also
create virtual functions, if you limit yourself to listing the
possible instantiations up front.

Technically, the vconst functions provide one other feature -- implicit casting back to the correct type. You can't support that with templates, and still have the compiler ensure const is obeyed during the function all with a function signature. Also, there is only ever a single vconst function, not 3^n overloaded ones.

But I agree with allowing a restricted template to be able to be virtual. One recent discussion that applies here is templatized operator overloading -- wouldn't it be nice if:

opBinary(op : "+")(T rhs) {...}

could be a virtual function? That gives us immediate support for virtual functions without the hoaky:

opBinary(op : "+")(T rhs) {return opAdd(rhs);}

mixin boilerplate.

(BTW, this was Denis Koroshin's idea, not mine)

-Steve

Reply via email to