fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template <typename T, typename Enable=void>
  7. struct foo {
  8. void operator()() const { cout << "unspecialized" << endl; }
  9. };
  10.  
  11. template <typename T>
  12. struct foo<T, enable_if_t<
  13. is_integral<T>::value
  14. >>{
  15. void operator()() const { cout << "is_integral" << endl; }
  16. };
  17.  
  18. template <typename T>
  19. struct foo<T, enable_if_t<
  20. sizeof(T) == 4
  21. and not is_integral<T>::value
  22. >>{
  23. void operator()() const { cout << "size 4" << endl; }
  24. };
  25.  
  26. template <typename T>
  27. struct foo<T, enable_if_t<
  28. is_fundamental<T>::value
  29. and not (sizeof(T) == 4)
  30. and not is_integral<T>::value
  31. >>{
  32. void operator()() const { cout << "fundamental" << endl; }
  33. };
  34.  
  35. int main() {
  36. foo<int>()();
  37. foo<float>()();
  38. foo<double>()();
  39. foo<vector<int>>()();
  40. }
  41.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
is_integral
size 4
fundamental
unspecialized