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//
9// UNSUPPORTED: c++03
10
11// <system_error>
12
13// template <> struct is_error_code_enum<> : public false_type {};
14
15#include <cstddef>
16#include <string>
17#include <system_error>
18
19#include "test_macros.h"
20
21template <bool Expected, class T>
22void
23test()
24{
25 static_assert((std::is_error_code_enum<T>::value == Expected), "");
26#if TEST_STD_VER > 14
27 static_assert((std::is_error_code_enum_v<T> == Expected), "");
28 ASSERT_SAME_TYPE(decltype(std::is_error_code_enum_v<T>), const bool);
29#endif
30}
31
32class A {
33 A();
34 operator std::error_code () const { return std::error_code(); }
35};
36
37// Specialize the template for my class
38template <>
39struct std::is_error_code_enum<A> : public std::true_type {};
40
41int main(int, char**)
42{
43 test<false, void>();
44 test<false, int>();
45 test<false, std::nullptr_t>();
46 test<false, std::string>();
47
48 test<true, A>();
49
50 return 0;
51}
52

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of libcxx/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp