• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 template < class _Tp, class _Sequence = std::deque< _Tp > > class queue;
16 
17 template < class _Tp, class _Seq >
18 inline bool operator==(const queue< _Tp, _Seq >&, const queue< _Tp, _Seq >&);
19 
20 template < class _Tp, class _Seq >
21 inline bool operator<(const queue< _Tp, _Seq >&, const queue< _Tp, _Seq >&);
22 
23 template < class _Tp, class _Sequence > class queue
24 {
25 
26 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
27     template < class _Tp1, class _Seq1 >
28     friend bool operator==(
29         const queue< _Tp1, _Seq1 >&, const queue< _Tp1, _Seq1 >&);
30     template < class _Tp1, class _Seq1 >
31     friend bool operator<(
32         const queue< _Tp1, _Seq1 >&, const queue< _Tp1, _Seq1 >&);
33 #endif
34 public:
35     typedef typename _Sequence::value_type value_type;
36     typedef typename _Sequence::size_type size_type;
37     typedef _Sequence container_type;
38 
39     typedef typename _Sequence::reference reference;
40     typedef typename _Sequence::const_reference const_reference;
41 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
42 protected:
43 #endif
44     _Sequence c;
45 
46 public:
queue()47     queue() : c() {}
queue(const _Sequence & __c)48     explicit queue(const _Sequence& __c) : c(__c) {}
49 
empty() const50     bool empty() const { return c.empty(); }
size() const51     size_type size() const { return c.size(); }
front()52     reference front() { return c.front(); }
front() const53     const_reference front() const { return c.front(); }
top()54     reference top() { return c.front(); }
top() const55     const_reference top() const { return c.front(); }
back()56     reference back() { return c.back(); }
back() const57     const_reference back() const { return c.back(); }
push(const value_type & __x)58     void push(const value_type& __x) { c.push_back(__x); }
pop()59     void pop() { c.pop_front(); }
60 
swap(queue & other)61     void swap(queue& other)
62     {
63         using std::swap;
64         swap(c, other.c);
65     }
66 };
67 
68 template < class _Tp, class _Sequence >
operator ==(const queue<_Tp,_Sequence> & __x,const queue<_Tp,_Sequence> & __y)69 bool operator==(
70     const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y)
71 {
72     return __x.c == __y.c;
73 }
74 
75 template < class _Tp, class _Sequence >
operator <(const queue<_Tp,_Sequence> & __x,const queue<_Tp,_Sequence> & __y)76 bool operator<(
77     const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y)
78 {
79     return __x.c < __y.c;
80 }
81 
82 template < class _Tp, class _Sequence >
operator !=(const queue<_Tp,_Sequence> & __x,const queue<_Tp,_Sequence> & __y)83 bool operator!=(
84     const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y)
85 {
86     return !(__x == __y);
87 }
88 
89 template < class _Tp, class _Sequence >
operator >(const queue<_Tp,_Sequence> & __x,const queue<_Tp,_Sequence> & __y)90 bool operator>(
91     const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y)
92 {
93     return __y < __x;
94 }
95 
96 template < class _Tp, class _Sequence >
operator <=(const queue<_Tp,_Sequence> & __x,const queue<_Tp,_Sequence> & __y)97 bool operator<=(
98     const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y)
99 {
100     return !(__y < __x);
101 }
102 
103 template < class _Tp, class _Sequence >
operator >=(const queue<_Tp,_Sequence> & __x,const queue<_Tp,_Sequence> & __y)104 bool operator>=(
105     const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y)
106 {
107     return !(__x < __y);
108 }
109 
110 template < class _Tp, class _Sequence >
swap(queue<_Tp,_Sequence> & __x,queue<_Tp,_Sequence> & __y)111 inline void swap(queue< _Tp, _Sequence >& __x, queue< _Tp, _Sequence >& __y)
112 {
113     __x.swap(__y);
114 }
115 
116 } /* namespace boost */
117 
118 #endif /* BOOST_QUEUE_HPP */
119