I am trying to update an abandoned open source library to C++11 and 17. It uses std::binary_function
and its result_type
in a way I am not sure how to remove. These features were deprecated in C++11 and removed in 17.
First, I've simply removed std::binary_function
(and std::unary_function
) from this.
Next, I'm unsure how to eliminate the use of result_type in places like this.
template<class R, int D, class F>
static Vector<typename F::result_type, D> apply(const F &func, const VRD &v)
{
Vector<typename F::result_type, D> out;
_apply(func, v, out);
return out;
}
I tried replacing Vector<typename F::result_type, D>
with auto
, but my compiler (currently set to C++11) complained that auto
for return types is introduced in C++14.
F
is a generic functor. How can I re-write the above code when I don't know what result_type
is?
Thanks for the suggestions, I was eventually able to get it to work. I did use C++17 features, so this version won't work on C++11.
The result is posted here. There ended up being a number of techniques required -- depending on whether result_type appeared as a return type, as an argument type, or as a variable type inside the function. Two of these were illustrated in the sample above.
The above example ends up looking like this...
template<class R, int D, class F>
static decltype(auto) apply(const F &func, const VRD &v)
{
Vector< decltype( func( v[0] ) ), D > out;
_apply(func, v, out);
return out;
}