12#include <switchboard/SBAny.hpp>
18namespace switchboard {
23struct SWITCHBOARDSDK_EXPORT
Error {
39class SWITCHBOARDSDK_EXPORT Result {
41 using ValueType = std::conditional_t<std::is_void_v<T>, std::monostate, T>;
42 std::variant<ValueType, Error> result;
45 explicit Result(ValueType
value) : result(std::move(
value)) {}
54 return std::holds_alternative<ValueType>(result);
63 return std::holds_alternative<Error>(result);
71 [[nodiscard]] ValueType
value()
const {
73 throw std::runtime_error(
"Result does not contain a value, operation failed.");
75 return std::get<ValueType>(result);
85 throw std::runtime_error(
"Result does not contain an error, operation was successful.");
87 return std::get<Error>(result);
98 [[nodiscard]] Result<SBAny>
toAny()
const {
115Result<T> makeSuccess(T value) {
116 return Result<T>(std::move(value));
136Result<T> makeError(std::string errorMessage) {
Represents the result of an operation that can either succeed or fail.
Definition Result.hpp:39
bool isSuccess() const
Returns true if the operation was successful.
Definition Result.hpp:53
ValueType value() const
Returns the value of the operation if it was successful.
Definition Result.hpp:71
Result< SBAny > toAny() const
Converts the result to a SBAny type.
Definition Result.hpp:98
Error error() const
Returns the error of the operation if it failed.
Definition Result.hpp:83
bool isError() const
Returns true if the operation failed.
Definition Result.hpp:62
A versatile container class that can hold values of various types.
Definition SBAny.hpp:53
Represents an error that can occur during an operation.
Definition Result.hpp:23
std::string message
Error message.
Definition Result.hpp:25
Error(std::string msg)
Error constructor.
Definition Result.hpp:32