#include <cstdio> #include <type_traits> // nobody is foo template <typename T> struct IsFoo { static const bool value = false; }; // ... except for `double` template <> struct IsFoo<double> { static const bool value = true; }; // ... and `int` template <> struct IsFoo<int> { static const bool value = true; }; //---------------------------------------------------- template <typename T> typename std::enable_if<IsFoo<T>::value, void>::type print(const T &) { std::printf("Is foo\n"); } template <typename T> typename std::enable_if<! IsFoo<T>::value, void>::type print(const T &) { std::printf("Is not foo\n"); } int main() { print(false); print('c'); print(42); print(1.2f); print(1.2); } |