1 | // Copyright 2021, 2022 Peter Dimov. |
2 | // Distributed under the Boost Software License, Version 1.0. |
3 | // http://www.boost.org/LICENSE_1_0.txt |
4 | |
5 | #include <boost/system/error_code.hpp> |
6 | #include <boost/system/error_condition.hpp> |
7 | #include <boost/core/lightweight_test.hpp> |
8 | #include <boost/config/pragma_message.hpp> |
9 | #include <boost/config.hpp> |
10 | #include <boost/config/workaround.hpp> |
11 | |
12 | #if defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY) |
13 | |
14 | BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY is defined" ) |
15 | int main() {} |
16 | |
17 | #else |
18 | |
19 | #include <system_error> |
20 | |
21 | namespace sys = boost::system; |
22 | |
23 | enum my_errc |
24 | { |
25 | enomem_c = ENOMEM |
26 | }; |
27 | |
28 | enum my_errn |
29 | { |
30 | enomem_n = ENOMEM |
31 | }; |
32 | |
33 | namespace std { |
34 | |
35 | template<> struct is_error_code_enum<my_errc> |
36 | { |
37 | static const bool value = true; |
38 | }; |
39 | |
40 | template<> struct is_error_condition_enum<my_errn> |
41 | { |
42 | static const bool value = true; |
43 | }; |
44 | |
45 | } // namespace std |
46 | |
47 | std::error_code make_error_code( my_errc e ) |
48 | { |
49 | return std::error_code( e, std::generic_category() ); |
50 | } |
51 | |
52 | std::error_condition make_error_condition( my_errn e ) |
53 | { |
54 | return std::error_condition( e, std::generic_category() ); |
55 | } |
56 | |
57 | int main() |
58 | { |
59 | sys::error_code ec = make_error_code( e: sys::errc::not_enough_memory ); |
60 | sys::error_condition en( sys::errc::not_enough_memory ); |
61 | |
62 | BOOST_TEST_EQ( ec, en ); |
63 | BOOST_TEST_EQ( en, ec ); |
64 | |
65 | BOOST_TEST_EQ( ec, enomem_c ); |
66 | BOOST_TEST_EQ( enomem_c, ec ); |
67 | |
68 | BOOST_TEST_EQ( ec, enomem_n ); |
69 | BOOST_TEST_EQ( enomem_n, ec ); |
70 | |
71 | BOOST_TEST_EQ( en, enomem_c ); |
72 | BOOST_TEST_EQ( enomem_c, en ); |
73 | |
74 | #if BOOST_WORKAROUND(BOOST_MSVC, == 1800) |
75 | |
76 | // msvc-12.0 has op== as a member of std::error_condition |
77 | |
78 | #else |
79 | |
80 | BOOST_TEST_EQ( en, enomem_n ); |
81 | |
82 | #endif |
83 | |
84 | BOOST_TEST_EQ( enomem_n, en ); |
85 | |
86 | return boost::report_errors(); |
87 | } |
88 | |
89 | #endif |
90 | |