-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.hpp
156 lines (121 loc) · 4.69 KB
/
queue.hpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* queue.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ncarob <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/27 17:48:57 by ncarob #+# #+# */
/* Updated: 2023/02/27 18:14:17 by ncarob ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef QUEUE_H
# define QUEUE_H
# include "deque.hpp"
namespace ft
{
template <typename T, typename Container = ft::deque<T> >
class queue {
public:
typedef T value_type;
typedef T& reference;
typedef const T& const_reference;
typedef Container container_type;
typedef size_t size_type;
explicit queue (const container_type& c = container_type());
queue(const queue& other);
~queue();
queue& operator = (const queue& other);
bool empty() const;
size_type size() const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
void push(const value_type& val);
void pop(void);
template <typename Y, typename YContainer>
friend bool operator == (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs);
template <typename Y, typename YContainer>
friend bool operator != (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs);
template <typename Y, typename YContainer>
friend bool operator < (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs);
template <typename Y, typename YContainer>
friend bool operator <= (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs);
template <typename Y, typename YContainer>
friend bool operator > (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs);
template <typename Y, typename YContainer>
friend bool operator >= (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs);
private:
container_type _c;
};
template <class T, class Container>
queue<T, Container>::queue (const container_type& c) : _c(c) { }
template <class T, class Container>
queue<T, Container>::queue(const queue& other) : _c(other._c) { }
template <class T, class Container>
queue<T, Container>::~queue() { }
template <class T, class Container>
queue<T, Container>& queue<T, Container>::operator = (const queue& other) {
if (*this != other)
_c = other._c;
return *this;
}
template <class T, class Container>
bool queue<T, Container>::empty() const {
return _c.empty();
}
template <class T, class Container>
typename queue<T, Container>::size_type queue<T, Container>::size() const {
return _c.size();
}
template <class T, class Container>
typename queue<T, Container>::reference queue<T, Container>::front() {
return _c.front();
}
template <class T, class Container>
typename queue<T, Container>::const_reference queue<T, Container>::front() const {
return _c.front();
}
template <class T, class Container>
typename queue<T, Container>::reference queue<T, Container>::back() {
return _c.back();
}
template <class T, class Container>
typename queue<T, Container>::const_reference queue<T, Container>::back() const {
return _c.back();
}
template <class T, class Container>
void queue<T, Container>::push(const value_type& val) {
return _c.push_back(val);
}
template <class T, class Container>
void queue<T, Container>::pop(void) {
return _c.pop_front();
}
template <class Y, class YContainer>
bool operator == (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs) {
return lhs._c == rhs._c;
}
template <class Y, class YContainer>
bool operator != (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs) {
return lhs._c != rhs._c;
}
template <class Y, class YContainer>
bool operator < (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs) {
return lhs._c < rhs._c;
}
template <class Y, class YContainer>
bool operator <= (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs) {
return lhs._c <= rhs._c;
}
template <class Y, class YContainer>
bool operator > (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs) {
return lhs._c > rhs._c;
}
template <class Y, class YContainer>
bool operator >= (const queue<Y, YContainer>& lhs, const queue<Y, YContainer>& rhs) {
return lhs._c >= rhs._c;
}
} /* FT NAMESPACE */
#endif