#include <cstdio> // 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> void print(const T &value) { if (IsFoo<T>::value) { std::printf("Is foo\n"); } else { std::printf("Is not foo\n"); } } int main() { print(false); print('c'); print(42); print(1.2f); print(1.2); } |