c++ - Problems adapting member functions in Phoenix -
i use boost_phoenix_adapt_function
time in spirit. i'd able adapt member functions of same reason. however, compile errors if this:
struct { int foo(int i) { return 5*i; }}; boost_phoenix_adapt_function(int, afoo, &a::foo, 2)
is there easy way adapt member function? note can't store bind expression in auto
because on vc2008. how come doesn't work in bind
, function
?
thanks,
mike
the boost_phoenix_adapt_function(return,lazy_name,func,n)
is simple. creates functor templated operator()
returns return
, has n
template parameters. in body invokes func(parameters...)
. &a::foo
not directly callable, , error occurs. can use:
boost_phoenix_adapt_function(int,afoo,boost::mem_fn(&a::foo),2)
#include <iostream> #include <boost/phoenix.hpp> #include <boost/phoenix/function.hpp> #include <boost/mem_fn.hpp> struct { a(int f) : f_(f) {} int foo(int i) { return f_*i; } private: int f_; }; boost_phoenix_adapt_function(int,afoo,boost::mem_fn(&a::foo),2) int main() { using namespace boost::phoenix; using namespace boost::phoenix::arg_names; instance(5); std::cout << afoo(arg1,arg2)(&instance, 2) << std::endl; }
Comments
Post a Comment