deque 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // Profiling deque implementation -*- C++ -*-
  2. // Copyright (C) 2009-2018 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. _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
  109. { _Base::swap(__x); }
  110. _Base&
  111. _M_base() _GLIBCXX_NOEXCEPT { return *this; }
  112. const _Base&
  113. _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
  114. };
  115. template<typename _Tp, typename _Alloc>
  116. inline bool
  117. operator==(const deque<_Tp, _Alloc>& __lhs,
  118. const deque<_Tp, _Alloc>& __rhs)
  119. { return __lhs._M_base() == __rhs._M_base(); }
  120. template<typename _Tp, typename _Alloc>
  121. inline bool
  122. operator!=(const deque<_Tp, _Alloc>& __lhs,
  123. const deque<_Tp, _Alloc>& __rhs)
  124. { return __lhs._M_base() != __rhs._M_base(); }
  125. template<typename _Tp, typename _Alloc>
  126. inline bool
  127. operator<(const deque<_Tp, _Alloc>& __lhs,
  128. const deque<_Tp, _Alloc>& __rhs)
  129. { return __lhs._M_base() < __rhs._M_base(); }
  130. template<typename _Tp, typename _Alloc>
  131. inline bool
  132. operator<=(const deque<_Tp, _Alloc>& __lhs,
  133. const deque<_Tp, _Alloc>& __rhs)
  134. { return __lhs._M_base() <= __rhs._M_base(); }
  135. template<typename _Tp, typename _Alloc>
  136. inline bool
  137. operator>=(const deque<_Tp, _Alloc>& __lhs,
  138. const deque<_Tp, _Alloc>& __rhs)
  139. { return __lhs._M_base() >= __rhs._M_base(); }
  140. template<typename _Tp, typename _Alloc>
  141. inline bool
  142. operator>(const deque<_Tp, _Alloc>& __lhs,
  143. const deque<_Tp, _Alloc>& __rhs)
  144. { return __lhs._M_base() > __rhs._M_base(); }
  145. template<typename _Tp, typename _Alloc>
  146. inline void
  147. swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
  148. _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
  149. { __lhs.swap(__rhs); }
  150. } // namespace __profile
  151. } // namespace std
  152. #endif