|
Boost : |
Subject: Re: [boost] virtual function templates
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2010-02-20 06:16:41
On 20.02.2010 14:09, strasser_at_[hidden] 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?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk