1#ifndef __COMMON_RESULTS_HPP__
2#define __COMMON_RESULTS_HPP__
11template <
typename S,
typename T>
struct Result :
protected std::variant<S, T>
13 explicit constexpr Result() noexcept : std::variant<S, T>{ S{} } {};
14 constexpr explicit Result(T
const&& t) noexcept : std::variant<S, T>{ t }
18 constexpr explicit Result(S&& s) noexcept : std::variant<S, T>{ std::move(s) }
23 operator bool() const noexcept
28 [[nodiscard]]
constexpr bool
31 return std::holds_alternative<S>(*
this);
33 [[nodiscard]]
constexpr bool
39 [[nodiscard]]
constexpr auto
40 get() const noexcept -> T
42 return (
invalid() ? std::get<T>(*
this) : T());
50 return std::move(std::get<S>(*
this));
52 throw std::runtime_error(
"Deref None");
68 template <
typename Func,
typename Err>
70 match(Func&& f, Err&& r)
noexcept
74 return f(std::forward<S>(std::get<S>(*
this)));
77 return r(std::forward<T>(std::get<T>(*
this)));
constexpr bool valid() const noexcept
Definition results.hpp:29
constexpr Result(S &&s) noexcept
Definition results.hpp:18
constexpr auto get() const noexcept -> T
Definition results.hpp:40
constexpr Result(T const &&t) noexcept
Definition results.hpp:14
auto gets() const -> S
Definition results.hpp:46
auto match(Func &&f, Err &&r) noexcept
Definition results.hpp:70
constexpr bool invalid() const noexcept
Definition results.hpp:34
constexpr Result() noexcept
Definition results.hpp:13