From b3d350cb111eb5e9c1c80a0d9907ab4a3e6e868b Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Tue, 14 Nov 2017 03:13:54 +0100 Subject: [PATCH] more --- include/continuable/detail/expected.hpp | 30 +++++++++++++++++++++-- test/unit-test/test-continuable-await.cpp | 8 +++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/continuable/detail/expected.hpp b/include/continuable/detail/expected.hpp index b595b8c..dbd70d3 100644 --- a/include/continuable/detail/expected.hpp +++ b/include/continuable/detail/expected.hpp @@ -40,13 +40,16 @@ namespace cti { namespace detail { namespace expected { +/// A tag which is passed to the visitor when the expected type is empty +struct empty_guard_tag {}; + /// A class similar to the one in the expected proposal, /// however it is capable of carrying an exception_ptr if /// exceptions are used. template > class expected { - enum class slot_t { empty, type, error }; + enum class slot_t { empty, value, error }; Storage storage_; slot_t slot_; @@ -55,7 +58,30 @@ public: explicit expected() : slot_(slot_t::empty) { } - explicit expected(T value) : slot_(slot_t::error) { + explicit expected(T value) : slot_(slot_t::value) { + } + + explicit expected(types::error_type error) : slot_(slot_t::value) { + } + + bool is_empty() const noexcept { + return slot_ == slot_t::empty; + } + bool is_value() const noexcept { + return slot_ == slot_t::value; + } + bool is_error() const noexcept { + return slot_ == slot_t::error; + } + + template + auto visit(T&& visitor) + -> decltype(std::forward(visitor)(empty_guard_tag{})) { + + switch(slot_) + { + + } } }; } // namespace expected diff --git a/test/unit-test/test-continuable-await.cpp b/test/unit-test/test-continuable-await.cpp index 8f02a30..70afb14 100644 --- a/test/unit-test/test-continuable-await.cpp +++ b/test/unit-test/test-continuable-await.cpp @@ -36,12 +36,12 @@ struct coroutine_traits { void set_exception(exception_ptr const&) noexcept { } - bool initial_suspend() noexcept { - return false; + suspend_never initial_suspend() noexcept { + return {}; } - bool final_suspend() noexcept { - return false; + suspend_never final_suspend() noexcept { + return {}; } void return_void() noexcept {