gz-cpp-util
1.3
A c++20 library containing various utilities
iterator.hpp
1
#pragma once
2
3
namespace
gz {
4
8
template
<
typename
T>
9
struct
Iterator
{
10
public
:
11
using
value_type = T;
12
Iterator
() : ptr(
nullptr
) {};
13
Iterator
(T* ptr) : ptr(ptr) {};
14
T& operator*()
const
{
return
*ptr; };
15
Iterator
& operator=(
const
Iterator
& other) {
16
ptr = other.ptr;
17
return
*
this
;
18
};
19
Iterator
& operator++() { ptr++;
return
*
this
; };
20
Iterator
operator++(
int
) {
auto
copy = *
this
; ptr++;
return
copy; };
21
friend
int
operator-(
Iterator
lhs,
Iterator
rhs) {
22
return
lhs.ptr - rhs.ptr;
23
};
24
bool
operator==(
const
Iterator
& other)
const
{
return
ptr == other.ptr; };
25
// bool operator!=(const Iterator& other) const { return ptr != other.ptr; };
26
private
:
27
T* ptr;
28
};
// Iterator
29
30
/* static_assert(std::forward_iterator<Iterator<int>>, "Iterator not a forward range."); */
31
}
// namespace gz
gz::Iterator
A generic iterator that satisfies std::forward_iterator.
Definition:
iterator.hpp:9
container
iterator.hpp
Generated by
1.9.3