diff options
author | babenko <babenko@yandex-team.com> | 2024-01-27 16:19:45 +0300 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-01-31 14:23:57 +0300 |
commit | 9c90564d50be397a9a1ae46f2531b39bde56bcc1 (patch) | |
tree | b5a121b758fded45e4a2021e1fe6199a814ac2ee | |
parent | 3cb4ac068569140f8d226b29df8be1b997cebe36 (diff) | |
download | ydb-9c90564d50be397a9a1ae46f2531b39bde56bcc1.tar.gz |
Drop TEnumIndexedVector
-rw-r--r-- | library/cpp/yt/misc/enum-inl.h | 61 | ||||
-rw-r--r-- | library/cpp/yt/misc/enum.h | 46 | ||||
-rw-r--r-- | library/cpp/yt/string/format-inl.h | 21 | ||||
-rw-r--r-- | library/cpp/yt/string/unittests/enum_ut.cpp | 1 |
4 files changed, 0 insertions, 129 deletions
diff --git a/library/cpp/yt/misc/enum-inl.h b/library/cpp/yt/misc/enum-inl.h index 02493d7ac5..5e1d04da1f 100644 --- a/library/cpp/yt/misc/enum-inl.h +++ b/library/cpp/yt/misc/enum-inl.h @@ -302,67 +302,6 @@ T TEnumTraits<T, true>::FromString(TStringBuf literal) //////////////////////////////////////////////////////////////////////////////// -template <class E, class T, E Min, E Max> -constexpr TEnumIndexedVector<E, T, Min, Max>::TEnumIndexedVector() - : Items_{} -{ } - -template <class E, class T, E Min, E Max> -constexpr TEnumIndexedVector<E, T, Min, Max>::TEnumIndexedVector(std::initializer_list<T> elements) - : Items_{} -{ - Y_ASSERT(std::distance(elements.begin(), elements.end()) <= N); - size_t index = 0; - for (const auto& element : elements) { - Items_[index++] = element; - } -} - -template <class E, class T, E Min, E Max> -T& TEnumIndexedVector<E, T, Min, Max>::operator[] (E index) -{ - Y_ASSERT(index >= Min && index <= Max); - return Items_[ToUnderlying(index) - ToUnderlying(Min)]; -} - -template <class E, class T, E Min, E Max> -const T& TEnumIndexedVector<E, T, Min, Max>::operator[] (E index) const -{ - return const_cast<TEnumIndexedVector&>(*this)[index]; -} - -template <class E, class T, E Min, E Max> -T* TEnumIndexedVector<E, T, Min, Max>::begin() -{ - return Items_.data(); -} - -template <class E, class T, E Min, E Max> -const T* TEnumIndexedVector<E, T, Min, Max>::begin() const -{ - return Items_.data(); -} - -template <class E, class T, E Min, E Max> -T* TEnumIndexedVector<E, T, Min, Max>::end() -{ - return begin() + N; -} - -template <class E, class T, E Min, E Max> -const T* TEnumIndexedVector<E, T, Min, Max>::end() const -{ - return begin() + N; -} - -template <class E, class T, E Min, E Max> -bool TEnumIndexedVector<E, T, Min, Max>::IsDomainValue(E value) -{ - return value >= Min && value <= Max; -} - -//////////////////////////////////////////////////////////////////////////////// - #define ENUM__BINARY_BITWISE_OPERATOR(T, assignOp, op) \ [[maybe_unused]] inline constexpr T operator op (T lhs, T rhs) \ { \ diff --git a/library/cpp/yt/misc/enum.h b/library/cpp/yt/misc/enum.h index 9da79b9fd3..954b63cbc0 100644 --- a/library/cpp/yt/misc/enum.h +++ b/library/cpp/yt/misc/enum.h @@ -185,52 +185,6 @@ struct TEnumTraits<T, true> //////////////////////////////////////////////////////////////////////////////// -// TODO(babenko): drop in favor of TEnumIndexedArray -//! A statically sized vector with elements of type |T| indexed by -//! the items of enumeration type |E|. -/*! - * Items are value-initialized on construction. - */ -template < - class E, - class T, - E Min = TEnumTraits<E>::GetMinValue(), - E Max = TEnumTraits<E>::GetMaxValue() -> -class TEnumIndexedVector -{ -public: - using TIndex = E; - using TValue = T; - - constexpr TEnumIndexedVector(); - constexpr TEnumIndexedVector(std::initializer_list<T> elements); - - constexpr TEnumIndexedVector(const TEnumIndexedVector&) = default; - constexpr TEnumIndexedVector(TEnumIndexedVector&&) noexcept = default; - - constexpr TEnumIndexedVector& operator=(const TEnumIndexedVector&) = default; - constexpr TEnumIndexedVector& operator=(TEnumIndexedVector&&) noexcept = default; - - T& operator[] (E index); - const T& operator[] (E index) const; - - // STL interop. - T* begin(); - const T* begin() const; - T* end(); - const T* end() const; - - static bool IsDomainValue(E value); - -private: - using TUnderlying = std::underlying_type_t<E>; - static constexpr int N = static_cast<TUnderlying>(Max) - static_cast<TUnderlying>(Min) + 1; - std::array<T, N> Items_; -}; - -//////////////////////////////////////////////////////////////////////////////// - //! Returns |true| iff the enumeration value is not bitwise zero. template <typename E> requires TEnumTraits<E>::IsBitEnum diff --git a/library/cpp/yt/string/format-inl.h b/library/cpp/yt/string/format-inl.h index c198fdcd65..776b48e7fb 100644 --- a/library/cpp/yt/string/format-inl.h +++ b/library/cpp/yt/string/format-inl.h @@ -415,27 +415,6 @@ struct TValueFormatter<TEnumIndexedArray<E, T>> } }; -// TEnumIndexedVector -template <class E, class T> -struct TValueFormatter<TEnumIndexedVector<E, T>> -{ - static void Do(TStringBuilderBase* builder, const TEnumIndexedVector<E, T>& collection, TStringBuf format) - { - builder->AppendChar('{'); - bool firstItem = true; - for (const auto& index : TEnumTraits<E>::GetDomainValues()) { - if (!firstItem) { - builder->AppendString(DefaultJoinToStringDelimiter); - } - FormatValue(builder, index, format); - builder->AppendString(": "); - FormatValue(builder, collection[index], format); - firstItem = false; - } - builder->AppendChar('}'); - } -}; - // std::pair template <class T1, class T2> struct TValueFormatter<std::pair<T1, T2>> diff --git a/library/cpp/yt/string/unittests/enum_ut.cpp b/library/cpp/yt/string/unittests/enum_ut.cpp index 91a8b04500..2c368e85d4 100644 --- a/library/cpp/yt/string/unittests/enum_ut.cpp +++ b/library/cpp/yt/string/unittests/enum_ut.cpp @@ -14,7 +14,6 @@ namespace { DEFINE_ENUM(ESample, (One)(Two)); static_assert(TFormatTraits<ESample>::HasCustomFormatValue); static_assert(TFormatTraits<TEnumIndexedArray<ESample, int>>::HasCustomFormatValue); -static_assert(TFormatTraits<TEnumIndexedVector<ESample, int>>::HasCustomFormatValue); DEFINE_ENUM(EColor, (Red) |