
On Fri, Jun 6, 2008 at 4:51 PM, Eric Niebler <eric@boost-consulting.com> wrote:
Daniel Walker wrote:
OK, but I was thinking more of user defined function objects. Something like ...
struct f_ { template<class> struct result { typedef void type; }; template<class T> void operator()(T& t) { ++t; } };
int main() { phoenix::function<f_> f; int i = 0; f(i);
That creates a lazy function invocation, but doesn't execute it.
Haha! Thanks.
assert(i == 1); }
Actually, I just tried this and the assertion failed. So, I assume user defined function objects are required to be "pure." Why is that?
#include <boost/phoenix/core.hpp> #include <boost/phoenix/operator.hpp> #include <boost/phoenix/function.hpp>
namespace phoenix = boost::phoenix;
struct f_ { template<class> struct result { typedef void type; }; template<class T> void operator()(T& t) { ++t; } };
int main() { using phoenix::arg_names::_1; phoenix::function<f_> f;
int i = 0; f(_1)(i); // OK assert(i == 1);
int j = 0; //f(j)(); // by value, doesn't compile //assert(j == 0);
f(phoenix::ref(j))(); // by ref, OK assert(j == 1); }
Very good! Thanks. I hate "pure" functions. ;-) Daniel Walker