|
Boost Users : |
From: Olaf Peter (ope-devel_at_[hidden])
Date: 2008-04-09 14:39:26
Hi,
I've wrapped a variant<double,bool> 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?
I guess, inside the variant_print I have to use the vistor to dispatch
the print functors, isn't?
BTW, fusion could be used? On debian/linux 1.35 is not released yet, so
I use 1.34.1.
Thanks,
Olaf
---8<---
#include <boost/variant.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_io.hpp>
#include <iostream>
struct pretty_print
{
pretty_print( double d ) : m_d( d ) { }
std::ostream& print_on( std::ostream& os ) const
{
os << m_d;
return os;
}
double m_d;
};
std::ostream& operator<<( std::ostream& os, const pretty_print& p )
{
return p.print_on( os );
}
struct variant_print
{
// ?????????
variant_print(::boost::variant<double, bool>& v)
{ }
};
using namespace std;
using namespace boost::tuples;
using namespace boost;
int main()
{
typedef variant<double, bool> double_variant;
typedef tuple<double_variant> double_tuple;
double_tuple v1;
double_tuple v2;
get<0>( v1 ) = 3.14;
get<0>( v2 ) = true;
// This works
cout << pretty_print( get<double>( get<0>( v1 ) ) ) << endl;
// This not
cout << variant_print( get<0>( v1 ) ) << endl;
}
--->8---
$ LANG=en g++ -Wall tuple.cpp -o tuple && ./tuple
tuple.cpp: In function 'int main()':
tuple.cpp:55: error: no match for 'operator<<' in 'std::cout <<
variant_print(((boost::variant<double, bool,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_,
boost::detail::variant::void_>&)((boost::variant<double, bool,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_,
boost::detail::variant::void_>*)boost::tuples::get [with int N = 0, HT =
boost::variant<double, bool, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_>, TT =
boost::tuples::null_type](((boost::tuples::cons<boost::variant<double,
bool, boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>,
boost::tuples::null_type>&)(&
v1.boost::tuples::tuple<boost::variant<double, bool,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type>::<anonymous>))))))'
...
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