I'm coding on a project which makes heavy use of curried objects and templates. The new decltype
feature of c++11 means that I could start accepting function objects that do not explicitly define a return type as the curry for my function objects. Instead, the return type could be extracted with a meta function such as:
template<typename func_T, typename arg1_T>
struct unary_result {
typedef typename std::remove_reference<std::remove_cv<decltype(func_T()(arg1_T()))>::type>::type type;
};
Given a function object:
struct foo {
int operator()(double) const;
};
(which does not inherit from std::unary_function<double, int>
or define its result_type
), I could just get it as unary_result<foo, double>::type
, which works out well in my current code (for one thing, it allows the same function object to have different behavior for different parameters).
My question is: how would this interact with function pointers?
I am aware that STL is able to use function objects and function pointers interchangeably, but have never actually worked with function pointers, so my intuitions are not very well developed in this area. I am also aware that this might be something that is buried somewhere in Boost already (I'm sure someone will point that out very soon if this is the case).
No comments:
Post a Comment