Boost logo

Boost :

Subject: Re: [boost] Request For a feature - Templated virtual functions
From: Gokulakannan Somasundaram (gokul007_at_[hidden])
Date: 2009-02-12 07:33:23

On Thu, Feb 12, 2009 at 4:00 PM, Mathias Gaunard <
mathias.gaunard_at_[hidden]> wrote:

> Gokulakannan Somasundaram wrote:
> Thanks for pointing me to Boost.Variant. But let me just try to clarify my
>> understanding on Boost Variant. It is a kind of union data type, where we
>> store the data and its type together. Whenever we retrieve the data, it
>> does
>> a switch-case lookup and type-casts the data to that type. In my opinion,
>> the switch-case is equivalent to a virtual table lookup. They should be
>> having more or less the same runtime penalty.
> Indeed.
> A switch-case is actually faster than a virtual table lookup, however.
> I did a small test in my system and the virtual function method proved to
be slightly better than using boost::variant. The difference can be ignored,
but then there is no use in switching to boost::variant. The method i
suggest is simple, it just replaces the virtual function overloading with
templates and hence it would provide better performance and better


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