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