Codefix 1d10e8ee6: explicitly delete unwanted indexers (#15522)

Prevents typed-indexers being used via implicit conversion.
This commit is contained in:
Peter Nelson
2026-04-23 08:32:25 +01:00
committed by GitHub
parent 146499ab99
commit 44c63bc400
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -37,12 +37,16 @@ concept ConvertibleThroughBaseOrTo = std::is_convertible_v<T, TTo> || Convertibl
template <typename Container, typename Index>
class TypedIndexContainer : public Container {
public:
Container::reference at(size_t pos) = delete;
Container::reference at(const Index &pos) { return this->Container::at(pos.base()); }
Container::const_reference at(size_t pos) const = delete;
Container::const_reference at(const Index &pos) const { return this->Container::at(pos.base()); }
Container::reference operator[](size_t pos) = delete;
Container::reference operator[](const Index &pos) { return this->Container::operator[](pos.base()); }
Container::const_reference operator[](size_t pos) const = delete;
Container::const_reference operator[](const Index &pos) const { return this->Container::operator[](pos.base()); }
};
+4
View File
@@ -246,12 +246,16 @@ public:
template <typename Container, typename Index>
class EnumClassIndexContainer : public Container {
public:
Container::reference at(size_t pos) = delete;
Container::reference at(const Index &pos) { return this->Container::at(to_underlying(pos)); }
Container::const_reference at(size_t pos) const = delete;
Container::const_reference at(const Index &pos) const { return this->Container::at(to_underlying(pos)); }
Container::reference operator[](size_t pos) = delete;
Container::reference operator[](const Index &pos) { return this->Container::operator[](to_underlying(pos)); }
Container::const_reference operator[](size_t pos) const = delete;
Container::const_reference operator[](const Index &pos) const { return this->Container::operator[](to_underlying(pos)); }
};