Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
Result.hpp
1#pragma once
2
3#include <variant>
4
5namespace Grindstone {
6 template<typename Value, typename Error>
7 struct Result {
8 static_assert(std::is_trivially_copyable_v<Value>);
9 static_assert(std::is_trivially_copyable_v<Error>);
10
11 Result() = default;
12 Result(Value val) : storage(val) {}
13 Result(Error err) : storage(err) {}
14
15 Value GetValue() const {
16 return std::get<Value>(storage);
17 }
18
19 Error GetError() const {
20 return std::get<Error>(storage);
21 }
22
23 bool HasValue() const noexcept {
24 return std::holds_alternative<Value>(storage);
25 }
26
27 bool HasError() const noexcept {
28 return std::holds_alternative<Error>(storage);
29 }
30
31 operator bool() const noexcept {
32 return std::holds_alternative<Value>(storage);
33 }
34
35 std::variant<Value, Error> storage;
36 };
37}
Definition Assert.hpp:16