forked from qt-creator/qt-creator
tl_expected: Add error_or functions
These are in C++23's std::expected, but were missing in our C++20 -capable copy. Change-Id: I6a9bf0f62f7571bbb376361134757ea36c9e49f3 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -2039,6 +2039,19 @@ public:
|
||||
"T must be move-constructible and convertible to from U&&");
|
||||
return bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(v));
|
||||
}
|
||||
|
||||
template <class U> constexpr T error_or(U &&v) const & {
|
||||
static_assert(std::is_copy_constructible<E>::value &&
|
||||
std::is_convertible<U &&, E>::value,
|
||||
"E must be copy-constructible and convertible to from U&&");
|
||||
return !has_value() ? err().value() : static_cast<T>(std::forward<U>(v));
|
||||
}
|
||||
template <class U> TL_EXPECTED_11_CONSTEXPR T error_or(U &&v) && {
|
||||
static_assert(std::is_move_constructible<T>::value &&
|
||||
std::is_convertible<U &&, T>::value,
|
||||
"E must be move-constructible and convertible to from U&&");
|
||||
return !has_value() ? std::move(err().value()) : static_cast<E>(std::forward<U>(v));
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
Reference in New Issue
Block a user