diff --git a/common/main/d_range.h b/common/main/d_range.h index e83a0e137..fe2d49608 100644 --- a/common/main/d_range.h +++ b/common/main/d_range.h @@ -130,6 +130,14 @@ public: m_idx(i) { } + /* This is a temporary constructor to facilitate conversion to sentinel + * usage in calling algorithms. + */ + template + constexpr xrange_iterator(xrange_endpoint i) : + m_idx(i) + { + } index_type operator*() const { return m_idx; @@ -152,6 +160,12 @@ public: } [[nodiscard]] constexpr bool operator==(const xrange_iterator &i) const = default; + template + [[nodiscard]] + constexpr bool operator==(const xrange_endpoint &i) const + { + return m_idx == i.value; + } }; /* This provides an approximation of the functionality of the Python2 @@ -237,9 +251,9 @@ public: { return iterator(static_cast(*this)); } - iterator end() const + end_type end() const { - return iterator(static_cast(*this)); + return *this; } }; diff --git a/common/unittest/xrange.cpp b/common/unittest/xrange.cpp index 9e5aa93cd..cf8e42698 100644 --- a/common/unittest/xrange.cpp +++ b/common/unittest/xrange.cpp @@ -131,5 +131,6 @@ BOOST_AUTO_TEST_CASE(xrange_iter_values) { auto &&r = xrange(2u); BOOST_TEST(*r.begin() == 0); - BOOST_TEST(*r.end() == 2); + BOOST_TEST(*std::next(r.begin()) == 1); + BOOST_TEST(*std::next(r.begin(), 2) == 2); }