Skip to content

Commit 76b7c67

Browse files
committed
add option for forcing explicit unwrapping of Result
1 parent 2fba9c7 commit 76b7c67

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

include/common/result.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
#include <stacktrace>
77
#include <type_traits>
88

9+
// library developers and advanced users may appreciate compiler checks to ensure they are actually
10+
// handling all errors.
11+
// By defining EXPLICIT_RESULTS, the Result conversion operators will be marked as explicit.
12+
// This does not break ABI, so libraries/projects dependencies can define EXPLICIT_RESULTS or not
13+
// and still be compatible.
14+
#ifndef EXPLICIT_RESULTS
15+
#define RESULT_EXPLICIT_QUALIFIER
16+
#else
17+
#define RESULT_EXPLICIT_QUALIFIER explicit
18+
#endif
19+
920
namespace zest {
1021

1122
template<typename T>
@@ -67,11 +78,11 @@ class Result {
6778
error({type, std::format(fmt, std::forward<Args>(args)...), std::stacktrace::current()}) {
6879
}
6980

70-
operator T() const& {
81+
RESULT_EXPLICIT_QUALIFIER operator T() const& {
7182
return val;
7283
}
7384

74-
operator T() && {
85+
RESULT_EXPLICIT_QUALIFIER operator T() && {
7586
return std::move(val);
7687
}
7788

0 commit comments

Comments
 (0)