|
27 | 27 | _LIBCPP_BEGIN_NAMESPACE_STD |
28 | 28 |
|
29 | 29 | template <class _Tp> |
30 | | -struct _LIBCPP_TEMPLATE_VIS is_error_code_enum |
31 | | - : public false_type {}; |
| 30 | +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum : public false_type {}; |
32 | 31 |
|
33 | 32 | #if _LIBCPP_STD_VER >= 17 |
34 | 33 | template <class _Tp> |
35 | 34 | inline constexpr bool is_error_code_enum_v = is_error_code_enum<_Tp>::value; |
36 | 35 | #endif |
37 | 36 |
|
38 | 37 | namespace __adl_only { |
39 | | - // Those cause ADL to trigger but they are not viable candidates, |
40 | | - // so they are never actually selected. |
41 | | - void make_error_code() = delete; |
| 38 | +// Those cause ADL to trigger but they are not viable candidates, |
| 39 | +// so they are never actually selected. |
| 40 | +void make_error_code() = delete; |
42 | 41 | } // namespace __adl_only |
43 | 42 |
|
44 | | -class _LIBCPP_TYPE_VIS error_code |
45 | | -{ |
46 | | - int __val_; |
47 | | - const error_category* __cat_; |
| 43 | +class _LIBCPP_TYPE_VIS error_code { |
| 44 | + int __val_; |
| 45 | + const error_category* __cat_; |
| 46 | + |
48 | 47 | public: |
49 | | - _LIBCPP_INLINE_VISIBILITY |
50 | | - error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {} |
51 | | - |
52 | | - _LIBCPP_INLINE_VISIBILITY |
53 | | - error_code(int __val, const error_category& __cat) _NOEXCEPT |
54 | | - : __val_(__val), __cat_(&__cat) {} |
55 | | - |
56 | | - template <class _Ep> |
57 | | - _LIBCPP_INLINE_VISIBILITY |
58 | | - error_code(_Ep __e, |
59 | | - typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr |
60 | | - ) _NOEXCEPT |
61 | | - { |
62 | | - using __adl_only::make_error_code; |
63 | | - *this = make_error_code(__e); |
64 | | - } |
65 | | - |
66 | | - _LIBCPP_INLINE_VISIBILITY |
67 | | - void assign(int __val, const error_category& __cat) _NOEXCEPT |
68 | | - { |
69 | | - __val_ = __val; |
70 | | - __cat_ = &__cat; |
71 | | - } |
72 | | - |
73 | | - template <class _Ep> |
74 | | - _LIBCPP_INLINE_VISIBILITY |
75 | | - typename enable_if |
76 | | - < |
77 | | - is_error_code_enum<_Ep>::value, |
78 | | - error_code& |
79 | | - >::type |
80 | | - operator=(_Ep __e) _NOEXCEPT |
81 | | - { |
82 | | - using __adl_only::make_error_code; |
83 | | - *this = make_error_code(__e); |
84 | | - return *this; |
85 | | - } |
86 | | - |
87 | | - _LIBCPP_INLINE_VISIBILITY |
88 | | - void clear() _NOEXCEPT |
89 | | - { |
90 | | - __val_ = 0; |
91 | | - __cat_ = &system_category(); |
92 | | - } |
93 | | - |
94 | | - _LIBCPP_INLINE_VISIBILITY |
95 | | - int value() const _NOEXCEPT {return __val_;} |
96 | | - |
97 | | - _LIBCPP_INLINE_VISIBILITY |
98 | | - const error_category& category() const _NOEXCEPT {return *__cat_;} |
99 | | - |
100 | | - _LIBCPP_INLINE_VISIBILITY |
101 | | - error_condition default_error_condition() const _NOEXCEPT |
102 | | - {return __cat_->default_error_condition(__val_);} |
103 | | - |
104 | | - string message() const; |
105 | | - |
106 | | - _LIBCPP_INLINE_VISIBILITY |
107 | | - explicit operator bool() const _NOEXCEPT {return __val_ != 0;} |
| 48 | + _LIBCPP_INLINE_VISIBILITY error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {} |
| 49 | + |
| 50 | + _LIBCPP_INLINE_VISIBILITY error_code(int __val, const error_category& __cat) _NOEXCEPT |
| 51 | + : __val_(__val), |
| 52 | + __cat_(&__cat) {} |
| 53 | + |
| 54 | + template <class _Ep> |
| 55 | + _LIBCPP_INLINE_VISIBILITY |
| 56 | + error_code(_Ep __e, typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr) _NOEXCEPT { |
| 57 | + using __adl_only::make_error_code; |
| 58 | + *this = make_error_code(__e); |
| 59 | + } |
| 60 | + |
| 61 | + _LIBCPP_INLINE_VISIBILITY void assign(int __val, const error_category& __cat) _NOEXCEPT { |
| 62 | + __val_ = __val; |
| 63 | + __cat_ = &__cat; |
| 64 | + } |
| 65 | + |
| 66 | + template <class _Ep> |
| 67 | + _LIBCPP_INLINE_VISIBILITY typename enable_if< is_error_code_enum<_Ep>::value, error_code& >::type |
| 68 | + operator=(_Ep __e) _NOEXCEPT { |
| 69 | + using __adl_only::make_error_code; |
| 70 | + *this = make_error_code(__e); |
| 71 | + return *this; |
| 72 | + } |
| 73 | + |
| 74 | + _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT { |
| 75 | + __val_ = 0; |
| 76 | + __cat_ = &system_category(); |
| 77 | + } |
| 78 | + |
| 79 | + _LIBCPP_INLINE_VISIBILITY int value() const _NOEXCEPT { return __val_; } |
| 80 | + |
| 81 | + _LIBCPP_INLINE_VISIBILITY const error_category& category() const _NOEXCEPT { return *__cat_; } |
| 82 | + |
| 83 | + _LIBCPP_INLINE_VISIBILITY error_condition default_error_condition() const _NOEXCEPT { |
| 84 | + return __cat_->default_error_condition(__val_); |
| 85 | + } |
| 86 | + |
| 87 | + string message() const; |
| 88 | + |
| 89 | + _LIBCPP_INLINE_VISIBILITY explicit operator bool() const _NOEXCEPT { return __val_ != 0; } |
108 | 90 | }; |
109 | 91 |
|
110 | | -inline _LIBCPP_INLINE_VISIBILITY |
111 | | -error_code |
112 | | -make_error_code(errc __e) _NOEXCEPT |
113 | | -{ |
114 | | - return error_code(static_cast<int>(__e), generic_category()); |
| 92 | +inline _LIBCPP_INLINE_VISIBILITY error_code make_error_code(errc __e) _NOEXCEPT { |
| 93 | + return error_code(static_cast<int>(__e), generic_category()); |
115 | 94 | } |
116 | 95 |
|
117 | | -inline _LIBCPP_INLINE_VISIBILITY |
118 | | -bool |
119 | | -operator==(const error_code& __x, const error_code& __y) _NOEXCEPT |
120 | | -{ |
121 | | - return __x.category() == __y.category() && __x.value() == __y.value(); |
| 96 | +inline _LIBCPP_INLINE_VISIBILITY bool operator==(const error_code& __x, const error_code& __y) _NOEXCEPT { |
| 97 | + return __x.category() == __y.category() && __x.value() == __y.value(); |
122 | 98 | } |
123 | 99 |
|
124 | | -inline _LIBCPP_INLINE_VISIBILITY |
125 | | -bool |
126 | | -operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT |
127 | | -{ |
128 | | - return __x.category().equivalent(__x.value(), __y) |
129 | | - || __y.category().equivalent(__x, __y.value()); |
| 100 | +inline _LIBCPP_INLINE_VISIBILITY bool operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT { |
| 101 | + return __x.category().equivalent(__x.value(), __y) || __y.category().equivalent(__x, __y.value()); |
130 | 102 | } |
131 | 103 |
|
132 | 104 | #if _LIBCPP_STD_VER <= 17 |
133 | | -inline _LIBCPP_INLINE_VISIBILITY |
134 | | -bool |
135 | | -operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT |
136 | | -{ |
137 | | - return __y == __x; |
| 105 | +inline _LIBCPP_INLINE_VISIBILITY bool operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT { |
| 106 | + return __y == __x; |
138 | 107 | } |
139 | 108 | #endif |
140 | 109 |
|
141 | 110 | #if _LIBCPP_STD_VER <= 17 |
142 | 111 |
|
143 | | -inline _LIBCPP_INLINE_VISIBILITY |
144 | | -bool |
145 | | -operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT |
146 | | -{return !(__x == __y);} |
147 | | - |
148 | | -inline _LIBCPP_INLINE_VISIBILITY |
149 | | -bool |
150 | | -operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT |
151 | | -{return !(__x == __y);} |
152 | | - |
153 | | -inline _LIBCPP_INLINE_VISIBILITY |
154 | | -bool |
155 | | -operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT |
156 | | -{return !(__x == __y);} |
157 | | - |
158 | | -inline _LIBCPP_INLINE_VISIBILITY |
159 | | -bool |
160 | | -operator<(const error_code& __x, const error_code& __y) _NOEXCEPT |
161 | | -{ |
162 | | - return __x.category() < __y.category() |
163 | | - || (__x.category() == __y.category() && __x.value() < __y.value()); |
| 112 | +inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT { |
| 113 | + return !(__x == __y); |
| 114 | +} |
| 115 | + |
| 116 | +inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT { |
| 117 | + return !(__x == __y); |
| 118 | +} |
| 119 | + |
| 120 | +inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT { |
| 121 | + return !(__x == __y); |
| 122 | +} |
| 123 | + |
| 124 | +inline _LIBCPP_INLINE_VISIBILITY bool operator<(const error_code& __x, const error_code& __y) _NOEXCEPT { |
| 125 | + return __x.category() < __y.category() || (__x.category() == __y.category() && __x.value() < __y.value()); |
164 | 126 | } |
165 | 127 |
|
166 | | -#else // _LIBCPP_STD_VER <= 17 |
| 128 | +#else // _LIBCPP_STD_VER <= 17 |
167 | 129 |
|
168 | | -inline _LIBCPP_HIDE_FROM_ABI strong_ordering |
169 | | -operator<=>(const error_code& __x, const error_code& __y) noexcept |
170 | | -{ |
171 | | - if (auto __c = __x.category() <=> __y.category(); __c != 0) |
172 | | - return __c; |
173 | | - return __x.value() <=> __y.value(); |
| 130 | +inline _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const error_code& __x, const error_code& __y) noexcept { |
| 131 | + if (auto __c = __x.category() <=> __y.category(); __c != 0) |
| 132 | + return __c; |
| 133 | + return __x.value() <=> __y.value(); |
174 | 134 | } |
175 | 135 |
|
176 | 136 | #endif // _LIBCPP_STD_VER <= 17 |
177 | 137 |
|
178 | 138 | template <> |
179 | | -struct _LIBCPP_TEMPLATE_VIS hash<error_code> |
180 | | - : public __unary_function<error_code, size_t> |
181 | | -{ |
182 | | - _LIBCPP_INLINE_VISIBILITY |
183 | | - size_t operator()(const error_code& __ec) const _NOEXCEPT |
184 | | - { |
185 | | - return static_cast<size_t>(__ec.value()); |
186 | | - } |
| 139 | +struct _LIBCPP_TEMPLATE_VIS hash<error_code> : public __unary_function<error_code, size_t> { |
| 140 | + _LIBCPP_INLINE_VISIBILITY size_t operator()(const error_code& __ec) const _NOEXCEPT { |
| 141 | + return static_cast<size_t>(__ec.value()); |
| 142 | + } |
187 | 143 | }; |
188 | 144 |
|
189 | 145 | _LIBCPP_END_NAMESPACE_STD |
|
0 commit comments