| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- //
- // capture_iterator.h
- // iterator
- //
- // Created by Sam Jaffe on 4/1/23.
- // Copyright © 2023 Sam Jaffe. All rights reserved.
- //
- #pragma once
- #include <iterator/forwards.h>
- #include <iterator/proxy.h>
- #include <iterator/detail/macro.h>
- namespace iterator {
- template <typename It>
- class capture_iterator : public proxy<It, capture_iterator<It>> {
- public:
- using super_t = proxy<It, capture_iterator<It>>;
- using value_type = typename std::iterator_traits<It>::value_type;
- using difference_type = typename std::iterator_traits<It>::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>) {
- super_t::increment();
- cache_ = super_t::dereference();
- }
- void decrement() requires(bidirectional<super_t>) {
- super_t::decrement();
- cache_ = super_t::dereference();
- }
- void advance(difference_type off) requires(random_access<super_t>) {
- super_t::advance(off);
- cache_ = super_t::dereference();
- }
- };
- template <typename It> capture_iterator(It) -> capture_iterator<It>;
- }
- #include <iterator/detail/undef.h>
|