mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-15 15:19:52 +00:00
Prevents typed-indexers being used via implicit conversion.
This commit is contained in:
@@ -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()); }
|
||||
};
|
||||
|
||||
|
||||
@@ -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)); }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user