From 994a19def11bda02a9ce21e8633ad1ece9d60503 Mon Sep 17 00:00:00 2001 From: Yulon Date: Sat, 29 Jul 2023 17:46:43 +0800 Subject: [PATCH] feat: add expected<>::vrt() --- include/rua/error.hpp | 22 ++++++++++++++++++---- include/rua/sync/future.hpp | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/rua/error.hpp b/include/rua/error.hpp index ee005ae..dcb2a95 100644 --- a/include/rua/error.hpp +++ b/include/rua/error.hpp @@ -277,15 +277,15 @@ class expected : public enable_value_operators, T> { return nullptr; } - variant &data() & { + variant &vrt() & { return $v; } - variant &&data() && { + variant &&vrt() && { return std::move($v); } - const variant &data() const & { + const variant &vrt() const & { return $v; } @@ -357,12 +357,26 @@ class expected { 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 vrt() && { + return std::move($err); + } + + variant vrt() const & { + return $err; + } + void reset() { $err.reset(); } diff --git a/include/rua/sync/future.hpp b/include/rua/sync/future.hpp index 746d2d5..02d9ecd 100644 --- a/include/rua/sync/future.hpp +++ b/include/rua/sync/future.hpp @@ -88,7 +88,7 @@ class future : private enable_await_operators { typename = enable_if_t< (std::is_void::value && std::is_void::value) || std::is_convertible::value>> - future(expected exp) : $v(std::move(exp).data()) {} + future(expected exp) : $v(std::move(exp).vrt()) {} template < typename Promise,