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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#pragma once
#ifndef ENUM_INDEXED_ARRAY_INL_H_
#error "Direct inclusion of this file is not allowed, include enum.h"
// For the sake of sane code completion.
#include "enum_indexed_array.h"
#endif
#include <library/cpp/yt/assert/assert.h>
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
template <class E, class T, E Min, E Max>
TEnumIndexedArray<E, T, Min, Max>::TEnumIndexedArray(std::initializer_list<std::pair<E, T>> elements)
{
for (const auto& [index, value] : elements) {
(*this)[index] = value;
}
}
template <class E, class T, E Min, E Max>
T& TEnumIndexedArray<E, T, Min, Max>::operator[] (E index)
{
YT_ASSERT(IsValidIndex(index));
return Items_[ToUnderlying(index) - ToUnderlying(Min)];
}
template <class E, class T, E Min, E Max>
const T& TEnumIndexedArray<E, T, Min, Max>::operator[] (E index) const
{
return const_cast<TEnumIndexedArray&>(*this)[index];
}
template <class E, class T, E Min, E Max>
T* TEnumIndexedArray<E, T, Min, Max>::begin()
{
return Items_.data();
}
template <class E, class T, E Min, E Max>
const T* TEnumIndexedArray<E, T, Min, Max>::begin() const
{
return Items_.data();
}
template <class E, class T, E Min, E Max>
T* TEnumIndexedArray<E, T, Min, Max>::end()
{
return begin() + Size;
}
template <class E, class T, E Min, E Max>
const T* TEnumIndexedArray<E, T, Min, Max>::end() const
{
return begin() + Size;
}
template <class E, class T, E Min, E Max>
constexpr size_t TEnumIndexedArray<E, T, Min, Max>::size() const
{
return Size;
}
template <class E, class T, E Min, E Max>
bool TEnumIndexedArray<E, T, Min, Max>::IsValidIndex(E index)
{
return index >= Min && index <= Max;
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
|