Boost logo

Boost :

From: Ruslan Zasukhin (sunshine_at_[hidden])
Date: 2002-06-27 01:27:47

on 6/27/02 3:50, Andrei Alexandrescu at andrewalex_at_[hidden] wrote:

> "Douglas Gregor" <gregod_at_[hidden]> wrote in message
> [snip]
> An idea just occured to me. Storing the pseudo-vtable as an integral index
> instead of a pointer to a table of functions has a nice fringe benefit:
> given a Variant object, we can easily and efficiently retrieve its index in
> the typelist. This in turn would help implementing switch-on-type
> efficiently in both library and client code, something like:
> typedef Variant<TYPELIST_3(int, double, string)> Field;
> Field fld;
> switch (fld.TypeIndex())
> {
> case Field::tag<int>::result:
> // it's an int!
> break;
> case Field::tag<double>::result:
> // it's a double!
> break;
> case Field::tag<string>::result:
> // it's a string!
> break;
> default:
> // it's a boy!
> }
> Of course, you can just as well use 0, 1, 2, instead of
> Field::tag<xxx>::result, but the formulation above is more resilient in face
> of changing the typedef.
> So I guess this would be the second useful change to Variant.

Hi Andreas,

It seems you work on HOW to convert one variant value into other,
And you going to have for this switch( type ) that will have probably about
10-15 cases.

In the book "C++ for Real Programmers" of Jeff Alger is described trick
Double Dispatch. It is more effective than switch. It is based on vtable

Best regards,
Ruslan Zasukhin              [ I feel the need...the need for speed ]
Valentina is cross-platform, fantastic fast database engine, supports
C/C++, Java, SQL, REALbasic, Director, XCMD, COM, Visual BASIC, ...

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