1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
#ifndef BOOST_LEAF_TEST_EC_HPP_INCLUDED
#define BOOST_LEAF_TEST_EC_HPP_INCLUDED
// Copyright 2018-2024 Emil Dotchevski and Reverge Studios, Inc.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <system_error>
enum class errc_a { a0 = 10, a1, a2, a3 };
namespace std { template <> struct is_error_code_enum<errc_a>: true_type { }; }
inline std::error_category const & cat_errc_a()
{
class cat : public std::error_category
{
char const * name() const noexcept
{
return "errc_a";
}
std::string message(int code) const
{
switch( errc_a(code) )
{
case errc_a::a0: return "a0";
case errc_a::a1: return "a1";
case errc_a::a2: return "a2";
case errc_a::a3: return "a3";
default: return "error";
}
}
};
static cat c;
return c;
}
inline std::error_code make_error_code( errc_a code )
{
return std::error_code(int(code), cat_errc_a());
}
template <int> struct e_errc_a { std::error_code value; };
////////////////////////////////////////
enum class errc_b { b0 = 20, b1, b2, b3 };
namespace std { template <> struct is_error_code_enum<errc_b>: true_type { }; };
inline std::error_category const & cat_errc_b()
{
class cat : public std::error_category
{
char const * name() const noexcept
{
return "errc_b";
}
std::string message(int code) const
{
switch( errc_b(code) )
{
case errc_b::b0: return "b0";
case errc_b::b1: return "b1";
case errc_b::b2: return "b2";
case errc_b::b3: return "b3";
default: return "error";
}
}
};
static cat c;
return c;
}
inline std::error_code make_error_code( errc_b code )
{
return std::error_code(int(code), cat_errc_b());
}
template <int> struct e_errc_b { std::error_code value; };
////////////////////////////////////////
enum class cond_x { x00 = 30, x11, x22, x33 };
namespace std { template <> struct is_error_condition_enum<cond_x>: true_type { }; };
inline std::error_category const & cat_cond_x()
{
class cat : public std::error_category
{
char const * name() const noexcept
{
return "cond_x";
}
std::string message(int cond) const
{
switch( cond_x(cond) )
{
case cond_x::x00:
return "x00";
case cond_x::x11:
return "x11";
case cond_x::x22:
return "x22";
case cond_x::x33:
return "x33";
default:
return "error";
}
}
bool equivalent(std::error_code const & code, int cond) const noexcept
{
switch( cond_x(cond) )
{
case cond_x::x00:
return code == make_error_code(errc_a::a0) || code == make_error_code(errc_b::b0);
case cond_x::x11:
return code == make_error_code(errc_a::a1) || code == make_error_code(errc_b::b1);
case cond_x::x22:
return code == make_error_code(errc_a::a2) || code == make_error_code(errc_b::b2);
case cond_x::x33:
return code == make_error_code(errc_a::a3) || code == make_error_code(errc_b::b3);
default:
return false;
}
}
};
static cat c;
return c;
}
inline std::error_condition make_error_condition( cond_x cond )
{
return std::error_condition(int(cond), cat_cond_x());
}
template <int> struct e_cond_x { cond_x value; };
////////////////////////////////////////
enum class cond_y { y03 = 40, y12, y21, y30 };
namespace std { template <> struct is_error_condition_enum<cond_y>: true_type { }; };
inline std::error_category const & cat_cond_y()
{
class cat : public std::error_category
{
char const * name() const noexcept
{
return "cond_y";
}
std::string message( int cond ) const
{
switch( cond_y(cond) )
{
case cond_y::y03:
return "y03";
case cond_y::y12:
return "y12";
case cond_y::y21:
return "y21";
case cond_y::y30:
return "y30";
default:
return "error";
}
}
bool equivalent(std::error_code const & code, int cond) const noexcept
{
switch( cond_y(cond) )
{
case cond_y::y03:
return code == make_error_code(errc_a::a0) || code == make_error_code(errc_b::b0);
case cond_y::y12:
return code == make_error_code(errc_a::a1) || code == make_error_code(errc_b::b1);
case cond_y::y21:
return code == make_error_code(errc_a::a2) || code == make_error_code(errc_b::b2);
case cond_y::y30:
return code == make_error_code(errc_a::a3) || code == make_error_code(errc_b::b3);
default:
return false;
}
}
};
static cat c;
return c;
}
inline std::error_condition make_error_condition( cond_y cond )
{
return std::error_condition(int(cond), cat_cond_y());
}
template <int> struct e_cond_y { cond_y value; };
#endif
|