-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFailureOr.h
38 lines (35 loc) · 886 Bytes
/
FailureOr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include "Forward.h"
#include "ImmutableString.h"
#include "SharedEnums.h"
#include "Value.h"
//Used in some contexts to store a runtime when the interpreter maybe not be available
//(or might not exist, as is the case during const-folding)
struct FailureOr
{
struct Failure
{
ErrorCode code;
ImmutableString what;
};
bool didError;
std::variant<Value, Failure> data;
FailureOr(Value&& ret)
:didError(false)
,data(ret)
{
}
FailureOr(const ImmutableString& _what)
:didError(true)
,data(Failure{ ErrorCode::Unknown, _what })
{
}
FailureOr(ErrorCode _code, const ImmutableString& _what)
:didError(true)
{
Failure fail = { _code, _what };
data = std::variant<Value, Failure>(fail);
}
Value get_or_throw(Interpreter&);
Value must_get();
};