From db3e34b2bac0b5e4d55fa8a174c2bb776074b632 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 19 Nov 2022 18:38:01 +0100 Subject: [PATCH] Result: Add try_set_value() This helper returns true if the Result contains a value, or false if it doesn't. Additionally, if it has a value, it sets the passed reference to it. --- luna/Result.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/luna/Result.h b/luna/Result.h index e5e99ae0..1aec130f 100644 --- a/luna/Result.h +++ b/luna/Result.h @@ -104,6 +104,13 @@ template class Result return other; } + bool try_set_value(T& ref) + { + if (!has_value()) return false; + ref = m_storage.fetch_reference(); + return true; + } + T release_value() { check(has_value());