stl_iterator.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Debugging support implementation -*- C++ -*-
  2. // Copyright (C) 2015-2023 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 debug/stl_iterator.h
  21. * This file is a GNU debug extension to the Standard C++ Library.
  22. */
  23. #ifndef _GLIBCXX_DEBUG_STL_ITERATOR_H
  24. #define _GLIBCXX_DEBUG_STL_ITERATOR_H 1
  25. #include <debug/helper_functions.h>
  26. namespace __gnu_debug
  27. {
  28. // Help Debug mode to see through reverse_iterator.
  29. template<typename _Iterator>
  30. _GLIBCXX20_CONSTEXPR
  31. inline bool
  32. __valid_range(const std::reverse_iterator<_Iterator>& __first,
  33. const std::reverse_iterator<_Iterator>& __last,
  34. typename _Distance_traits<_Iterator>::__type& __dist)
  35. {
  36. return __gnu_debug::__valid_range(__last.base(), __first.base(), __dist);
  37. }
  38. template<typename _Iterator>
  39. _GLIBCXX20_CONSTEXPR
  40. inline typename _Distance_traits<_Iterator>::__type
  41. __get_distance(const std::reverse_iterator<_Iterator>& __first,
  42. const std::reverse_iterator<_Iterator>& __last)
  43. { return __gnu_debug::__get_distance(__last.base(), __first.base()); }
  44. template<typename _Iterator, typename _Size>
  45. _GLIBCXX20_CONSTEXPR
  46. inline bool
  47. __can_advance(const std::reverse_iterator<_Iterator>& __it, _Size __n)
  48. { return __gnu_debug::__can_advance(__it.base(), -__n); }
  49. template<typename _Iterator, typename _Diff>
  50. _GLIBCXX20_CONSTEXPR
  51. inline bool
  52. __can_advance(const std::reverse_iterator<_Iterator>& __it,
  53. const std::pair<_Diff, _Distance_precision>& __dist,
  54. int __way)
  55. { return __gnu_debug::__can_advance(__it.base(), __dist, -__way); }
  56. template<typename _Iterator, typename _Sequence>
  57. _GLIBCXX20_CONSTEXPR
  58. inline std::reverse_iterator<_Iterator>
  59. __base(const std::reverse_iterator<_Safe_iterator<
  60. _Iterator, _Sequence, std::random_access_iterator_tag> >& __it)
  61. { return std::reverse_iterator<_Iterator>(__it.base().base()); }
  62. #if __cplusplus < 201103L
  63. template<typename _Iterator>
  64. struct _Unsafe_type<std::reverse_iterator<_Iterator> >
  65. {
  66. typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
  67. typedef std::reverse_iterator<_UnsafeType> _Type;
  68. };
  69. template<typename _Iterator>
  70. inline std::reverse_iterator<typename _Unsafe_type<_Iterator>::_Type>
  71. __unsafe(const std::reverse_iterator<_Iterator>& __it)
  72. {
  73. typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
  74. return std::reverse_iterator<_UnsafeType>(__unsafe(__it.base()));
  75. }
  76. #else
  77. template<typename _Iterator>
  78. _GLIBCXX20_CONSTEXPR
  79. inline auto
  80. __unsafe(const std::reverse_iterator<_Iterator>& __it)
  81. -> decltype(std::__make_reverse_iterator(__unsafe(__it.base())))
  82. { return std::__make_reverse_iterator(__unsafe(__it.base())); }
  83. #endif
  84. #if __cplusplus >= 201103L
  85. // Help Debug mode to see through move_iterator.
  86. template<typename _Iterator>
  87. _GLIBCXX20_CONSTEXPR
  88. inline bool
  89. __valid_range(const std::move_iterator<_Iterator>& __first,
  90. const std::move_iterator<_Iterator>& __last,
  91. typename _Distance_traits<_Iterator>::__type& __dist)
  92. {
  93. return __gnu_debug::__valid_range(__first.base(), __last.base(), __dist);
  94. }
  95. template<typename _Iterator>
  96. _GLIBCXX20_CONSTEXPR
  97. inline typename _Distance_traits<_Iterator>::__type
  98. __get_distance(const std::move_iterator<_Iterator>& __first,
  99. const std::move_iterator<_Iterator>& __last)
  100. { return __gnu_debug::__get_distance(__first.base(), __last.base()); }
  101. template<typename _Iterator, typename _Size>
  102. _GLIBCXX20_CONSTEXPR
  103. inline bool
  104. __can_advance(const std::move_iterator<_Iterator>& __it, _Size __n)
  105. { return __gnu_debug::__can_advance(__it.base(), __n); }
  106. template<typename _Iterator, typename _Diff>
  107. _GLIBCXX20_CONSTEXPR
  108. inline bool
  109. __can_advance(const std::move_iterator<_Iterator>& __it,
  110. const std::pair<_Diff, _Distance_precision>& __dist,
  111. int __way)
  112. { return __gnu_debug::__can_advance(__it.base(), __dist, __way); }
  113. template<typename _Iterator>
  114. _GLIBCXX20_CONSTEXPR
  115. inline auto
  116. __unsafe(const std::move_iterator<_Iterator>& __it)
  117. -> decltype(std::make_move_iterator(__unsafe(__it.base())))
  118. { return std::make_move_iterator(__unsafe(__it.base())); }
  119. template<typename _Iterator>
  120. _GLIBCXX20_CONSTEXPR
  121. inline auto
  122. __base(const std::move_iterator<_Iterator>& __it)
  123. -> decltype(std::make_move_iterator(__base(__it.base())))
  124. { return std::make_move_iterator(__base(__it.base())); }
  125. #endif
  126. }
  127. #endif