deque 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Profiling deque implementation -*- C++ -*-
  2. // Copyright (C) 2009-2015 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file profile/deque
  21. * This file is a GNU profile extension to the Standard C++ Library.
  22. */
  23. #ifndef _GLIBCXX_PROFILE_DEQUE
  24. #define _GLIBCXX_PROFILE_DEQUE 1
  25. #include <deque>
  26. namespace std _GLIBCXX_VISIBILITY(default)
  27. {
  28. namespace __profile
  29. {
  30. /// Class std::deque wrapper with performance instrumentation.
  31. template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
  32. class deque
  33. : public _GLIBCXX_STD_C::deque<_Tp, _Allocator>
  34. {
  35. typedef _GLIBCXX_STD_C::deque<_Tp, _Allocator> _Base;
  36. public:
  37. typedef typename _Base::size_type size_type;
  38. typedef typename _Base::value_type value_type;
  39. // 23.2.1.1 construct/copy/destroy:
  40. #if __cplusplus < 201103L
  41. deque()
  42. : _Base() { }
  43. deque(const deque& __x)
  44. : _Base(__x) { }
  45. ~deque() { }
  46. #else
  47. deque() = default;
  48. deque(const deque&) = default;
  49. deque(deque&&) = default;
  50. deque(const deque& __d, const _Allocator& __a)
  51. : _Base(__d, __a) { }
  52. deque(deque&& __d, const _Allocator& __a)
  53. : _Base(std::move(__d), __a) { }
  54. ~deque() = default;
  55. deque(initializer_list<value_type> __l,
  56. const _Allocator& __a = _Allocator())
  57. : _Base(__l, __a) { }
  58. #endif
  59. explicit
  60. deque(const _Allocator& __a)
  61. : _Base(__a) { }
  62. #if __cplusplus >= 201103L
  63. explicit
  64. deque(size_type __n, const _Allocator& __a = _Allocator())
  65. : _Base(__n, __a) { }
  66. deque(size_type __n, const _Tp& __value,
  67. const _Allocator& __a = _Allocator())
  68. : _Base(__n, __value, __a) { }
  69. #else
  70. explicit
  71. deque(size_type __n, const _Tp& __value = _Tp(),
  72. const _Allocator& __a = _Allocator())
  73. : _Base(__n, __value, __a) { }
  74. #endif
  75. #if __cplusplus >= 201103L
  76. template<typename _InputIterator,
  77. typename = std::_RequireInputIter<_InputIterator>>
  78. #else
  79. template<typename _InputIterator>
  80. #endif
  81. deque(_InputIterator __first, _InputIterator __last,
  82. const _Allocator& __a = _Allocator())
  83. : _Base(__first, __last, __a)
  84. { }
  85. deque(const _Base& __x)
  86. : _Base(__x) { }
  87. #if __cplusplus < 201103L
  88. deque&
  89. operator=(const deque& __x)
  90. {
  91. _M_base() = __x;
  92. return *this;
  93. }
  94. #else
  95. deque&
  96. operator=(const deque&) = default;
  97. deque&
  98. operator=(deque&&) = default;
  99. deque&
  100. operator=(initializer_list<value_type> __l)
  101. {
  102. _M_base() = __l;
  103. return *this;
  104. }
  105. #endif
  106. void
  107. swap(deque& __x)
  108. #if __cplusplus >= 201103L
  109. noexcept( noexcept(declval<_Base>().swap(__x)) )
  110. #endif
  111. { _Base::swap(__x); }
  112. _Base&
  113. _M_base() _GLIBCXX_NOEXCEPT { return *this; }
  114. const _Base&
  115. _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
  116. };
  117. template<typename _Tp, typename _Alloc>
  118. inline bool
  119. operator==(const deque<_Tp, _Alloc>& __lhs,
  120. const deque<_Tp, _Alloc>& __rhs)
  121. { return __lhs._M_base() == __rhs._M_base(); }
  122. template<typename _Tp, typename _Alloc>
  123. inline bool
  124. operator!=(const deque<_Tp, _Alloc>& __lhs,
  125. const deque<_Tp, _Alloc>& __rhs)
  126. { return __lhs._M_base() != __rhs._M_base(); }
  127. template<typename _Tp, typename _Alloc>
  128. inline bool
  129. operator<(const deque<_Tp, _Alloc>& __lhs,
  130. const deque<_Tp, _Alloc>& __rhs)
  131. { return __lhs._M_base() < __rhs._M_base(); }
  132. template<typename _Tp, typename _Alloc>
  133. inline bool
  134. operator<=(const deque<_Tp, _Alloc>& __lhs,
  135. const deque<_Tp, _Alloc>& __rhs)
  136. { return __lhs._M_base() <= __rhs._M_base(); }
  137. template<typename _Tp, typename _Alloc>
  138. inline bool
  139. operator>=(const deque<_Tp, _Alloc>& __lhs,
  140. const deque<_Tp, _Alloc>& __rhs)
  141. { return __lhs._M_base() >= __rhs._M_base(); }
  142. template<typename _Tp, typename _Alloc>
  143. inline bool
  144. operator>(const deque<_Tp, _Alloc>& __lhs,
  145. const deque<_Tp, _Alloc>& __rhs)
  146. { return __lhs._M_base() > __rhs._M_base(); }
  147. template<typename _Tp, typename _Alloc>
  148. inline void
  149. swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
  150. { __lhs.swap(__rhs); }
  151. } // namespace __profile
  152. } // namespace std
  153. #endif