1 #ifndef BOOST_LEAF_TEST_EC_HPP_INCLUDED
2 #define BOOST_LEAF_TEST_EC_HPP_INCLUDED
4 // Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
6 // Distributed under the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 #include <system_error>
11 enum class errc_a { a0 = 10, a1, a2, a3 };
13 namespace std { template <> struct is_error_code_enum<errc_a>: true_type { }; }
15 inline std::error_category const & cat_errc_a()
17 class cat : public std::error_category
19 char const * name() const noexcept
23 std::string message(int code) const
25 switch( errc_a(code) )
27 case errc_a::a0: return "a0";
28 case errc_a::a1: return "a1";
29 case errc_a::a2: return "a2";
30 case errc_a::a3: return "a3";
31 default: return "error";
39 inline std::error_code make_error_code( errc_a code )
41 return std::error_code(int(code), cat_errc_a());
44 template <int> struct e_errc_a { std::error_code value; };
46 ///////////////////////////////////
48 enum class errc_b { b0 = 20, b1, b2, b3 };
50 namespace std { template <> struct is_error_code_enum<errc_b>: true_type { }; };
52 inline std::error_category const & cat_errc_b()
54 class cat : public std::error_category
56 char const * name() const noexcept
60 std::string message(int code) const
62 switch( errc_b(code) )
64 case errc_b::b0: return "b0";
65 case errc_b::b1: return "b1";
66 case errc_b::b2: return "b2";
67 case errc_b::b3: return "b3";
68 default: return "error";
76 inline std::error_code make_error_code( errc_b code )
78 return std::error_code(int(code), cat_errc_b());
81 template <int> struct e_errc_b { std::error_code value; };
83 ///////////////////////////////////
85 enum class cond_x { x00 = 30, x11, x22, x33 };
87 namespace std { template <> struct is_error_condition_enum<cond_x>: true_type { }; };
89 inline std::error_category const & cat_cond_x()
91 class cat : public std::error_category
93 char const * name() const noexcept
97 std::string message(int cond) const
99 switch( cond_x(cond) )
113 bool equivalent(std::error_code const & code, int cond) const noexcept
115 switch( cond_x(cond) )
118 return code==make_error_code(errc_a::a0) || code==make_error_code(errc_b::b0);
120 return code==make_error_code(errc_a::a1) || code==make_error_code(errc_b::b1);
122 return code==make_error_code(errc_a::a2) || code==make_error_code(errc_b::b2);
124 return code==make_error_code(errc_a::a3) || code==make_error_code(errc_b::b3);
134 inline std::error_condition make_error_condition( cond_x cond )
136 return std::error_condition(int(cond), cat_cond_x());
139 template <int> struct e_cond_x { cond_x value; };
141 ///////////////////////////////////
143 enum class cond_y { y03 = 40, y12, y21, y30 };
145 namespace std { template <> struct is_error_condition_enum<cond_y>: true_type { }; };
147 inline std::error_category const & cat_cond_y()
149 class cat : public std::error_category
151 char const * name() const noexcept
155 std::string message( int cond ) const
157 switch( cond_y(cond) )
171 bool equivalent(std::error_code const & code, int cond) const noexcept
173 switch( cond_y(cond) )
176 return code==make_error_code(errc_a::a0) || code==make_error_code(errc_b::b0);
178 return code==make_error_code(errc_a::a1) || code==make_error_code(errc_b::b1);
180 return code==make_error_code(errc_a::a2) || code==make_error_code(errc_b::b2);
182 return code==make_error_code(errc_a::a3) || code==make_error_code(errc_b::b3);
192 inline std::error_condition make_error_condition( cond_y cond )
194 return std::error_condition(int(cond), cat_cond_y());
197 template <int> struct e_cond_y { cond_y value; };