// enable_if example: two ways of using enable_if
#include <iostream>
#include <type_traits>
// 1. 如果T是一个整数类型,则返回值类型为bool是有效类型:
template <class T>
typename std::enable_if<std::is_integral<T>::value, bool>::type
is_odd(T i) { return bool(i % 2); }
// 2. 第二个模板参数仅在 T 是整数类型时才有效
template <class T,
class = typename std::enable_if<std::is_integral<T>::value>::type>
bool is_even(T i) { return !bool(i % 2); }
int main()
{
short int i = 1; // code does not compile if type of i is not integral
std::cout << std::boolalpha;
std::cout << "i is odd: " << is_odd(i) << std::endl;
std::cout << "i is even: " << is_even(i) << std::endl;
return 0;
}