15 template<
typename T =
int>
18 Error(
const T& num,
const std::string& msg =
"");
21 const T& code()
const;
22 const std::string& message()
const;
35 template<
typename T,
typename E = Error<>>
46 const T& value()
const;
47 const E& error()
const;
50 operator bool()
const;
52 constexpr T* operator->() {
return &*_val; }
53 constexpr const T* operator->()
const {
return &*_val; }
54 constexpr T& operator*() {
return *_val; }
55 constexpr const T& operator*()
const {
return *_val; }
58 std::optional<T> _val;
59 std::optional<E> _err;
72 const E& error()
const;
75 operator bool()
const;
78 std::optional<E> _err;
89 const T& Error<T>::code()
const
93 const std::string& Error<T>::message()
const
97 template<
typename T,
typename E>
98 Result<T, E>::Result(T&& val) :
102 template<
typename T,
typename E>
103 Result<T, E>::Result(
const E& err) :
108 Result<void, E>::Result(
const E& err) :
112 template<
typename T,
typename E>
113 T& Result<T, E>::value()
115 SL_ASSERT(good(),
"Result not good!");
119 template<
typename T,
typename E>
120 const T& Result<T, E>::value()
const
122 SL_ASSERT(good(),
"Result not good!");
126 template<
typename T,
typename E>
127 const E& Result<T, E>::error()
const
129 SL_ASSERT(_err.has_value(),
"Result is good!");
134 const E& Result<void, E>::error()
const
136 SL_ASSERT(_err.has_value(),
"Result is good!");
140 template<
typename T,
typename E>
141 bool Result<T, E>::good()
const
143 return _val.has_value();
147 bool Result<void, E>::good()
const
149 return !_err.has_value();
152 template<
typename T,
typename E>
153 Result<T, E>::operator bool()
const
157 Result<void, E>::operator bool()
const
Simple wrapper class for passing errors along to user.
Definition Result.hpp:17
Basic way to return a value or an error.
Definition Result.hpp:37