template <typename T, typename K, typename R,
typename = typename std::enable_if<std::is_arithmetic<T>::value &&
std::is arithmetic<K>::value &&
std::is_arithmetic<R>::value>::type>
R safe_division(T dividend, K divisor, R result)
{
return fabs(divisor) > 0.000001 ? dividend / divisor : result;
}
int main()
{
auto a = safe_division(2.0,0,1.1);|
cout << a << endl;
}
C++模板SFINA
最新推荐文章于 2024-08-09 10:25:03 发布