
On Sunday, March 27, 2011 12:07:04 AM Steven Watanabe wrote:
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?
Thanks for the heads up. I can add the operator, for actor at all times, but keep it disabled (with a compile error) untile boost/phoenix/statement.hpp is included.
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.
Has this issue been resolved now? Looking at the test runner matrix the MSVC10 runner doesn't have problems like these. Maybe we should add a testcase for that ... Regards, Thomas