| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // 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_; }
- SFINAE(super_t::category_enum >= category::forward) void increment() {
- super_t::increment();
- cache_ = super_t::dereference();
- }
- SFINAE(super_t::category_enum >= category::bidirectional)
- void decrement() {
- super_t::decrement();
- cache_ = super_t::dereference();
- }
- SFINAE(super_t::category_enum >= category::random_access)
- void advance(difference_type off) {
- super_t::advance(off);
- cache_ = super_t::dereference();
- }
- };
- template <typename It> capture_iterator(It) -> capture_iterator<It>;
- }
- #include <iterator/detail/undef.h>
|