
Hi,
I've wrapped a variant

On Wed, 09 Apr 2008 20:39:26 +0200
Olaf Peter
Hi,
I've wrapped a variant
into a tuple. Unpacking the tuple works as far I can see. I want to print the tuple for doubles with one pretty print functor and for booleans with another functor (not shown here). Anyway, variant_print takes a long argument list as the error message shows. How can I pass it convinient?
This is the type of your variant. The first two are double and bool, the rest are placeholders that would be replaced if your variant held more types.
I guess, inside the variant_print I have to use the vistor to dispatch the print functors, isn't?
That's basically how I'd do it. I've modified your example to demonstrate this:
---8<---
#include

Thank you Jeffrey.
typedef boost::variant
double_variant; typedef boost::tuple double_tuple; ... std::ostream& operator<<( std::ostream& os, const double_variant& p ) { output_visitor out_v(os); boost::apply_visitor(out_v,p); return os; } ...
This works, but is there a generic way without global typedefs? Thanks, Olaf

On Thu, 10 Apr 2008 07:21:08 +0200
Olaf Peter
Thank you Jeffrey.
typedef boost::variant
double_variant; typedef boost::tuple double_tuple; ... std::ostream& operator<<( std::ostream& os, const double_variant& p ) { output_visitor out_v(os); boost::apply_visitor(out_v,p); return os; } ... This works, but is there a generic way without global typedefs?
You don't have to use the typedefs. Just replace double_variant with boost::variant

Thank you Jeffrey.
typedef boost::variant
double_variant; typedef boost::tuple double_tuple; ... std::ostream& operator<<( std::ostream& os, const double_variant& p ) { output_visitor out_v(os); boost::apply_visitor(out_v,p); return os; } ... This works, but is there a generic way without global typedefs?
You don't have to use the typedefs. Just replace double_variant with boost::variant
and double_tuple with boost::tuple . Is that what you were asking?
Yep, after reading this, it was so clear ;-) Thanks, Olaf
participants (2)
-
Jeffrey A. Edlund
-
Olaf Peter