How to find type boost::variant is holding?
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
On Mon, 28 Nov 2005 19:20:23 -0200, Merrill Cornish
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
participants (2)
-
Bruno MartÃnez
-
Merrill Cornish