blob: b21e21acb0078d1af690073c64072cb08d157880 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#pragma once
#include <util/generic/serialized_enum.h>
#include <util/generic/vector.h>
namespace NUnifiedAgent {
namespace NPrivate {
using TEnumNames = TVector<const TString*>;
template <typename TEnum>
TEnumNames BuildEnumNames() {
const auto names = GetEnumNames<TEnum>();
auto result = 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;
}
return result;
}
template <typename TEnum>
inline const auto EnumNames = BuildEnumNames<TEnum>();
}
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)];
}
}
|