Boost logo

Boost Users :

From: Merrill Cornish (merrill.cornish_at_[hidden])
Date: 2005-11-28 16:20:23


If I have a boost::variant variable holding either of two types,
is there a simple test to determine which type it is currently
holding?

Yes, I know that the object-oriented way to to avoid testing for
types at runtime, but a simple if-test would work very well in
the code.

I've seen the static_visitor example, and that would work, but
it hides the type determination and type-specific actions inside
another class (or at least other functions). Yes, that would work
logically, but the code needing to make this determination would
be much clearer is written simply as a if-the-else based on the
current type of the variant variable.

Merrill


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net