-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixedqueue.h
77 lines (59 loc) · 1.27 KB
/
fixedqueue.h
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
#ifndef FIXEDQUEUE_H
#define FIXEDQUEUE_H
#include <deque>
template <typename T>
class FixedQueue
{
public:
typedef typename std::deque<T>::iterator iterator;
typedef typename std::deque<T>::const_iterator const_iterator;
//set max size
FixedQueue(size_t size)
{
que.resize(size);
}
//push back
void push_back(const T&& t)
{
que.pop_front();
que.push_back(t);
}
void push_back(const T& t)
{
que.pop_front();
que.push_back(t);
}
//push front
void push_front(const T&& t)
{
que.pop_back();
que.push_front(t);
}
void push_front(const T& t)
{
que.pop_back();
que.push_front(t);
}
//access front
T & get_front(void)
{
return que.front();
}
//access back
T & get_back(void)
{
return que.back();
}
//Get size
int get_size(void)
{
return que.size();
}
iterator begin() { return que.begin(); }
const_iterator begin() const { return que.begin(); }
iterator end() { return que.end(); }
const_iterator end() const { return que.end(); }
private:
std::deque < T > que; //!< データが格納されているコンテナ
};
#endif // FIXEDQUEUE_H