18 template <
typename SUCCESS,
typename ERROR>
class Result {
20 std::variant<std::monostate, SUCCESS, ERROR> result {};
21 bool is_success {
true};
43 r.result = std::move(s);
66 r.result = std::move(e);
75 return is_success == other.is_success && result == other.result;
82 [[nodiscard]]
bool is_ok()
const {
83 return std::holds_alternative<SUCCESS>(result);
91 [[nodiscard]]
const SUCCESS&
get_ok() const & {
93 return std::get<SUCCESS>(result);
95 throw std::runtime_error(
"Cannot get ok value from error result");
105 return std::move(std::get<SUCCESS>(result));
107 throw std::runtime_error(
"Cannot consume ok value from error result");
117 return std::get<ERROR>(result);
119 throw std::runtime_error(
"Cannot get error value from success result");
129 return std::move(std::get<ERROR>(result));
131 throw std::runtime_error(
"Cannot consume error value from success result");
Result wrapper for success or error values.
SUCCESS consume_ok() &&
Move success value out of the result.
const ERROR & get_error() const &
Access error value as const reference.
static Result error(const ERROR &e)
Construct an error result from a const reference.
ERROR consume_error() &&
Move the error value out of the result.
bool is_ok() const
Check if the result represents success.
static Result error(ERROR &&e)
Construct an error result from an rvalue.
static Result success(SUCCESS &&s)
Construct a success result from an rvalue.
static Result success(const SUCCESS &s)
Construct a success result from a const reference.
bool operator==(const Result &other) const
Equality comparison based on status and payload.
const SUCCESS & get_ok() const &
Access success value as const reference.
ErrorType
Error codes returned by graph operations.
@ UNKNOWN
An unexpected internal error occurred.
@ VERTEX_NOT_FREE
The vertex cannot be removed because it still has incident edges.
@ ABSENT_VERTEX
The referenced vertex ID does not exist in the graph.
@ EDGE_ALREADY_EXISTS
An edge between the two vertices already exists.
@ INVALID_ARGUMENT
A supplied argument is invalid.
@ ABSENT_EDGE
The referenced edge ID does not exist in the graph.