Sunday, 11 August 2013

Is there a macro-based adapter to make a functor from a class?

Is there a macro-based adapter to make a functor from a class?

Creating a functor requires an unnecessary boiler plate. The state has to
be written 4 times!
struct f{
double s; // 1st
f(double state): s(state) {} // 2nd, 3rd and 4th
double operator() (double x) {
return x*s;
}
};
is there a library with a macro that would be just double
functor(state)(x){ return x*state; } or something similar.
BOOST_FOREACH is a macro adapter that works well. I'm looking for
something similar.
any suggestions on how to write one is appreciated too.
ps. using struct for functor is faster then bind Class's operator() or
bind a function as a functor?

No comments:

Post a Comment