Skip to content

Commit 5b2fa54

Browse files
committed
feat: better Expected
1 parent f1f8ee0 commit 5b2fa54

14 files changed

+360
-153
lines changed

include/mrdox/Support/Error.hpp

+31-16
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace mrdox {
2929
/** Holds the description of an error, or success.
3030
*/
3131
class [[nodiscard]] MRDOX_DECL
32-
Error final : public std::exception
32+
Error final
3333
{
3434
std::string message_;
3535
std::string reason_;
@@ -47,19 +47,19 @@ class [[nodiscard]] MRDOX_DECL
4747
A default constructed error is
4848
equivalent to success.
4949
*/
50-
Error() = default;
50+
Error() noexcept = default;
5151

5252
/** Constructor.
5353
*/
54-
Error(Error&&) = default;
54+
Error(Error&&) noexcept = default;
5555

5656
/** Constructor.
5757
*/
5858
Error(Error const&) = default;
5959

6060
/** Constructor.
6161
*/
62-
Error& operator=(Error&&) = default;
62+
Error& operator=(Error&&) noexcept = default;
6363

6464
/** Assignment.
6565
*/
@@ -110,64 +110,79 @@ class [[nodiscard]] MRDOX_DECL
110110

111111
/** Return true if this holds an error.
112112
*/
113-
bool failed() const noexcept
113+
constexpr bool
114+
failed() const noexcept
114115
{
115116
return ! message_.empty();
116117
}
117118

118119
/** Return true if this holds an error.
119120
*/
120-
explicit
121+
constexpr explicit
121122
operator bool() const noexcept
122123
{
123124
return failed();
124125
}
125126

126127
/** Return the error string.
127128
*/
128-
std::string_view
129+
constexpr std::string_view
129130
message() const noexcept
130131
{
131132
return message_;
132133
}
133134

134135
/** Return the reason string.
135136
*/
136-
std::string_view
137+
constexpr std::string_view
137138
reason() const noexcept
138139
{
139140
return reason_;
140141
}
141142

142143
/** Return the source location.
143144
*/
144-
std::source_location
145+
constexpr std::source_location
145146
location() const noexcept
146147
{
147148
return loc_;
148149
}
149150

150-
/** Return true if this equals other.
151+
/** Return true if this equals rhs.
151152
*/
152-
bool
153-
operator==(Error const& other) const noexcept
153+
constexpr bool
154+
operator==(Error const& rhs) const noexcept
154155
{
155-
return message_ == other.message_;
156+
return message_ == rhs.message_;
156157
}
157158

159+
#if 0
158160
/** Return a null-terminated error string.
159161
*/
160162
char const*
161163
what() const noexcept override
162164
{
163165
return reason_.c_str();
164166
}
167+
#endif
168+
169+
constexpr void swap(Error& rhs) noexcept
170+
{
171+
using std::swap;
172+
swap(message_, rhs.message_);
173+
swap(reason_, rhs.reason_);
174+
swap(loc_, rhs.loc_);
175+
}
176+
177+
friend constexpr void swap(
178+
Error& lhs, Error& rhs) noexcept
179+
{
180+
lhs.swap(rhs);
181+
}
165182

166183
/** Return a value indicating success.
167184
*/
168-
static
169-
Error
170-
success() noexcept;
185+
static Error success() noexcept;
171186
};
172187

173188
inline

0 commit comments

Comments
 (0)