たまに使うのに調べてもパッと出てこなかったので自分用のメモ
test.cc
#include <iostream>
#include <type_traits>
using std::cout;
using std::endl;
template <class T,
typename std::enable_if<std::is_floating_point<T>::value, T>::type* = nullptr>
void func(T num){
cout << "This is a floating point number:" << num << endl;
}
template <class T,
typename std::enable_if<std::is_integral<T>::value, T>::type* = nullptr>
void func(T num){
cout << "This is an integer number:" << num << endl;
}
template <class T,
typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value, T>::type* = nullptr>
void func(T num){
cout << "This is neither integer nor floating number:" << num << endl;
}
int main(){
func(123);
func(123.);
func(123.f);
func("0x7B");
return 0;
}