Is there a some more standard way of applying an argument to range of functions? I came up with solutions like the one listed below, but it feels wrong - out there should be something already for building such logic.
template<typename Function, typename Result, typename Argument>
struct apply_argument_t {
Argument x;
Result operator () (Function f) {
return f (x);
}
};
Thus a simple use case:
transform (in.begin(), in.end(), out.begin(), apply_argument(x));
I intentionally skipped implementation details.
Edit: But anyway, as they were asked for:
in
is a range of unary functions (e.g. vector<int(*)(char)>
)
out
is a range of these unary function's results (e.g. vector<int>
)
apply_argument
is like the structure but without the template specification and initialization (e.g. apply_argument_t<int(*)(char), int, char>
)
Also I missed the remark that a solution for C++11 is not searched.