7 #include "arg_router/exception.hpp"
18 template <
typename ResultType,
typename ExceptionType>
21 static_assert(!std::is_same_v<ResultType, ExceptionType>,
22 "Result and exception argument cannot be same type");
42 constexpr
result(ExceptionType ex) noexcept : data_{std::move(ex)} {}
48 [[nodiscard]] constexpr
bool has_result() const noexcept {
return data_.index() == 0; }
60 [[nodiscard]]
explicit constexpr
operator bool() const noexcept {
return has_result(); }
78 return std::get<0>(data_) == std::get<0>(other.data_);
88 return !(*
this == other);
100 if (lhs.has_error()) {
103 return std::get<0>(lhs.data_) == rhs;
115 return !(lhs == rhs);
125 const result& rhs) noexcept
137 const result& rhs) noexcept
139 return !(lhs == rhs);
149 return has_result() ? &std::get<0>(data_) :
nullptr;
158 return has_result() ? &std::get<0>(data_) :
nullptr;
171 return std::move(std::get<0>(data_));
173 throw std::move(std::get<1>(data_));
182 [[nodiscard]]
auto get() const
183 -> std::conditional_t<(sizeof(std::
size_t) >= sizeof(
result_type)) &&
189 return std::get<0>(data_);
206 std::variant<result_type, exception_type> data_;
constexpr bool has_error() const noexcept
constexpr bool operator!=(const result &other) const noexcept
constexpr bool operator==(const result &other) const noexcept
constexpr friend bool operator!=(const result &lhs, const result_type &rhs) noexcept
result_type * get_if() noexcept
constexpr bool operator!() const noexcept
auto get() const -> std::conditional_t<(sizeof(std::size_t) >=sizeof(result_type)) &&std::is_copy_constructible_v< result_type >, result_type, const result_type & >
void throw_exception() const
constexpr friend bool operator==(const result &lhs, const result_type &rhs) noexcept
const result_type * get_if() const noexcept
constexpr result(ExceptionType ex) noexcept
constexpr friend bool operator==(const result_type &lhs, const result &rhs) noexcept
constexpr bool has_result() const noexcept
std::decay_t< ResultType > result_type
constexpr result(result_type value) noexcept
ExceptionType exception_type
constexpr friend bool operator!=(const result_type &lhs, const result &rhs) noexcept