使用简单的SFINE来整理模板函数应该被实例化的类型。
// variable template for sorting out the allowed types
template<typename Type>
static constexpr bool is_allowed = std::is_same_v<Type, int> ||
std::is_same_v<Type, double> ||
std::is_same_v<Type, Eigen::VectorXd>
/* add other types which needed to be included */;
// type traits for sorting out the allowed types
template<typename T, typename U, typename ReType = void>
using enable_for_allowed_types = std::enable_if_t<
is_allowed<T> && is_allowed<U>,
ReType
>;
template<typename T, typename U>
auto normalise(T first, U second)
-> enable_for_allowed_types<T, U, decltype(first*second)>
{
return first * second;
}