Make the expected class part of the public interface

* Required for exception rethrowing and recovering
This commit is contained in:
Denis Blank 2018-11-24 22:48:16 +01:00
parent 3a70356f16
commit c76fe9e973
5 changed files with 117 additions and 60 deletions

View File

@ -895,6 +895,19 @@ constexpr auto make_exceptional_continuable(Exception&& exception) {
std::move(exception));
});
}
template <typename... Args>
auto recover(Args&&... args) {
// TODO
}
inline auto rethrow(exception_t exception) {
// TODO
}
inline constexpr auto cancel() {
// TODO
}
/// \}
} // namespace cti

View File

@ -28,24 +28,20 @@
SOFTWARE.
**/
#ifndef CONTINUABLE_DETAIL_EXPECTED_HPP_INCLUDED
#define CONTINUABLE_DETAIL_EXPECTED_HPP_INCLUDED
#ifndef CONTINUABLE_EXPECTED_HPP_INCLUDED
#define CONTINUABLE_EXPECTED_HPP_INCLUDED
#include <type_traits>
#include <utility>
#include <continuable/continuable-primitives.hpp>
#include <continuable/detail/core/hints.hpp>
#include <continuable/detail/utility/flat-variant.hpp>
namespace cti {
namespace detail {
namespace container {
/// A class similar to the one in the expected proposal,
/// however it is capable of carrying an exception_ptr if
/// exceptions are used.
/// however it's capable of carrying an exception_t.
template <typename T>
class expected {
flat_variant<T, exception_t> variant_;
detail::container::flat_variant<T, exception_t> variant_;
public:
explicit expected() = default;
@ -76,6 +72,9 @@ public:
variant_ = std::move(exception);
}
bool is_empty() {
return variant_.is_empty();
}
bool is_value() const noexcept {
return variant_.template is<T>();
}
@ -107,56 +106,6 @@ public:
return get_value();
}
};
namespace detail {
struct void_guard_tag {};
template <typename T>
struct expected_result_trait;
template <>
struct expected_result_trait<traits::identity<>> {
using expected_type = expected<void_guard_tag>;
static constexpr void_guard_tag wrap() noexcept {
return {};
}
static void unwrap(expected_type&& e) {
assert(e.is_value());
(void)e;
}
};
template <typename T>
struct expected_result_trait<traits::identity<T>> {
using expected_type = expected<T>;
static auto wrap(T arg) {
return std::move(arg);
}
static auto unwrap(expected_type&& e) {
assert(e.is_value());
return std::move(e.get_value());
}
};
template <typename First, typename Second, typename... Rest>
struct expected_result_trait<traits::identity<First, Second, Rest...>> {
using expected_type = expected<std::tuple<First, Second, Rest...>>;
static auto wrap(First first, Second second, Rest... rest) {
return std::make_tuple(std::move(first), std::move(second),
std::move(rest)...);
}
static auto unwrap(expected_type&& e) {
assert(e.is_value());
return std::move(e.get_value());
}
};
} // namespace detail
template <typename Continuable>
using expected_result_trait_t = detail::expected_result_trait<decltype(
hints::hint_of(traits::identify<Continuable>{}))>;
} // namespace container
} // namespace detail
} // namespace cti
#endif // CONTINUABLE_DETAIL_EXPECTED_HPP_INCLUDED
#endif // CONTINUABLE_EXPECTED_HPP_INCLUDED

View File

@ -34,6 +34,7 @@
#include <tuple>
#include <type_traits>
#include <utility>
#include <continuable/continuable-expected.hpp>
#include <continuable/continuable-primitives.hpp>
#include <continuable/detail/core/hints.hpp>
#include <continuable/detail/core/types.hpp>

View File

@ -35,11 +35,12 @@
#include <cassert>
#include <tuple>
#include <experimental/coroutine>
#include <continuable/continuable-expected.hpp>
#include <continuable/continuable-primitives.hpp>
#include <continuable/detail/core/hints.hpp>
#include <continuable/detail/core/types.hpp>
#include <continuable/detail/features.hpp>
#include <continuable/detail/utility/expected.hpp>
#include <continuable/detail/utility/expected-traits.hpp>
#include <continuable/detail/utility/traits.hpp>
#include <continuable/detail/utility/util.hpp>

View File

@ -0,0 +1,93 @@
/*
/~` _ _ _|_. _ _ |_ | _
\_,(_)| | | || ||_|(_||_)|(/_
https://github.com/Naios/continuable
v3.0.0
Copyright(c) 2015 - 2018 Denis Blank <denis.blank at outlook dot com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**/
#ifndef CONTINUABLE_DETAIL_EXPECTED_TRAITS_HPP_INCLUDED
#define CONTINUABLE_DETAIL_EXPECTED_TRAITS_HPP_INCLUDED
#include <type_traits>
#include <utility>
#include <continuable/continuable-expected.hpp>
#include <continuable/detail/core/hints.hpp>
namespace cti {
namespace detail {
namespace container {
namespace detail {
struct void_guard_tag {};
template <typename T>
struct expected_result_trait;
template <>
struct expected_result_trait<traits::identity<>> {
using expected_type = expected<void_guard_tag>;
static constexpr void_guard_tag wrap() noexcept {
return {};
}
static void unwrap(expected_type&& e) {
assert(e.is_value());
(void)e;
}
};
template <typename T>
struct expected_result_trait<traits::identity<T>> {
using expected_type = expected<T>;
static auto wrap(T arg) {
return std::move(arg);
}
static auto unwrap(expected_type&& e) {
assert(e.is_value());
return std::move(e.get_value());
}
};
template <typename First, typename Second, typename... Rest>
struct expected_result_trait<traits::identity<First, Second, Rest...>> {
using expected_type = expected<std::tuple<First, Second, Rest...>>;
static auto wrap(First first, Second second, Rest... rest) {
return std::make_tuple(std::move(first), std::move(second),
std::move(rest)...);
}
static auto unwrap(expected_type&& e) {
assert(e.is_value());
return std::move(e.get_value());
}
};
} // namespace detail
template <typename Continuable>
using expected_result_trait_t = detail::expected_result_trait<decltype(
hints::hint_of(traits::identify<Continuable>{}))>;
} // namespace container
} // namespace detail
} // namespace cti
#endif // CONTINUABLE_DETAIL_EXPECTED_TRAITS_HPP_INCLUDED