diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
commit | fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch) | |
tree | 4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /mfbt/EnumeratedArray.h | |
parent | Releasing progress-linux version 124.0.1-1~progress7.99u1. (diff) | |
download | firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mfbt/EnumeratedArray.h')
-rw-r--r-- | mfbt/EnumeratedArray.h | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/mfbt/EnumeratedArray.h b/mfbt/EnumeratedArray.h index f6edff4875..ba902d94b9 100644 --- a/mfbt/EnumeratedArray.h +++ b/mfbt/EnumeratedArray.h @@ -12,6 +12,7 @@ #include <utility> #include "mozilla/Array.h" +#include "EnumTypeTraits.h" namespace mozilla { @@ -33,19 +34,23 @@ namespace mozilla { * Count * }; * - * EnumeratedArray<AnimalSpecies, AnimalSpecies::Count, int> headCount; + * EnumeratedArray<AnimalSpecies, int, AnimalSpecies::Count> headCount; * * headCount[AnimalSpecies::Cow] = 17; * headCount[AnimalSpecies::Sheep] = 30; * + * If the enum class has contiguous values and provides a specialization of + * mozilla::MaxContiguousEnumValue then the size will be calculated as the max + * value + 1. */ -template <typename IndexType, IndexType SizeAsEnumValue, typename ValueType> +template <typename Enum, typename ValueType, + size_t Size = ContiguousEnumSize<Enum>::value> class EnumeratedArray { - public: - static const size_t kSize = size_t(SizeAsEnumValue); - private: - typedef Array<ValueType, kSize> ArrayType; + static_assert(UnderlyingValue(MinContiguousEnumValue<Enum>::value) == 0, + "All indexes would need to be corrected if min != 0"); + + using ArrayType = Array<ValueType, Size>; ArrayType mArray; @@ -56,16 +61,16 @@ class EnumeratedArray { MOZ_IMPLICIT constexpr EnumeratedArray(Args&&... aArgs) : mArray{std::forward<Args>(aArgs)...} {} - ValueType& operator[](IndexType aIndex) { return mArray[size_t(aIndex)]; } + ValueType& operator[](Enum aIndex) { return mArray[size_t(aIndex)]; } - const ValueType& operator[](IndexType aIndex) const { + const ValueType& operator[](Enum aIndex) const { return mArray[size_t(aIndex)]; } - typedef typename ArrayType::iterator iterator; - typedef typename ArrayType::const_iterator const_iterator; - typedef typename ArrayType::reverse_iterator reverse_iterator; - typedef typename ArrayType::const_reverse_iterator const_reverse_iterator; + using iterator = typename ArrayType::iterator; + using const_iterator = typename ArrayType::const_iterator; + using reverse_iterator = typename ArrayType::reverse_iterator; + using const_reverse_iterator = typename ArrayType::const_reverse_iterator; // Methods for range-based for loops. iterator begin() { return mArray.begin(); } |