Boost logo

Boost Users :

From: Bruno Martínez (br1_at_[hidden])
Date: 2005-11-28 18:05:45


On Mon, 28 Nov 2005 19:20:23 -0200, Merrill Cornish
<merrill.cornish_at_[hidden]> wrote:

> 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.

Search the documentation for get(), which() and type().

Bruno


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