Boost logo

Boost :

Subject: [boost] virtual function templates
From: strasser_at_[hidden]
Date: 2010-02-20 06:09:28


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().


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk