
I'm traveling, so won't be able to get back on this before Tuesday. Regards Hartmut --------------- Meet me at BoostCon www.boostcon.com
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Ravi Sent: Saturday, April 03, 2010 8:22 PM To: boost-users@lists.boost.org Subject: [Boost-users] [spirit][karma+phoenix] Show result of member function
Hi, How can karma be used to show the result of applying a member function to objects in a container? Consider the following code (which does not compile) to show the real and the imaginary parts of complex numbers stored in a vector:
--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<- - #include
#include #include #include #include <complex> #include <iostream> #include <vector>
namespace test {
template <typename Container> void show_container( const Container &ctr ) { typedef typename Container::value_type complex_t; typedef typename complex_t::value_type real_t; const real_t& ( complex_t::*real_func )() const = &complex_t::real; const real_t& ( complex_t::*imag_func )() const = &complex_t::imag;
namespace karma = boost::spirit::karma; namespace phoenix = boost::phoenix;
std::cout << karma::format( ( karma::double_[ // What goes here to extract the real part? karma::_1 = phoenix::bind( real_func, karma::_val ) ] << ',' << karma::double_[ karma::_1 = phoenix::bind( imag_func, karma::_val ) ] ) % karma::eol, ctr ); }
} // namespace test
int main( int, char *[] ) { std::vector< std::complex<double> > vec( 5 ); test::show_container( vec ); return 0; } --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<- -
The issue is that "karma::_1 = phoenix::bind( real_func, karma::_val )" seems unacceptable to the compiler (gcc 4.4.3, boost 1.42, Linux x86_64). The example above is a simplified version of much more complex code.
Regards, Ravi
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users