39 using ValueType = std::conditional_t<
40 std::is_same_v<std::decay_t<T>,
void>, std::monostate,
T>;
45 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
47 explicit Result(
T1 t) : m_valueOrError{std::move(
t)}
52 typename std::enable_if_t<std::is_void_v<std::decay_t<T1>>> * =
nullptr>
53 explicit Result() : m_valueOrError{std::monostate{}}
56 explicit Result(Error error) : m_valueOrError{std::move(error)} {}
59 m_valueOrError{
other.m_valueOrError}
63 m_valueOrError{std::move(
other.m_valueOrError)}
69 m_valueOrError =
other.m_valueOrError;
78 m_valueOrError = std::move(
other.m_valueOrError);
89 return std::holds_alternative<ValueType>(m_valueOrError);
99 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
101 [[nodiscard]] T1 & get()
108#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
111 ErrorString{
"Detected attempt to get value from empty Result"}};
115 return std::get<T>(m_valueOrError);
120 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
122 [[nodiscard]]
const T1 & get()
const
129#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
132 ErrorString{
"Detected attempt to get value from empty Result"}};
136 return std::get<T>(m_valueOrError);
141 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
143 [[nodiscard]] T1 & operator*()
150 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
152 [[nodiscard]]
const T1 & operator*()
const
157 [[nodiscard]]
const Error & error()
const
164#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
166 throw RuntimeError{ErrorString{
167 "Detected attempt to get error from non-empty Result"}};
171 return std::get<Error>(m_valueOrError);
174 [[nodiscard]] Error & error()
181#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
183 throw RuntimeError{ErrorString{
184 "Detected attempt to get error from non-empty Result"}};
188 return std::get<Error>(m_valueOrError);
192 std::variant<ValueType, Error> m_valueOrError;