Virtual templated functions. Previously: Preserving const? -- A potential solution

Michel Fortin michel.fortin at michelf.com
Sun Mar 8 14:37:46 PDT 2009


On 2009-03-08 08:16:42 -0400, "Tim M" <a at b.com> said:

> I remember you blogging about a way of compiling base classes with new  
> methods and not needing to recompile the sub classes, I will read up on 
>  those genrics in C# and java later. If that doesn't work out, what if 
> the  compiler could check for all sub class functions within the same 
> module  and allowing a sort of limited virtual template functions, so 
> no work  through external libraries. I would prefer limited virtual 
> over no virtual.

Well, if you add a way to dynamically insert methods into objects, as I 
was indeed proposing on my blog, the only missing step is to compile 
the template at first use and insert it into the virtual table. But 
that would require a compiler in the runtime and preservation of the 
template source and its related types (perhaps as bytecode).

What I was proposing in the post you quoted doesn't require anything 
special in the runtime or the language other than the ability to impose 
restrictions about what a template can do in a virtual function to make 
sure that, whatever the template arguments, it always emit the same 
code. That'd work for return values using the same constness as an 
argument; it'd also work for making return values being of the same 
class as an argument when your function expect a base class.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list