queue.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #ifndef BOOST_QUEUE_HPP
  6. #define BOOST_QUEUE_HPP
  7. #include <deque>
  8. #include <algorithm>
  9. namespace boost {
  10. template <class _Tp,
  11. class _Sequence = std::deque<_Tp> >
  12. class queue;
  13. template <class _Tp, class _Seq>
  14. inline bool operator==(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
  15. template <class _Tp, class _Seq>
  16. inline bool operator<(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
  17. template <class _Tp, class _Sequence>
  18. class queue {
  19. #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  20. template <class _Tp1, class _Seq1>
  21. friend bool operator== (const queue<_Tp1, _Seq1>&,
  22. const queue<_Tp1, _Seq1>&);
  23. template <class _Tp1, class _Seq1>
  24. friend bool operator< (const queue<_Tp1, _Seq1>&,
  25. const queue<_Tp1, _Seq1>&);
  26. #endif
  27. public:
  28. typedef typename _Sequence::value_type value_type;
  29. typedef typename _Sequence::size_type size_type;
  30. typedef _Sequence container_type;
  31. typedef typename _Sequence::reference reference;
  32. typedef typename _Sequence::const_reference const_reference;
  33. #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  34. protected:
  35. #endif
  36. _Sequence c;
  37. public:
  38. queue() : c() {}
  39. explicit queue(const _Sequence& __c) : c(__c) {}
  40. bool empty() const { return c.empty(); }
  41. size_type size() const { return c.size(); }
  42. reference front() { return c.front(); }
  43. const_reference front() const { return c.front(); }
  44. reference top() { return c.front(); }
  45. const_reference top() const { return c.front(); }
  46. reference back() { return c.back(); }
  47. const_reference back() const { return c.back(); }
  48. void push(const value_type& __x) { c.push_back(__x); }
  49. void pop() { c.pop_front(); }
  50. void swap(queue& other)
  51. {
  52. using std::swap;
  53. swap(c, other.c);
  54. }
  55. };
  56. template <class _Tp, class _Sequence>
  57. bool
  58. operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
  59. {
  60. return __x.c == __y.c;
  61. }
  62. template <class _Tp, class _Sequence>
  63. bool
  64. operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
  65. {
  66. return __x.c < __y.c;
  67. }
  68. template <class _Tp, class _Sequence>
  69. bool
  70. operator!=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
  71. {
  72. return !(__x == __y);
  73. }
  74. template <class _Tp, class _Sequence>
  75. bool
  76. operator>(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
  77. {
  78. return __y < __x;
  79. }
  80. template <class _Tp, class _Sequence>
  81. bool
  82. operator<=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
  83. {
  84. return !(__y < __x);
  85. }
  86. template <class _Tp, class _Sequence>
  87. bool
  88. operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
  89. {
  90. return !(__x < __y);
  91. }
  92. template <class _Tp, class _Sequence>
  93. inline void
  94. swap(queue<_Tp, _Sequence>& __x, queue<_Tp, _Sequence>& __y)
  95. { __x.swap(__y); }
  96. } /* namespace boost */
  97. #endif /* BOOST_QUEUE_HPP */