is_error_code_enum.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // UNSUPPORTED: c++03
  11. // <system_error>
  12. // template <> struct is_error_code_enum<> : public false_type {};
  13. #include <system_error>
  14. #include <string>
  15. #include "test_macros.h"
  16. template <bool Expected, class T>
  17. void
  18. test()
  19. {
  20. static_assert((std::is_error_code_enum<T>::value == Expected), "");
  21. #if TEST_STD_VER > 14
  22. static_assert((std::is_error_code_enum_v<T> == Expected), "");
  23. #endif
  24. }
  25. class A {
  26. A();
  27. operator std::error_code () const { return std::error_code(); }
  28. };
  29. // Specialize the template for my class
  30. namespace std
  31. {
  32. template <>
  33. struct is_error_code_enum<A> : public std::true_type {};
  34. }
  35. int main()
  36. {
  37. test<false, void>();
  38. test<false, int>();
  39. test<false, std::nullptr_t>();
  40. test<false, std::string>();
  41. test<true, A>();
  42. }