
On 03/26/2011 04:46 PM, Steven Watanabe wrote:
AMDG
On 03/26/2011 04:27 PM, Michael Caisse wrote:
#include <boost/phoenix/phoenix.hpp> #include <boost/phoenix/statement.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, std::cout << "Summed: " << ref(sum) << "\n" ) ); return 0; }
This is incorrect. std::cout << "Summed: " is evaluated eagerly.
In Christ, Steven Watanabe
Sorry about that: std::cout << val("Summed: ") << ref(sum) << "\n" or one of the other possibilities will do fine. michael -- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com