Skip to content

Commit

Permalink
feat: add expected<>::vrt()
Browse files Browse the repository at this point in the history
  • Loading branch information
yulon committed Jul 29, 2023
1 parent 767ad3b commit 994a19d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions include/rua/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@ class expected : public enable_value_operators<expected<T>, T> {
return nullptr;
}

variant<T, error_i> &data() & {
variant<T, error_i> &vrt() & {
return $v;
}

variant<T, error_i> &&data() && {
variant<T, error_i> &&vrt() && {
return std::move($v);
}

const variant<T, error_i> &data() const & {
const variant<T, error_i> &vrt() const & {
return $v;
}

Expand Down Expand Up @@ -357,12 +357,26 @@ class expected<void> {
return has_value();
}

RUA_CONSTEXPR_14 void value() const {}
void value() const {
#ifdef RUA_HAS_EXCEPTIONS
if (!has_value()) {
throw error();
}
#endif
}

error_i error() const {
return $err;
}

variant<void, error_i> vrt() && {
return std::move($err);
}

variant<void, error_i> vrt() const & {
return $err;
}

void reset() {
$err.reset();
}
Expand Down
2 changes: 1 addition & 1 deletion include/rua/sync/future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class future : private enable_await_operators {
typename = enable_if_t<
(std::is_void<T>::value && std::is_void<U>::value) ||
std::is_convertible<U, T>::value>>
future(expected<U> exp) : $v(std::move(exp).data()) {}
future(expected<U> exp) : $v(std::move(exp).vrt()) {}

template <
typename Promise,
Expand Down

0 comments on commit 994a19d

Please sign in to comment.