Skip to content

Commit

Permalink
feat: add meet_expected
Browse files Browse the repository at this point in the history
remove expected_or<>()
  • Loading branch information
yulon committed Sep 6, 2023
1 parent ab8a3d5 commit c8c6e48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions include/rua/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ inline error_i current_exception_error() {

RUA_CVAR strv_error unexpected("unexpected");

struct meet_expected_t {};

RUA_CVAL meet_expected_t meet_expected;

template <typename T = void>
class expected : public enable_value_operators<expected<T>, T> {
public:
Expand All @@ -220,6 +224,8 @@ class expected : public enable_value_operators<expected<T>, T> {
expected(std::initializer_list<U> il, Args &&...args) :
$v(in_place_type_t<T>{}, il, std::forward<Args>(args)...) {}

expected(meet_expected_t) : $v(in_place_type_t<T>{}) {}

expected(const expected &src) : $v(src.$v) {}

expected(expected &&src) : $v(std::move(src.$v)) {}
Expand Down Expand Up @@ -343,6 +349,8 @@ class expected<void> {
assert(r);
}

expected(meet_expected_t) : $err() {}

expected(const expected &src) : $err(src.$err) {}

expected(expected &&src) : $err(std::move(src.$err)) {}
Expand Down Expand Up @@ -391,18 +399,6 @@ class expected<void> {

////////////////////////////////////////////////////////////////////////////

template <typename T>
inline expected<T> expected_or(error_i unexpected_err) {
return unexpected_err;
}

template <>
inline expected<void> expected_or(error_i) {
return {};
}

////////////////////////////////////////////////////////////////////////////

template <typename T>
struct is_expected : std::false_type {};

Expand Down
2 changes: 1 addition & 1 deletion include/rua/sync/promise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class promise<T, void> {
//////////////////// fulfill ////////////////////

void fulfill(
expected<T> value = expected_or<T>(err_promise_unfulfilled),
expected<T> value = meet_expected,
std::function<void(expected<T>)> on_unharvested = nullptr) noexcept {

assert(std::is_void<T>::value || !$val);
Expand Down

0 comments on commit c8c6e48

Please sign in to comment.