Boost logo

Boost :

From: Andrei Alexandrescu (andrewalex_at_[hidden])
Date: 2002-06-26 19:50:57

"Douglas Gregor" <gregod_at_[hidden]> wrote in message

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!
case Field::tag<double>::result:
    // it's a double!
case Field::tag<string>::result:
    // it's a string!
    // 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.

Andrei the mischievous one

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