11 using InternalType = std::variant<T, ERR>;
12 const InternalType held;
14 Result(InternalType&& value)
15 : held(std::move(value)) {}
18 const T* operator->()
const {
19 if (held.index() != 0) {
20 throw std::runtime_error(
"Illegal access into error result");
23 return &(std::get<T>(held));
26 bool isOk()
const {
return held.index() == 0; }
27 bool isError()
const {
return held.index() == 1; }
29 const T& unwrap() {
return std::get<0>(held); }
30 const ERR& error() {
return std::get<1>(held); }
32 static Result<T, ERR> ok(T&& value) {
33 return Result(InternalType(std::in_place_index<0>, std::move(value)));
35 static Result<T, ERR> err(ERR&& value) {
36 return Result(InternalType(std::in_place_index<1>, std::move(value)));