1 | // (C) Copyright Jeremy Siek 2004 |
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
3 | // accompanying file LICENSE_1_0.txt or copy at |
---|
4 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | |
---|
6 | #ifndef BOOST_QUEUE_HPP |
---|
7 | #define BOOST_QUEUE_HPP |
---|
8 | |
---|
9 | #include <deque> |
---|
10 | #include <algorithm> |
---|
11 | |
---|
12 | namespace boost { |
---|
13 | |
---|
14 | template <class _Tp, |
---|
15 | class _Sequence = std::deque<_Tp> > |
---|
16 | class queue; |
---|
17 | |
---|
18 | template <class _Tp, class _Seq> |
---|
19 | inline bool operator==(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&); |
---|
20 | |
---|
21 | template <class _Tp, class _Seq> |
---|
22 | inline bool operator<(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&); |
---|
23 | |
---|
24 | |
---|
25 | template <class _Tp, class _Sequence> |
---|
26 | class queue { |
---|
27 | |
---|
28 | #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS |
---|
29 | template <class _Tp1, class _Seq1> |
---|
30 | friend bool operator== (const queue<_Tp1, _Seq1>&, |
---|
31 | const queue<_Tp1, _Seq1>&); |
---|
32 | template <class _Tp1, class _Seq1> |
---|
33 | friend bool operator< (const queue<_Tp1, _Seq1>&, |
---|
34 | const queue<_Tp1, _Seq1>&); |
---|
35 | #endif |
---|
36 | public: |
---|
37 | typedef typename _Sequence::value_type value_type; |
---|
38 | typedef typename _Sequence::size_type size_type; |
---|
39 | typedef _Sequence container_type; |
---|
40 | |
---|
41 | typedef typename _Sequence::reference reference; |
---|
42 | typedef typename _Sequence::const_reference const_reference; |
---|
43 | #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS |
---|
44 | protected: |
---|
45 | #endif |
---|
46 | _Sequence c; |
---|
47 | public: |
---|
48 | queue() : c() {} |
---|
49 | explicit queue(const _Sequence& __c) : c(__c) {} |
---|
50 | |
---|
51 | bool empty() const { return c.empty(); } |
---|
52 | size_type size() const { return c.size(); } |
---|
53 | reference front() { return c.front(); } |
---|
54 | const_reference front() const { return c.front(); } |
---|
55 | reference top() { return c.front(); } |
---|
56 | const_reference top() const { return c.front(); } |
---|
57 | reference back() { return c.back(); } |
---|
58 | const_reference back() const { return c.back(); } |
---|
59 | void push(const value_type& __x) { c.push_back(__x); } |
---|
60 | void pop() { c.pop_front(); } |
---|
61 | |
---|
62 | void swap(queue& other) |
---|
63 | { |
---|
64 | using std::swap; |
---|
65 | swap(c, other.c); |
---|
66 | } |
---|
67 | }; |
---|
68 | |
---|
69 | template <class _Tp, class _Sequence> |
---|
70 | bool |
---|
71 | operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) |
---|
72 | { |
---|
73 | return __x.c == __y.c; |
---|
74 | } |
---|
75 | |
---|
76 | template <class _Tp, class _Sequence> |
---|
77 | bool |
---|
78 | operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) |
---|
79 | { |
---|
80 | return __x.c < __y.c; |
---|
81 | } |
---|
82 | |
---|
83 | template <class _Tp, class _Sequence> |
---|
84 | bool |
---|
85 | operator!=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) |
---|
86 | { |
---|
87 | return !(__x == __y); |
---|
88 | } |
---|
89 | |
---|
90 | template <class _Tp, class _Sequence> |
---|
91 | bool |
---|
92 | operator>(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) |
---|
93 | { |
---|
94 | return __y < __x; |
---|
95 | } |
---|
96 | |
---|
97 | template <class _Tp, class _Sequence> |
---|
98 | bool |
---|
99 | operator<=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) |
---|
100 | { |
---|
101 | return !(__y < __x); |
---|
102 | } |
---|
103 | |
---|
104 | template <class _Tp, class _Sequence> |
---|
105 | bool |
---|
106 | operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) |
---|
107 | { |
---|
108 | return !(__x < __y); |
---|
109 | } |
---|
110 | |
---|
111 | template <class _Tp, class _Sequence> |
---|
112 | inline void |
---|
113 | swap(queue<_Tp, _Sequence>& __x, queue<_Tp, _Sequence>& __y) |
---|
114 | { __x.swap(__y); } |
---|
115 | |
---|
116 | } /* namespace boost */ |
---|
117 | |
---|
118 | #endif /* BOOST_QUEUE_HPP */ |
---|