42 using ValueWrapperInnerType = std::conditional_t<
43 std::is_void_v<std::decay_t<ValueType>>, std::nullptr_t,
44 std::decay_t<ValueType>>;
48 typename T1 = ValueType,
49 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
51 explicit Result(T1 t) :
52 m_valueOrError{ValueWrapper<std::decay_t<ValueType>>{std::move(t)}}
56 typename T1 = ValueType,
57 typename std::enable_if_t<std::is_void_v<std::decay_t<T1>>> * =
nullptr>
58 explicit Result() : m_valueOrError{ValueWrapper<std::nullptr_t>{}}
61 explicit Result(ErrorType error) : m_valueOrError{std::move(error)} {}
63 Result(
const Result<ValueType, ErrorType> & other) :
64 m_valueOrError{other.m_valueOrError}
67 Result(Result<ValueType, ErrorType> && other) :
68 m_valueOrError{std::move(other.m_valueOrError)}
71 Result & operator=(
const Result<ValueType, ErrorType> & other)
74 m_valueOrError = other.m_valueOrError;
80 Result & operator=(Result<ValueType, ErrorType> && other)
83 m_valueOrError = std::move(other.m_valueOrError);
92 [[nodiscard]]
bool isValid() const noexcept
94 return std::holds_alternative<ValueWrapper<ValueWrapperInnerType>>(
98 operator bool() const noexcept
104 typename T1 = ValueType,
105 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
107 [[nodiscard]] T1 & get()
114#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
117 ErrorString{
"Detected attempt to get value from empty Result"}};
121 return std::get<ValueWrapper<std::decay_t<ValueType>>>(m_valueOrError)
126 typename T1 = ValueType,
127 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
129 [[nodiscard]]
const T1 & get()
const
136#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
139 ErrorString{
"Detected attempt to get value from empty Result"}};
143 return std::get<ValueWrapper<std::decay_t<ValueType>>>(m_valueOrError)
148 typename T1 = ValueType,
149 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
151 [[nodiscard]] T1 & operator*()
157 typename T1 = ValueType,
158 typename std::enable_if_t<!std::is_void_v<std::decay_t<T1>>> * =
160 [[nodiscard]]
const T1 & operator*()
const
165 [[nodiscard]]
const ErrorType & error()
const
172#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
174 throw RuntimeError{ErrorString{
175 "Detected attempt to get error from non-empty Result"}};
179 return std::get<ErrorType>(m_valueOrError);
182 [[nodiscard]] ErrorType & error()
189#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
191 throw RuntimeError{ErrorString{
192 "Detected attempt to get error from non-empty Result"}};
196 return std::get<ErrorType>(m_valueOrError);
200 std::variant<ValueWrapper<ValueWrapperInnerType>, ErrorType> m_valueOrError;