1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <type_traits>
template <typename T>
typename std::enable_if<std::is_integral<T>::value, bool>::type
is_odd(T i) {
return i % 2 != 0;
}
int main() {
std::cout << "Is 5 odd? " << is_odd(5) << std::endl;
// std::cout << "Is 3.14 odd? " << is_odd(3.14) << std::endl; // This would cause a compile error
return 0;
}
Back to std_if_enable