aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/misc/enum-inl.h
diff options
context:
space:
mode:
authorhiddenpath <hiddenpath@yandex-team.com>2025-03-25 14:31:21 +0300
committerhiddenpath <hiddenpath@yandex-team.com>2025-03-25 14:59:32 +0300
commit142f1b5904ca33612aa65b98a10444ea655b0ab1 (patch)
tree4369739ee8a48fa23a5fa6196d63236c1e548708 /library/cpp/yt/misc/enum-inl.h
parentfb0706c704e0253cc65a489b324ccec66ef85bf8 (diff)
downloadydb-142f1b5904ca33612aa65b98a10444ea655b0ab1.tar.gz
Make some methods of smart enum being constexpr
commit_hash:c29f08fc16d8bd974d4ce516af499de848607ab8
Diffstat (limited to 'library/cpp/yt/misc/enum-inl.h')
-rw-r--r--library/cpp/yt/misc/enum-inl.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/library/cpp/yt/misc/enum-inl.h b/library/cpp/yt/misc/enum-inl.h
index d8037bbf74..4cd668ebf0 100644
--- a/library/cpp/yt/misc/enum-inl.h
+++ b/library/cpp/yt/misc/enum-inl.h
@@ -115,13 +115,14 @@ constexpr bool CheckDomainNames(const TNames& names)
[[maybe_unused]] static constexpr bool IsMonotonic = \
::NYT::NDetail::CheckValuesMonotonic(Values); \
\
- static TStringBuf GetTypeName() \
+ static constexpr TStringBuf TypeName = PP_STRINGIZE(enumType); \
+ \
+ static constexpr TStringBuf GetTypeName() \
{ \
- static constexpr TStringBuf Result = PP_STRINGIZE(enumType); \
- return Result; \
+ return TypeName; \
} \
\
- static const std::optional<TStringBuf> FindLiteralByValue(T value) \
+ static constexpr std::optional<TStringBuf> FindLiteralByValue(T value) \
{ \
for (int i = 0; i < GetDomainSize(); ++i) { \
if (Values[i] == value) { \
@@ -131,7 +132,7 @@ constexpr bool CheckDomainNames(const TNames& names)
return std::nullopt; \
} \
\
- static std::optional<T> FindValueByLiteral(TStringBuf literal) \
+ static constexpr std::optional<T> FindValueByLiteral(TStringBuf literal) \
{ \
for (int i = 0; i < GetDomainSize(); ++i) { \
if (Names[i] == literal) { \
@@ -292,7 +293,7 @@ std::vector<T> TEnumTraitsWithKnownDomain<T, true>::Decompose(T value)
////////////////////////////////////////////////////////////////////////////////
template <class T>
-TStringBuf TEnumTraits<T, true>::GetTypeName()
+constexpr TStringBuf TEnumTraits<T, true>::GetTypeName()
{
return TEnumTraitsImpl<T>::GetTypeName();
}
@@ -305,13 +306,13 @@ constexpr std::optional<T> TEnumTraits<T, true>::TryGetUnknownValue()
}
template <class T>
-std::optional<T> TEnumTraits<T, true>::FindValueByLiteral(TStringBuf literal)
+constexpr std::optional<T> TEnumTraits<T, true>::FindValueByLiteral(TStringBuf literal)
{
return TEnumTraitsImpl<T>::FindValueByLiteral(literal);
}
template <class T>
-std::optional<TStringBuf> TEnumTraits<T, true>::FindLiteralByValue(T value)
+constexpr std::optional<TStringBuf> TEnumTraits<T, true>::FindLiteralByValue(T value)
{
return TEnumTraitsImpl<T>::FindLiteralByValue(value);
}
@@ -349,7 +350,7 @@ TString TEnumTraits<T, true>::ToString(T value)
}
template <class T>
-T TEnumTraits<T, true>::FromString(TStringBuf literal)
+constexpr T TEnumTraits<T, true>::FromString(TStringBuf literal)
{
auto optionalValue = FindValueByLiteral(literal);
if (!optionalValue) {