fork(1) download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <string>
  4. #include <cstdint>
  5.  
  6. template <typename... Ts>
  7. struct have_common_type
  8. {
  9. using yes = char[1];
  10. using no = char[2];
  11.  
  12. template <typename... Us>
  13. static yes& test(typename std::common_type_t<Us...>*);
  14.  
  15. template <typename...>
  16. static no& test(...);
  17.  
  18. static constexpr bool value = sizeof(test<Ts...>(nullptr)) == sizeof(yes);
  19. };
  20.  
  21. int main()
  22. {
  23. std::cout << have_common_type<int, std::uint32_t, char>::value << std::endl; // 1
  24. std::cout << have_common_type<int, bool, std::string>::value << std::endl; // 0
  25. return 0;
  26. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
1
0