Added void variant of Result.
This commit is contained in:
parent
32ccaad00a
commit
5a111df9ea
@ -60,6 +60,32 @@ public:
|
|||||||
[[nodiscard]] const TError& getError() const MIJIN_NOEXCEPT { return std::get<TError>(state_); }
|
[[nodiscard]] const TError& getError() const MIJIN_NOEXCEPT { return std::get<TError>(state_); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace impl
|
||||||
|
{
|
||||||
|
struct ResultSuccess {};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TError>
|
||||||
|
class ResultBase<void, TError> : public ResultBase<impl::ResultSuccess, TError>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ResultBase() MIJIN_NOEXCEPT : ResultBase<impl::ResultSuccess, TError>(impl::ResultSuccess{}) {}
|
||||||
|
ResultBase(const ResultBase&) MIJIN_NOEXCEPT = default;
|
||||||
|
ResultBase(ResultBase&&) MIJIN_NOEXCEPT = default;
|
||||||
|
ResultBase(TError errorValue) MIJIN_NOEXCEPT : ResultBase<impl::ResultSuccess, TError>(std::move(errorValue)) {}
|
||||||
|
|
||||||
|
ResultBase& operator=(const ResultBase&) = default;
|
||||||
|
ResultBase& operator=(ResultBase&&) = default;
|
||||||
|
|
||||||
|
impl::ResultSuccess& operator*() MIJIN_NOEXCEPT = delete;
|
||||||
|
const impl::ResultSuccess& operator*() const MIJIN_NOEXCEPT = delete;
|
||||||
|
impl::ResultSuccess* operator->() MIJIN_NOEXCEPT = delete;
|
||||||
|
const impl::ResultSuccess* operator->() const MIJIN_NOEXCEPT = delete;
|
||||||
|
|
||||||
|
[[nodiscard]] impl::ResultSuccess& getValue() MIJIN_NOEXCEPT = delete;
|
||||||
|
[[nodiscard]] const impl::ResultSuccess& getValue() const MIJIN_NOEXCEPT = delete;
|
||||||
|
};
|
||||||
|
|
||||||
struct ResultError
|
struct ResultError
|
||||||
{
|
{
|
||||||
std::string message;
|
std::string message;
|
||||||
@ -73,7 +99,7 @@ struct ResultError
|
|||||||
ResultError& operator=(ResultError&&) MIJIN_NOEXCEPT = default;
|
ResultError& operator=(ResultError&&) MIJIN_NOEXCEPT = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename TSuccess>
|
template<typename TSuccess = void>
|
||||||
using Result = ResultBase<TSuccess, ResultError>;
|
using Result = ResultBase<TSuccess, ResultError>;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user