aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorgrebelnik <grebelnik@yandex-team.com>2023-07-13 16:42:24 +0300
committergrebelnik <grebelnik@yandex-team.com>2023-07-13 16:42:24 +0300
commit401f9575911308aa98bc0b4e010e8dc79cfa8b36 (patch)
treeed428d69f2f9baea3f6eac3c14a833082506eec3 /library/cpp
parent6de7fc0cd1c34f1e38b314eb169e4508a13ec3c3 (diff)
downloadydb-401f9575911308aa98bc0b4e010e8dc79cfa8b36.tar.gz
unified-agent - fix static initialization order problem
unified-agent - fix static initialization order problem
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/unified_agent_client/enum.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/library/cpp/unified_agent_client/enum.h b/library/cpp/unified_agent_client/enum.h
index b21e21acb0..ad08efb723 100644
--- a/library/cpp/unified_agent_client/enum.h
+++ b/library/cpp/unified_agent_client/enum.h
@@ -8,23 +8,26 @@ namespace NUnifiedAgent {
using TEnumNames = TVector<const TString*>;
template <typename TEnum>
- TEnumNames BuildEnumNames() {
+ TEnumNames* BuildEnumNames() {
const auto names = GetEnumNames<TEnum>();
- auto result = TEnumNames(names.size());
+ TEnumNames* result = new TEnumNames(names.size());
size_t index = 0;
for (const auto& p: names) {
Y_VERIFY(static_cast<size_t>(p.first) == index);
- result[index++] = &p.second;
+ (*result)[index++] = &p.second;
}
return result;
}
template <typename TEnum>
- inline const auto EnumNames = BuildEnumNames<TEnum>();
+ const TEnumNames& EnumNamesVec() {
+ static const TEnumNames* EnumNames = BuildEnumNames<TEnum>();
+ return *EnumNames;
+ }
}
template <typename TEnum, typename = std::enable_if_t<std::is_enum_v<TEnum>>>
inline const TString& NameOf(TEnum val) noexcept {
- return *NPrivate::EnumNames<TEnum>[static_cast<size_t>(val)];
+ return *NPrivate::EnumNamesVec<TEnum>()[static_cast<size_t>(val)];
}
}