stl_iterator.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Debugging support implementation -*- C++ -*-
  2. // Copyright (C) 2015-2021 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. inline bool
  31. __valid_range(const std::reverse_iterator<_Iterator>& __first,
  32. const std::reverse_iterator<_Iterator>& __last,
  33. typename _Distance_traits<_Iterator>::__type& __dist)
  34. { return __valid_range(__last.base(), __first.base(), __dist); }
  35. template<typename _Iterator>
  36. inline typename _Distance_traits<_Iterator>::__type
  37. __get_distance(const std::reverse_iterator<_Iterator>& __first,
  38. const std::reverse_iterator<_Iterator>& __last)
  39. { return __get_distance(__last.base(), __first.base()); }
  40. template<typename _Iterator, typename _Size>
  41. inline bool
  42. __can_advance(const std::reverse_iterator<_Iterator>& __it, _Size __n)
  43. { return __can_advance(__it.base(), -__n); }
  44. template<typename _Iterator, typename _Diff>
  45. inline bool
  46. __can_advance(const std::reverse_iterator<_Iterator>& __it,
  47. const std::pair<_Diff, _Distance_precision>& __dist,
  48. int __way)
  49. { return __can_advance(__it.base(), __dist, -__way); }
  50. template<typename _Iterator, typename _Sequence>
  51. inline std::reverse_iterator<_Iterator>
  52. __base(const std::reverse_iterator<_Safe_iterator<
  53. _Iterator, _Sequence, std::random_access_iterator_tag> >& __it)
  54. { return std::reverse_iterator<_Iterator>(__it.base().base()); }
  55. #if __cplusplus < 201103L
  56. template<typename _Iterator>
  57. struct _Unsafe_type<std::reverse_iterator<_Iterator> >
  58. {
  59. typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
  60. typedef std::reverse_iterator<_UnsafeType> _Type;
  61. };
  62. template<typename _Iterator>
  63. inline std::reverse_iterator<typename _Unsafe_type<_Iterator>::_Type>
  64. __unsafe(const std::reverse_iterator<_Iterator>& __it)
  65. {
  66. typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
  67. return std::reverse_iterator<_UnsafeType>(__unsafe(__it.base()));
  68. }
  69. #else
  70. template<typename _Iterator>
  71. inline auto
  72. __unsafe(const std::reverse_iterator<_Iterator>& __it)
  73. -> decltype(std::__make_reverse_iterator(__unsafe(__it.base())))
  74. { return std::__make_reverse_iterator(__unsafe(__it.base())); }
  75. #endif
  76. #if __cplusplus >= 201103L
  77. // Help Debug mode to see through move_iterator.
  78. template<typename _Iterator>
  79. inline bool
  80. __valid_range(const std::move_iterator<_Iterator>& __first,
  81. const std::move_iterator<_Iterator>& __last,
  82. typename _Distance_traits<_Iterator>::__type& __dist)
  83. { return __valid_range(__first.base(), __last.base(), __dist); }
  84. template<typename _Iterator>
  85. inline typename _Distance_traits<_Iterator>::__type
  86. __get_distance(const std::move_iterator<_Iterator>& __first,
  87. const std::move_iterator<_Iterator>& __last)
  88. { return __get_distance(__first.base(), __last.base()); }
  89. template<typename _Iterator, typename _Size>
  90. inline bool
  91. __can_advance(const std::move_iterator<_Iterator>& __it, _Size __n)
  92. { return __can_advance(__it.base(), __n); }
  93. template<typename _Iterator, typename _Diff>
  94. inline bool
  95. __can_advance(const std::move_iterator<_Iterator>& __it,
  96. const std::pair<_Diff, _Distance_precision>& __dist,
  97. int __way)
  98. { return __can_advance(__it.base(), __dist, __way); }
  99. template<typename _Iterator>
  100. inline auto
  101. __unsafe(const std::move_iterator<_Iterator>& __it)
  102. -> decltype(std::make_move_iterator(__unsafe(__it.base())))
  103. { return std::make_move_iterator(__unsafe(__it.base())); }
  104. template<typename _Iterator>
  105. inline auto
  106. __base(const std::move_iterator<_Iterator>& __it)
  107. -> decltype(std::make_move_iterator(__base(__it.base())))
  108. { return std::make_move_iterator(__base(__it.base())); }
  109. #endif
  110. }
  111. #endif