fork download
  1. #include <array>
  2. #include <iostream>
  3. #include <vector>
  4. #include <cstdint>
  5.  
  6. enum class Bar : uint8_t {
  7. ay, bee, see
  8. };
  9.  
  10. struct S {
  11.  
  12. static void foo() {}
  13.  
  14. // std::begin(h) is defined for h of type H
  15. template<typename H, typename... T>
  16. static typename std::enable_if<std::is_pointer<decltype(std::begin(std::declval<H>()))*>::value>::type
  17. foo(const H&, T&&... t)
  18. { std::cout << "container\n"; foo(std::forward<T>(t)...); }
  19.  
  20. // H is integral
  21. template<typename H, typename... T>
  22. static typename std::enable_if<std::is_integral<typename std::remove_reference<H>::type>::value>::type
  23. foo(const H&, T&&... t)
  24. { std::cout << "integer\n"; foo(std::forward<T>(t)...); }
  25.  
  26.  
  27. // H is an enum with underlying type = uint8_t
  28. #if 1
  29. template<typename H, typename... T>
  30. //static typename std::enable_if<std::is_same<typename std::underlying_type<H>::type,uint8_t>::value>::type
  31. static typename std::enable_if<std::is_enum<H>::value and (sizeof(H) == sizeof(uint8_t))>::type
  32. foo(const H&, T&&... t)
  33. { std::cout << "enum\n"; foo(std::forward<T>(t)...); }
  34. #endif
  35. };
  36.  
  37.  
  38. int main()
  39. {
  40. S::foo(std::array<int,8>(), 5, 5L, std::vector<int>{}, 5L);
  41. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
container
integer
integer
container
integer