// // end_aware_iterator.h // iterator // // Created by Sam Jaffe on 2/7/17. // #pragma once #include #include #include #include #include namespace iterator { /** * @class end_aware_iterator * @brief An iterator that keeps track of the relative end of the range. * * @tparam It The underlying iterator type */ template class end_aware_iterator : public proxy> { public: using super_t = proxy>; using sentinel_type = sentinel_t; public: end_aware_iterator() = default; end_aware_iterator(It it, It end) : super_t(it), end_(end) {} template )> end_aware_iterator(C && container) : super_t(std::begin(container)), end_(std::end(container)) { static_assert(std::is_reference_v, "Cannot access iterator of a temporary"); } template end_aware_iterator(end_aware_iterator const & other) : super_t(other.impl()), end_(other.end_) {} bool at_end() const { if constexpr (super_t::category_enum == category::random_access) { return super_t::impl() >= end_; } else { return super_t::impl() == end_; } } protected: It end() const { return end_; } private: template friend class end_aware_iterator; It end_; }; template end_aware_iterator(C &&) -> end_aware_iterator>; template end_aware_iterator(It, It) -> end_aware_iterator; template end_aware_iterator(end_aware_iterator, end_aware_iterator) -> end_aware_iterator; } MAKE_ITERATOR_FACADE_TYPEDEFS_T(::iterator::end_aware_iterator); #include