12 template <
typename T,
typename E>
13 requires (!std::is_same_v<T, E>)
17 static constexpr auto is_constructible_v =
18 std::is_constructible_v<T, X> || std::is_constructible_v<E, X>;
25 Expected(
const Expected&) =
default;
26 Expected(Expected&&)
noexcept =
default;
27 ~Expected() =
default;
30 requires is_constructible_v<X>
31 Q_IMPLICIT Expected(X&& x) : data(std::forward<X>(x))
34 Expected& operator=(
const Expected&) =
default;
35 Expected& operator=(Expected&&)
noexcept =
default;
38 requires is_constructible_v<X>
39 Expected& operator=(X&& x)
41 data = std::forward<X>(x);
45 bool has_value()
const {
return std::holds_alternative<T>(data); }
46 explicit operator
bool()
const {
return has_value(); }
48 const value_type& value()
const& {
return std::get<T>(data); }
49 value_type& value() & {
return std::get<T>(data); }
50 value_type value() && {
return std::get<T>(std::move(data)); }
52 const value_type& operator*()
const& {
return value(); }
53 value_type& operator*() & {
return value(); }
55 const value_type* operator->()
const& {
return std::get_if<T>(&data); }
56 value_type* operator->() & {
return std::get_if<T>(&data); }
59 const T& value_or(
const U& fallback)
const&
66 T&& value_or(U&& fallback) &&
69 return std::move(value());
70 return std::forward<U>(fallback);
73 T&& move_value_or(T&& fallback)
76 return std::move(value());
77 return std::move(fallback);
80 const E& error()
const& {
return std::get<E>(data); }
81 E& error() & {
return std::get<E>(data); }
84 std::variant<T, E> data;