From 077ececcf880409ccbf620539eb142aebf45e574 Mon Sep 17 00:00:00 2001
From: Mateusz Karbowiak <69864511+mtszkarbowiak@users.noreply.github.com>
Date: Sun, 6 Oct 2024 13:20:00 +0200
Subject: [PATCH] `Nullable` match
---
Source/Engine/Core/Types/Nullable.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/Source/Engine/Core/Types/Nullable.h b/Source/Engine/Core/Types/Nullable.h
index 9d8f3f65b..e1aae2ea3 100644
--- a/Source/Engine/Core/Types/Nullable.h
+++ b/Source/Engine/Core/Types/Nullable.h
@@ -331,6 +331,26 @@ public:
{
return _hasValue;
}
+
+
+ ///
+ /// Matches the wrapped value with a handler for the value or a handler for the null value.
+ ///
+ /// Value visitor handling valid nullable value.
+ /// Null visitor handling invalid nullable value.
+ /// Result of the call of one of handlers. Handlers must share the same result type.
+ template
+ FORCE_INLINE auto Match(ValueVisitor valueHandler, NullVisitor nullHandler) const
+ {
+ if (_hasValue)
+ {
+ return valueHandler(_value);
+ }
+ else
+ {
+ return nullHandler();
+ }
+ }
};
///