source: NonGTP/Boost/boost/pending/queue.hpp @ 857

Revision 857, 3.1 KB checked in by igarcia, 19 years ago (diff)
Line 
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
12namespace boost {
13
14template <class _Tp,
15          class _Sequence = std::deque<_Tp> >
16class queue;
17
18template <class _Tp, class _Seq>
19inline bool operator==(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
20
21template <class _Tp, class _Seq>
22inline bool operator<(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
23
24
25template <class _Tp, class _Sequence>
26class 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
36public:
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
44protected:
45#endif
46  _Sequence c;
47public:
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
69template <class _Tp, class _Sequence>
70bool
71operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
72{
73  return __x.c == __y.c;
74}
75
76template <class _Tp, class _Sequence>
77bool
78operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
79{
80  return __x.c < __y.c;
81}
82
83template <class _Tp, class _Sequence>
84bool
85operator!=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
86{
87  return !(__x == __y);
88}
89
90template <class _Tp, class _Sequence>
91bool
92operator>(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
93{
94  return __y < __x;
95}
96
97template <class _Tp, class _Sequence>
98bool
99operator<=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
100{
101  return !(__y < __x);
102}
103
104template <class _Tp, class _Sequence>
105bool
106operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
107{
108  return !(__x < __y);
109}
110
111template <class _Tp, class _Sequence>
112inline void
113swap(queue<_Tp, _Sequence>& __x, queue<_Tp, _Sequence>& __y)
114{ __x.swap(__y); }
115
116} /* namespace boost */
117
118#endif /* BOOST_QUEUE_HPP */
Note: See TracBrowser for help on using the repository browser.