I am trying to infer the return type of the called type, i.e. pointer to a function or functor.
Earlier, I asked and received an answer showing how to do this for function pointers with hints for how to do this for functors.
Type inference of return type in C ++ 03
Based on this, I have this helper structure, which now works for functors, but no longer works for function pointers.
template<class T>
struct Return;
{
typedef typename T::result_type type;
};
template<class R>
struct Return<R (*)()>
{
typedef R type;
};
This works for interacting functors that provide a result_typetypedef, but not for function pointers. clang gives the following:
error: type 'int (*) (int)' cannot be used before '::' because it has no members
typedef typename T::result_type type;
, SFINAE, Return.
, , .
http://coliru.stacked-crooked.com/a/53f4c8c90787e329
.
"" , function() ++ 98
, std::vector std::vector . , . :
template<typename F, typename T>
typename expr_check<sizeof(declval<F>()(declval<T>())), std::vector<T> >::type
map_vec(F fnc, const std::vector<T>& source)
F , T , F, std::vector<T>. . declval.
, , C. , T F , . :
template<typename F, typename C>
typename expr_check<sizeof(declval<F>()(declval<int>())),
std::vector<typename Return<F>::type> >::type
map_vec(F fnc, const C& source);