aboutsummaryrefslogtreecommitdiff
path: root/backend/ListIterator.h
blob: cf14724799d4b2f0c374e69fd0cee69fdbc583e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include "backend/List.h"

#include <iterator>

#include <stddef.h>

template <typename T>
class List;

template <typename T>
class ListIterator {
public:
	// required for <algorithm> compatibility
	using iterator_category = std::forward_iterator_tag;
	using value_type = T;
	using difference_type = std::ptrdiff_t;
	using pointer = T*;
	using reference = T&;

public:
	ListIterator(ListLink<T> * & here);

public:
	T & operator * () const;
	bool operator != (const ListIterator<T> &) const;
	ListIterator<T> & operator ++ ();
	bool operator ! () const;

private:
	ListLink<T> * here = nullptr;
	ListLink<T> * next = nullptr;
};

template <typename T>
class ListRange {
public:
	ListRange(List<T> & list);

public:
	ListIterator<T> begin();
	ListIterator<T> end();
	size_t size() const;

private:
	List<T> & list;
};

#include "ListIterator.hpp"