summaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorbabenko <[email protected]>2026-06-15 02:16:08 +0300
committerbabenko <[email protected]>2026-06-15 02:36:20 +0300
commitf8cd3660cc9c26e7dcbc92b9c226dece12649d90 (patch)
tree9bef51d3e6dc5acdff3c2476b5660d0aeec7fc3f /library/cpp
parent972b95687df432234ca66ad90d59ac74ae6048e3 (diff)
Add YT_DEFINE_SENTINEL_OPTIONAL macro
Add a macro for defining `TSentinelOptional` type aliases when the value type is not structural (e.g. has protected members) and therefore cannot use `TValueSentinel<V>`. The macro collapses the boilerplate sentinel struct plus `using` declaration into a single line: ```cpp // before struct TInstantSentinel { static constexpr auto Sentinel = TInstant::Zero(); }; using TSentinelOptionalInstant = TSentinelOptional<TInstant, TInstantSentinel>; // after YT_DEFINE_SENTINEL_OPTIONAL(TSentinelOptionalInstant, TInstant, TInstant::Zero()); ``` Also convert the existing call sites in `service_detail.cpp` and `inferrum/block_cache.cpp`. commit_hash:5dcdeb8db215736b0ce5a5b71f30aead91c7b8e8
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/containers/sentinel_optional.h14
-rw-r--r--library/cpp/yt/containers/unittests/sentinel_optional_ut.cpp6
2 files changed, 17 insertions, 3 deletions
diff --git a/library/cpp/yt/containers/sentinel_optional.h b/library/cpp/yt/containers/sentinel_optional.h
index 1d573550db9..6178327e29f 100644
--- a/library/cpp/yt/containers/sentinel_optional.h
+++ b/library/cpp/yt/containers/sentinel_optional.h
@@ -109,6 +109,20 @@ private:
} // namespace NYT
+//! Defines a type alias for |TSentinelOptional<type, ...>| with an inline sentinel struct.
+/*!
+ * Example:
+ * YT_DEFINE_SENTINEL_OPTIONAL(TInstantOpt, TInstant, TInstant::Zero());
+ */
+#define YT_DEFINE_SENTINEL_OPTIONAL(name, type, sentinel_value) \
+ struct name##Sentinel \
+ { \
+ static constexpr auto Sentinel = (sentinel_value); \
+ }; \
+ using name = ::NYT::TSentinelOptional<type, name##Sentinel>
+
+////////////////////////////////////////////////////////////////////////////////
+
#define SENTINEL_OPTIONAL_INL_H_
#include "sentinel_optional-inl.h"
#undef SENTINEL_OPTIONAL_INL_H_
diff --git a/library/cpp/yt/containers/unittests/sentinel_optional_ut.cpp b/library/cpp/yt/containers/unittests/sentinel_optional_ut.cpp
index 64ec5a04367..3bce427555a 100644
--- a/library/cpp/yt/containers/unittests/sentinel_optional_ut.cpp
+++ b/library/cpp/yt/containers/unittests/sentinel_optional_ut.cpp
@@ -10,7 +10,7 @@ namespace {
////////////////////////////////////////////////////////////////////////////////
-using TIntOpt = TSentinelOptional<int, TValueSentinel<-1>>;
+YT_DEFINE_SENTINEL_OPTIONAL(TIntOpt, int, -1);
////////////////////////////////////////////////////////////////////////////////
@@ -153,7 +153,7 @@ TEST(TSentinelOptionalTest, ConstAccess)
////////////////////////////////////////////////////////////////////////////////
// Pointer sentinel.
-using TPtrOpt = TSentinelOptional<int*, TValueSentinel<nullptr>>;
+YT_DEFINE_SENTINEL_OPTIONAL(TPtrOpt, int*, nullptr);
TEST(TSentinelOptionalTest, PointerSentinel)
{
@@ -178,7 +178,7 @@ enum class EColor
Unknown,
};
-using TColorOpt = TSentinelOptional<EColor, TValueSentinel<EColor::Unknown>>;
+YT_DEFINE_SENTINEL_OPTIONAL(TColorOpt, EColor, EColor::Unknown);
TEST(TSentinelOptionalTest, EnumSentinel)
{