From: Joel Rosdahl Date: Sun, 3 Aug 2025 11:43:51 +0000 (+0200) Subject: enhance: Add TRY_ASSIGN macro X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d8854a9f9f9d32d3e8d7c3fd23fb58b43ad3557;p=thirdparty%2Fccache.git enhance: Add TRY_ASSIGN macro --- diff --git a/src/ccache/util/expected.hpp b/src/ccache/util/expected.hpp index e8a55372..9f79ff95 100644 --- a/src/ccache/util/expected.hpp +++ b/src/ccache/util/expected.hpp @@ -58,6 +58,13 @@ void throw_on_error(const T& value, std::string_view prefix); } \ } while (false) +#define TRY_ASSIGN(var_, expression_) \ + auto result_##__LINE__##_ = (expression_); \ + if (!result_##__LINE__##_) { \ + return tl::unexpected(std::move(result_##__LINE__##_.error())); \ + } \ + var_ = std::move(*result_##__LINE__##_) + // --- Inline implementations --- template