Boost logo

Boost :

From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2008-03-29 00:19:34

Stefan Seefeld wrote:

> As I understand your request, you want to roll your own switch
> statement, but with more expressive values than simple numbers. In other
> words, you want a mapping from types to variant type discriminators:
> variant<A, B, C> v = ....;
> switch (v.which())
> {
> case v::type_id<A>::value: break;
> case v::type_id<B>::value: break;
> }

It seems you completely misunderstood. I absolutely do not want to do
such a thing.

As I already said, what I want to do has no relation with variant.
Variant is just an example of a library that does static visitation, and
that uses its own type identification mechanism instead of the one
bundled with C++.

What I want to do, is to provide visitation on top of the native C++
RTTI feature, with "naked" and unmodified polymorphic variables (which
are not in a variant or anything else that maintains its own additional
type identifier).

As the example I wrote demonstrated, as the title of the thread clearly
states, etc.

The switch was no example of interface: it was an example of how
visitation could be *implemented*.
Indeed, since RTTI is broken (it is not a constant expression), such
tricks are necessary to make things work.

The example of interface was after that.
Basically, providing an variant-like interface for polymorphic objects
that have already decayed.

> Certainly. But I haven't seen any good example on *what* I may want to
> compute on a string at compile-time. To me...

This thread just provided one possible good reason to do so.

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