[phoenix] Functions and function pointers

Hello all, How do I call functions and function pointers from within a Boost.Phoenix lambda function? For example: #include <boost/spirit/include/phoenix.hpp> #include <iostream> #include <vector> #include <algorithm> #include <cassert> #define N 1e4 #define S N * 1e2 const double& id(const double& x) { return x; } int main() { using boost::phoenix::ref; using boost::phoenix::arg_names::_1; double sum = 0.0; int factor = 1; const double& (*f)(const double&) = &id; std::vector<double> v(S); std::fill(v.begin(), v.end(), 1.0); for (size_t n = 0; n < N; ++n) { std::for_each(v.begin(), v.end(), ( ref(sum) += id(factor * f(_1)) // <<<<<<<<<<<<<< how do I call id(...) and f(...)? )); } std::cout << sum << std::endl; assert(sum == N * S); return 0; } Thank you very much. -- Lorenzo

On Thu, Apr 7, 2011 at 4:15 PM, Lorenzo Caminiti <lorcaminiti@gmail.com>wrote:
Hello all,
How do I call functions and function pointers from within a Boost.Phoenix lambda function?
[...] I think boost::phoenix::bind is your friend: http://www.boost.org/doc/libs/1_46_1/libs/spirit/phoenix/doc/html/phoenix/co... - Jeff
participants (2)
-
Jeffrey Lee Hellrung, Jr.
-
Lorenzo Caminiti