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)}
22 constexpr explicit operator bool() const noexcept
27 [[nodiscard]]
constexpr bool valid() const noexcept
29 return std::holds_alternative<S>(*
this);
31 [[nodiscard]]
constexpr bool invalid() const noexcept
36 [[nodiscard]]
constexpr auto get() const noexcept -> T
38 return (
invalid() ? std::get<T>(*
this) : T());
41 [[nodiscard]]
auto gets() const -> S
45 return std::move(std::get<S>(*
this));
47 throw std::runtime_error(
"Deref None");
62 template <
typename Func,
typename Err>
auto match(Func&& f, Err&& r)
noexcept
66 return f(std::forward<S>(std::get<S>(*
this)));
69 return r(std::forward<T>(std::get<T>(*
this)));
Definition results.hpp:12
constexpr bool valid() const noexcept
Definition results.hpp:27
constexpr Result(S &&s) noexcept
Definition results.hpp:18
constexpr auto get() const noexcept -> T
Definition results.hpp:36
constexpr Result(T const &&t) noexcept
Definition results.hpp:14
auto gets() const -> S
Definition results.hpp:41
auto match(Func &&f, Err &&r) noexcept
Definition results.hpp:62
constexpr bool invalid() const noexcept
Definition results.hpp:31
constexpr Result() noexcept
Definition results.hpp:13