$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] virtual function templates
From: strasser_at_[hidden]
Date: 2010-02-20 08:49:41
Zitat von Mathias Gaunard <mathias.gaunard_at_[hidden]>:
>> real virtual function templates are obviously not possible without  
>> a JIT-compiler
>
> Wrong, you would just need to do link-time template instantiation,  
> which is actually required by the C++ standard (but few implement  
> it, and none had the idea to use it to implement virtual template  
> functions as an extension).
right, probably because it wouldn't work across DLLs.
>
>
>> but if all derived types are known to the base type,
>
> Then you might as well use Boost.Variant.
it is similar from an implementation viewpoint, but the interface is  
vastly different.
take e.g. a base class with a number of virtual functions
struct A{
   virtual void f();
   virtual void g();
};
and then you'd want to add a template parameter to one of them. this  
would require you to refactor every use of class A to use  
Boost.Variant visitors.
not an option imho.
>
>
>> the runtime overhead besides the virtual call is one switch().
>
> It should be possible to be just a switch and no virtual call.
if you store the index of the most derived class in the base class, yes.
but construction is more difficult that way, and my example also  
requires that every vtemplate is overwritten in a derived class. if  
you extend this so that functions can be optionally overwritten (like  
any regular virtual function) you'd have to store an index for each  
vtemplate function.