35 return "yaclib::StopError";
45template <
typename Error>
79 return "yaclib::ResultEmpty";
89template <
typename ValueT,
typename E>
92 static_assert(
Check<E>(),
"E should be valid");
93 static_assert(!std::is_same_v<ValueT, E>,
"Result cannot be instantiated with same V and E, because it's ambiguous");
94 static_assert(std::is_constructible_v<E, StopTag>,
"Error should be constructable from StopTag");
95 using V = std::conditional_t<std::is_void_v<ValueT>,
Unit,
ValueT>;
96 using Variant = std::variant<V, std::exception_ptr, E, std::monostate>;
104 template <
typename...
Args,
107 Result(
Args&&...
args)
noexcept(std::is_nothrow_constructible_v<Variant, std::in_place_type_t<V>,
Args&&...>)
111 template <
typename...
Args>
113 Args&&...
args)
noexcept(std::is_nothrow_constructible_v<Variant, std::in_place_type_t<V>,
Args&&...>)
118 : _result{std::in_place_type<std::exception_ptr>, std::move(exception)} {
130 template <
typename Arg,
typename = std::enable_if_t<!is_result_v<std::decay_t<Arg>>,
void>>
132 _result = std::forward<Arg>(
arg);
140 void Ok() & =
delete;
150 return Get(std::move(*
this));
157 return ResultState{
static_cast<unsigned char>(_result.index())};
161 return std::get<V>(std::move(_result));
164 return std::get<V>(_result);
168 return std::get<std::exception_ptr>(std::move(_result));
171 return std::get<std::exception_ptr>(_result);
175 return std::get<E>(std::move(_result));
178 return std::get<E>(_result);
186 template <
typename R>
187 static decltype(
auto) Get(
R&&
r) {
190 return std::forward<R>(
r).Value();
192 std::rethrow_exception(std::forward<R>(
r).
Exception());
const Error & Get() const &noexcept
ResultError(ResultError &&) noexcept(std::is_nothrow_move_constructible_v< Error >)=default
ResultError(const Error &error) noexcept(std::is_nothrow_copy_constructible_v< Error >)
const char * what() const noexcept final
Encapsulated return value from caller.
Result(StopTag tag) noexcept
Result & operator=(Result &&other) noexcept(std::is_nothrow_move_assignable_v< Variant >)=default
Result & operator=(const Result &other) noexcept(std::is_nothrow_copy_assignable_v< Variant >)=default
Result(Result &&other) noexcept(std::is_nothrow_move_constructible_v< Variant >)=default
const std::exception_ptr & Exception() const &noexcept
Result(std::in_place_t, Args &&... args) noexcept(std::is_nothrow_constructible_v< Variant, std::in_place_type_t< V >, Args &&... >)
void Ok() const &&=delete
const E & Error() const &noexcept
std::exception_ptr && Exception() &&noexcept
Result & operator=(Arg &&arg) noexcept(std::is_nothrow_assignable_v< Variant, Arg >)
Result(std::exception_ptr exception) noexcept
ResultState State() const noexcept
const V & Value() const &noexcept
Result(Args &&... args) noexcept(std::is_nothrow_constructible_v< Variant, std::in_place_type_t< V >, Args &&... >)
Result(const Result &other) noexcept(std::is_nothrow_copy_constructible_v< Variant >)=default
#define YACLIB_DEFINE_VOID_COMPARE(type)
typename detail::Head< Args... >::Type head_t
Contract< V, E > MakeContract()
Creates related future and promise.
const char * what() const noexcept final
constexpr StopError(StopError &&) noexcept=default
constexpr StopError(StopTag) noexcept