is_error_condition_enum.pass.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03, c++11, c++14
  9. // <system_error>
  10. // template <class T> constexpr bool is_error_condition_enum_v;
  11. #include <system_error>
  12. #include <type_traits>
  13. #include "test_macros.h"
  14. template <bool Expected, class T>
  15. void
  16. test()
  17. {
  18. static_assert((std::is_error_condition_enum<T>::value == Expected), "");
  19. #if TEST_STD_VER > 14
  20. static_assert((std::is_error_condition_enum_v<T> == Expected), "");
  21. #endif
  22. }
  23. class A {
  24. A();
  25. operator std::error_condition () const { return std::error_condition(); }
  26. };
  27. // Specialize the template for my class
  28. namespace std
  29. {
  30. template <>
  31. struct is_error_condition_enum<A> : public std::true_type {};
  32. }
  33. int main(int, char**)
  34. {
  35. test<false, void>();
  36. test<false, int>();
  37. test<false, std::nullptr_t>();
  38. test<false, std::string>();
  39. test<true, A>();
  40. return 0;
  41. }