I have
template<typename DistanceFunc>
class C
{
using DistanceType = // the return type from DistanceFunc
public:
C(DistanceType distance, DistanceFunc f)
: m_distance(distance),
m_f(f)
{}
private:
DistanceType m_distance;
DistanceFunc m_f;
};
How do I derive the return type from DistanceFunc for DistanceType?
Another solution could be use template specialization.
You can declare
Cas receiving atypename, without defining itThen you can define a specialization of C receiving a (pointer to) function type as follows
As you can see the function type is resolved as a return type and the types of the arguments. Now
DistanceTypeis simply deduced (as return type) and you have to recreateDistanceFunc.You can use it as follows
Starting from C++17 you can also add a deduction guide
so you can declare a
Cobject simply as