IteratorUtil: Forward (non-reference) return types correctly

With auto&, an operator[] that returns a value (and not a reference)
would result in the proxy returning a reference to a local temporary,
which is UB
This commit is contained in:
Léo Lam 2022-07-01 16:57:40 +02:00
parent bd8b3dc61d
commit 0912686d9b
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
1 changed files with 2 additions and 2 deletions

View File

@ -66,8 +66,8 @@ public:
: mIndex(index), mContainer(container) {}
int getIndex() const { return mIndex; }
constexpr auto& get() const { return mContainer[mIndex]; }
constexpr auto& operator*() const { return get(); }
constexpr decltype(auto) get() const { return mContainer[mIndex]; }
constexpr decltype(auto) operator*() const { return get(); }
constexpr auto* operator->() const { return &get(); }
private: