3#include <boost/capy/io_task.hpp>
12#ifdef __cpp_lib_expected
38template <
typename Ty,
typename ValTy>
40 typename Ty::template return_type<ValTy>;
42 errp.template with_error<ValTy>(std::declval<std::error_code>())
43 } -> std::same_as<typename Ty::template return_type<ValTy>>;
45 errp.template with_success<ValTy>(std::declval<ValTy>())
46 } -> std::same_as<typename Ty::template return_type<ValTy>>;
69 throw std::system_error{ec};
74 return U(std::forward<Args>(args)...);
77static_assert(ErrorProtocol<as_exception_t, int>,
"Not an error protocol");
92 template <
typename ValTy>
using return_type = std::optional<ValTy>;
94 constexpr explicit as_optional_t (std::error_code &ec) noexcept : m_ec_ref(ec)
114 template <
typename U,
typename... Args>
115 auto with_success (Args &&...args)
noexcept(std::is_nothrow_constructible_v<U, Args...>)
119 return std::optional<U>(std::in_place, std::forward<Args>(args)...);
123 std::error_code &m_ec_ref;
125static_assert(ErrorProtocol<as_optional_t, int>,
"Not an error protocol");
127#ifdef __cpp_lib_expected
138 template <
typename ValTy>
using return_type = std::expected<ValTy, std::error_code>;
140 constexpr explicit as_expected_t () noexcept
149 template <
typename U>
auto with_error (std::error_code ec)
noexcept -> return_type<U>
151 return std::unexpected(ec);
159 template <
typename U,
typename... Args>
160 auto with_success (Args &&...args)
noexcept(std::is_nothrow_constructible_v<U, Args...>)
163 return return_type<U>(std::in_place, std::forward<Args>(args)...);
166static_assert(ErrorProtocol<as_expected_t, int>,
"Not an error protocol");
171 template <
typename ValTy>
using return_type = boost::capy::io_result<std::optional<ValTy>>;
179 return {ec, std::nullopt};
182 template <
typename U,
typename... Args>
183 auto with_success (Args &&...args)
noexcept(std::is_nothrow_constructible_v<U, Args...>)
186 return {{}, std::optional<U>(std::in_place, std::forward<Args>(args)...)};
189static_assert(ErrorProtocol<as_io_result_t, int>,
"Not an error protocol");
193 template <
typename ValTy>
using return_type = boost::capy::io_task<std::optional<ValTy>>;
201 co_return {ec, std::nullopt};
204 template <
typename U,
typename... Args>
205 auto with_success (Args &&...args)
noexcept(std::is_nothrow_constructible_v<U, Args...>)
208 co_return {{}, std::optional<U>(std::in_place, std::forward<Args>(args)...)};
211static_assert(ErrorProtocol<as_io_task_t, int>,
"Not an error protocol");
Result protocol for signaling error via error code or full completion.
Definition error_protocol.hpp:39
Definition flag_type.hpp:6
Exception error protocol.
Definition error_protocol.hpp:60
auto with_success(Args &&...args) -> return_type< U >
Definition error_protocol.hpp:72
auto with_error(std::error_code ec) -> return_type< U >
Definition error_protocol.hpp:67
ValTy return_type
Definition error_protocol.hpp:61
constexpr as_exception_t()
Definition error_protocol.hpp:63
Definition error_protocol.hpp:170
auto with_error(std::error_code ec) noexcept -> return_type< U >
Definition error_protocol.hpp:177
constexpr as_io_result_t() noexcept
Definition error_protocol.hpp:173
boost::capy::io_result< std::optional< ValTy > > return_type
Definition error_protocol.hpp:171
auto with_success(Args &&...args) noexcept(std::is_nothrow_constructible_v< U, Args... >) -> return_type< U >
Definition error_protocol.hpp:183
Definition error_protocol.hpp:192
auto with_error(std::error_code ec) noexcept -> return_type< U >
Definition error_protocol.hpp:199
boost::capy::io_task< std::optional< ValTy > > return_type
Definition error_protocol.hpp:193
auto with_success(Args &&...args) noexcept(std::is_nothrow_constructible_v< U, Args... >) -> return_type< U >
Definition error_protocol.hpp:205
constexpr as_io_task_t() noexcept
Definition error_protocol.hpp:195
Error protocol signaling error into a given error code reference and returning an optional.
Definition error_protocol.hpp:91
auto with_success(Args &&...args) noexcept(std::is_nothrow_constructible_v< U, Args... >) -> return_type< U >
Signals success via returned optional.
Definition error_protocol.hpp:115
auto with_error(std::error_code ec) noexcept -> return_type< U >
Signals error to stored error code reference.
Definition error_protocol.hpp:103
constexpr as_optional_t(std::error_code &ec) noexcept
Definition error_protocol.hpp:94
std::optional< ValTy > return_type
Definition error_protocol.hpp:92