util/DereferenceIterator: allow comparing with sentinel end iterators

This commit is contained in:
Max Kellermann 2024-07-10 21:29:34 +02:00
parent 3701378449
commit c77f5095d6

View File

@ -13,6 +13,11 @@
template<typename IT, template<typename IT,
typename VT=std::remove_reference_t<decltype(*std::declval<typename std::iterator_traits<IT>::value_type>())>> typename VT=std::remove_reference_t<decltype(*std::declval<typename std::iterator_traits<IT>::value_type>())>>
class DereferenceIterator { class DereferenceIterator {
/* this friend declaration allows the template operator==() to
compare arbitrary specializations */
template<typename, typename>
friend class DereferenceIterator;
using Traits = std::iterator_traits<IT>; using Traits = std::iterator_traits<IT>;
IT original; IT original;
@ -77,7 +82,10 @@ public:
return DereferenceIterator{original - n}; return DereferenceIterator{original - n};
} }
constexpr bool operator==(const DereferenceIterator<IT,VT> &other) const noexcept { /* this is a template to allow comparisons with sentinel end
iterators */
template<typename IT2>
constexpr bool operator==(const DereferenceIterator<IT2, VT> &other) const noexcept {
return original == other.original; return original == other.original;
} }
}; };