
Zitat von joel falcou <joel.falcou@lri.fr>:
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@gmail.com>:
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{ protected: typedef mpl::vector<T1,...> vtemplate_types; virtual std::size_t vtemplate_index() = 0; }; #define BOOST_SUPPORT_VTEMPLATE(T) \ virtual std::size_t vtemplate_index(){ //return index of T in vector vtemplate_types } #define BOOST_VTEMPALTE(F,TARGS,ARGS) \ switch(this->vtemplate_index()){ case 0: return static_cast<T1 *>(this)->template F<TARGS>(ARGS); ... }