TRIQS/itertools 1.3.0
C++ range library
Loading...
Searching...
No Matches
iterator_facade.hpp
Go to the documentation of this file.
1// Copyright (c) 2024 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Thomas Hahn, Olivier Parcollet, Nils Wentzell, chuffa
16
22#ifndef _ITERTOOLS_ITERATOR_FACADE_HPP
23#define _ITERTOOLS_ITERATOR_FACADE_HPP
24
25#include <cstddef>
26#include <iterator>
27
28namespace itertools {
29
31 // Forward declaration.
32 template <typename Iter, typename Value, typename Tag = std::forward_iterator_tag, typename Reference = Value &,
33 typename Difference = std::ptrdiff_t>
34 struct iterator_facade;
36
60 template <typename Iter, typename Value, typename Reference, typename Difference>
61 struct iterator_facade<Iter, Value, std::forward_iterator_tag, Reference, Difference> {
62 private:
63 // Get a reference to the derived iterator.
64 [[nodiscard]] Iter &self() { return static_cast<Iter &>(*this); }
65
66 // Get a const reference to the derived iterator.
67 [[nodiscard]] Iter const &self() const { return static_cast<const Iter &>(*this); }
68
69 public:
71 using value_type = Value;
72
74 using reference = Reference;
75
77 using pointer = Value *;
78
80 using difference_type = Difference;
81
83 using iterator_category = std::forward_iterator_tag;
84
89 Iter &operator++() {
90 self().increment();
91 return self();
92 }
93
98 Iter operator++(int) {
99 Iter c = self();
100 self().increment();
101 return c;
102 }
103
108 [[nodiscard]] decltype(auto) operator*() const { return self().dereference(); }
109
114 [[nodiscard]] decltype(auto) operator->() const { return operator*(); }
115 };
116
117} // namespace itertools
118
119#endif // _ITERTOOLS_ITERATOR_FACADE_HPP
std::forward_iterator_tag iterator_category
Iterator category of the derived iterator.