From c77f5095d6794f639c4482270e26c23c5284f49c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 10 Jul 2024 21:29:34 +0200 Subject: [PATCH] util/DereferenceIterator: allow comparing with sentinel end iterators --- src/util/DereferenceIterator.hxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util/DereferenceIterator.hxx b/src/util/DereferenceIterator.hxx index 1e68160e9..709df6ac4 100644 --- a/src/util/DereferenceIterator.hxx +++ b/src/util/DereferenceIterator.hxx @@ -13,6 +13,11 @@ template::value_type>())>> class DereferenceIterator { + /* this friend declaration allows the template operator==() to + compare arbitrary specializations */ + template + friend class DereferenceIterator; + using Traits = std::iterator_traits; IT original; @@ -77,7 +82,10 @@ public: return DereferenceIterator{original - n}; } - constexpr bool operator==(const DereferenceIterator &other) const noexcept { + /* this is a template to allow comparisons with sentinel end + iterators */ + template + constexpr bool operator==(const DereferenceIterator &other) const noexcept { return original == other.original; } };