is_error_condition_enum.pass.cpp 1.2 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. // UNSUPPORTED: c++98, c++03, c++11, c++14
  10. // <system_error>
  11. // template <class T> constexpr bool is_error_condition_enum_v;
  12. #include <system_error>
  13. #include <type_traits>
  14. #include "test_macros.h"
  15. template <bool Expected, class T>
  16. void
  17. test()
  18. {
  19. static_assert((std::is_error_condition_enum<T>::value == Expected), "");
  20. #if TEST_STD_VER > 14
  21. static_assert((std::is_error_condition_enum_v<T> == Expected), "");
  22. #endif
  23. }
  24. class A {
  25. A();
  26. operator std::error_condition () const { return std::error_condition(); }
  27. };
  28. // Specialize the template for my class
  29. namespace std
  30. {
  31. template <>
  32. struct is_error_condition_enum<A> : public std::true_type {};
  33. }
  34. int main()
  35. {
  36. test<false, void>();
  37. test<false, int>();
  38. test<false, std::nullptr_t>();
  39. test<false, std::string>();
  40. test<true, A>();
  41. }