// // capture_iterator.h // iterator // // Created by Sam Jaffe on 4/1/23. // Copyright © 2023 Sam Jaffe. All rights reserved. // #pragma once #include #include #include namespace iterator { template class capture_iterator : public proxy> { public: using super_t = proxy>; using value_type = typename std::iterator_traits::value_type; using difference_type = typename std::iterator_traits::difference_type; private: value_type cache_; public: capture_iterator() = default; capture_iterator(It it) : super_t(it) { cache_ = super_t::dereference(); } value_type const & dereference() const { return cache_; } void increment() requires(forward) { super_t::increment(); cache_ = super_t::dereference(); } void decrement() requires(bidirectional) { super_t::decrement(); cache_ = super_t::dereference(); } void advance(difference_type off) requires(random_access) { super_t::advance(off); cache_ = super_t::dereference(); } }; template capture_iterator(It) -> capture_iterator; } #include