I know how to use template in C++ but can't understand the code below, especially the last line. It's a operator * overloading for half-precision type. Could someone explain this to me? (Here detail
is a namespace)
/// SFINAE helper for generic half-precision functions.
/// This class template has to be specialized for each valid combination of argument types to provide a corresponding
/// `type` member equivalent to \a T.
/// \tparam T type to return
template<typename T,typename,typename=void,typename=void> struct enable {};
template<typename T> struct enable<T,half,void,void> { typedef T type; };
template<typename T> struct enable<T,expr,void,void> { typedef T type; };
template<typename T> struct enable<T,half,half,void> { typedef T type; };
template<typename T> struct enable<T,half,expr,void> { typedef T type; };
template<typename T> struct enable<T,expr,half,void> { typedef T type; };
template<typename T> struct enable<T,expr,expr,void> { typedef T type; };
template<typename T> struct enable<T,half,half,half> { typedef T type; };
template<typename T> struct enable<T,half,half,expr> { typedef T type; };
template<typename T> struct enable<T,half,expr,half> { typedef T type; };
template<typename T> struct enable<T,half,expr,expr> { typedef T type; };
template<typename T> struct enable<T,expr,half,half> { typedef T type; };
template<typename T> struct enable<T,expr,half,expr> { typedef T type; };
template<typename T> struct enable<T,expr,expr,half> { typedef T type; };
template<typename T> struct enable<T,expr,expr,expr> { typedef T type; };
.... some codes ...
template<typename T> typename detail::enable<half&,T>::type operator*=(T rhs) { return *this *= static_cast<float>(rhs); }
I understand there are different types of struct enable for different template pairs. But what does the struct enable declarations do above? Is it defining a type inside the structure?(so that that type
has type T inside the sturct?) and in the template specifier, what does for example mean? I don't know what expr here is. Is it a type or does it have special meaning?