aboutsummaryrefslogtreecommitdiff
path: root/backend/List.h
blob: d9911527db710e07e576d114018fa852cb7dba5c (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
51
52
53
#pragma once

#include <stdlib.h>

template <typename T>
class ListRange;

template <typename T>
class ListIterator;

template <typename T>
struct ListLink {
	friend class ListIterator<T>;
	ListLink<T> * prev;
	ListLink<T> * next;
	T value;
};

template<typename T>
class List {
public:
	List() = default;
	virtual ~List();
	List(const List &) = delete;
	List(List &&) = delete;
	List & operator = (const List &) = delete;
	List & operator = (List &&) = delete;

public:
	size_t size() const;

	void push_back(const T & el);
	void remove(const T & val);

	void pop_back();

	void clear();

	T & operator [] (size_t index) const;

	ListIterator<T> begin();
	ListIterator<T> end();
	ListRange<T> range();

private:
	friend class ListRange<T>;
	ListLink<T> * head = nullptr;
	ListLink<T> * tail = nullptr;
	size_t length = 0;
};

#include "List.hpp"