
On 20.02.2010 14:09, strasser@uni-bremen.de wrote:
Hi,
is there interest in a boost utility to implement (pseudo-) virtual function templates?
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:
struct base : enable_vtemplate<derived1,derived2>{ template<class OutputIterator> void f(OutputIterator it){ BOOST_VTEMPLATE(f,(OutputIterator),(it)); it << "not overridden\n"; } BOOST_SUPPORT_VTEMPLATE(); };
struct derived1 : base{ template<class OutputIterator> void f(OutputIterator it){ it << "derived1\n"; } BOOST_SUPPORT_VTEMPLATE(); };
struct derived2 : base{ template<class OutputIterator> void f(OutputIterator it){ it << "derived2\n"; } BOOST_SUPPORT_VTEMPLATE(); };
the runtime overhead besides the virtual call is one switch().
Interesting. I had a need in such a thing a couple of times. Is the code available somewhere?