From 4f42c1b39e869f9b366d6dcaf1c2ed5c35bc4e7f Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 10 Apr 2025 14:04:03 +0200 Subject: [PATCH] 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 --- .../3rdparty/tl_expected/include/tl/expected.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libs/3rdparty/tl_expected/include/tl/expected.hpp b/src/libs/3rdparty/tl_expected/include/tl/expected.hpp index afee404d43e..f7aa2deee1b 100644 --- a/src/libs/3rdparty/tl_expected/include/tl/expected.hpp +++ b/src/libs/3rdparty/tl_expected/include/tl/expected.hpp @@ -2039,6 +2039,19 @@ public: "T must be move-constructible and convertible to from U&&"); return bool(*this) ? std::move(**this) : static_cast(std::forward(v)); } + + template constexpr T error_or(U &&v) const & { + static_assert(std::is_copy_constructible::value && + std::is_convertible::value, + "E must be copy-constructible and convertible to from U&&"); + return !has_value() ? err().value() : static_cast(std::forward(v)); + } + template TL_EXPECTED_11_CONSTEXPR T error_or(U &&v) && { + static_assert(std::is_move_constructible::value && + std::is_convertible::value, + "E must be move-constructible and convertible to from U&&"); + return !has_value() ? std::move(err().value()) : static_cast(std::forward(v)); + } }; namespace detail {