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?
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
#include
#include
#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& v)
{ }
};
using namespace std;
using namespace boost::tuples;
using namespace boost;
int main()
{
typedef variant double_variant;
typedef tuple 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&)((boost::variant*)boost::tuples::get [with int N = 0, HT =
boost::variant, TT =
boost::tuples::null_type](((boost::tuples::cons,
boost::tuples::null_type>&)(&
v1.boost::tuples::tuple,
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>))))))'
...