diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-01-31 17:22:33 +0300 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-01-31 17:22:33 +0300 |
commit | 52be5dbdd420165c68e7e90ba8f1d2f00da041f6 (patch) | |
tree | 5d47f5b2ff4e6a7c8e75d33931a1e683949b7229 /library/cpp/yt/containers/enum_indexed_array-inl.h | |
parent | ea57c8867ceca391357c3c5ffcc5ba6738b49adc (diff) | |
parent | 809f0cf2fdfddfbeacc2256ffdbaaf5808ce5ed4 (diff) | |
download | ydb-52be5dbdd420165c68e7e90ba8f1d2f00da041f6.tar.gz |
Merge branch 'mergelibs12' into main
Diffstat (limited to 'library/cpp/yt/containers/enum_indexed_array-inl.h')
-rw-r--r-- | library/cpp/yt/containers/enum_indexed_array-inl.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/library/cpp/yt/containers/enum_indexed_array-inl.h b/library/cpp/yt/containers/enum_indexed_array-inl.h new file mode 100644 index 0000000000..edda891683 --- /dev/null +++ b/library/cpp/yt/containers/enum_indexed_array-inl.h @@ -0,0 +1,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 |