|
Boost : |
Subject: [boost] [phoenix] comma woes
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-03-26 19:07:04
AMDG
I was going to post a response to Lorenzo's question using phoenix,
but I ran into a few issues.
The initial version I wrote compiles, but doesn't work.
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
double sum = 0.0;
int factor = 10;
using namespace boost::phoenix;
using namespace boost::phoenix::placeholders;
std::vector<double> v(3);
v[0] = 1.0; v[1] = 2.0; v[2] = 3.0;
std::for_each(v.begin(), v.end(), (
ref(sum) += factor * _1,
ref(std::cout) << "Summed: " << ref(sum) << std::endl
));
return 0;
}
This is because the overloaded comma operator
is provided by statement.hpp, not operator.hpp as
I had erroneously assumed. Can we please make
sure that the built-in comma operator can't
get silently called?
After I added #include <boost/phoenix/statement.hpp>,
it still doesn't compile and I have no idea how to
make it compile, because it tries to copy std::cout.
I'm guessing that the result of the comma operator
is being deduced as a non-reference, since the
cout part compiles fine by itself.
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk