Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit][karma+phoenix] Show result of member function
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2010-04-04 13:58:47


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_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of Ravi
> Sent: Saturday, April 03, 2010 8:22 PM
> To: boost-users_at_[hidden]
> 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 <boost/spirit/include/karma.hpp>
> #include <boost/spirit/include/phoenix_bind.hpp>
> #include <boost/spirit/include/phoenix_core.hpp>
> #include <boost/spirit/include/phoenix_operator.hpp>
>
> #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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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