Boost logo

Boost :

Subject: Re: [boost] virtual function templates
From: strasser_at_[hidden]
Date: 2010-02-20 06:49:26

Zitat von joel falcou <joel.falcou_at_[hidden]>:
>> real virtual function templates are obviously not possible without
>> a JIT-compiler, but if all derived types are known to the base
>> type, something like the following is. I've used a non-generic form
>> of this a couple of times:
> I'm a bit amiss on how is this different from Polymorphic Function
> Obejct, aka Callable Entity with template operator() ?

I've never used Fusion.Functional but at first sight I can't even
figure out what they have in common.

the code I tried to emulate, if C++ had runtime generics, is the following:

struct base{
   template<class OutputIterator>
   virtual void f(OutputIterator);

struct derived : base{
   template<class OutputIterator>
   virtual void f(OutputIterator);

base *b=new derived;
b->f(...); //calls derived::f

how do you do something like that with Polymorphic Function Objects?

Zitat von Andrey Semashev <andrey.semashev_at_[hidden]>:
> Interesting. I had a need in such a thing a couple of times. Is the
> code available somewhere?

I have no generic implementation. what it could look like(pseudo-code):

template<class T1,...>
class enable_vtemplate{
   typedef mpl::vector<T1,...> vtemplate_types;
   virtual std::size_t vtemplate_index() = 0;

   virtual std::size_t vtemplate_index(){
     //return index of T in vector vtemplate_types

     case 0: return static_cast<T1 *>(this)->template F<TARGS>(ARGS);

Boost list run by bdawes at, gregod at, cpdaniel at, john at