stl_iterator.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Debugging support implementation -*- C++ -*-
  2. // Copyright (C) 2015-2020 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 _Sequence>
  45. inline std::reverse_iterator<_Iterator>
  46. __base(const std::reverse_iterator<_Safe_iterator<
  47. _Iterator, _Sequence, std::random_access_iterator_tag> >& __it)
  48. { return std::reverse_iterator<_Iterator>(__it.base().base()); }
  49. #if __cplusplus < 201103L
  50. template<typename _Iterator>
  51. struct _Unsafe_type<std::reverse_iterator<_Iterator> >
  52. {
  53. typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
  54. typedef std::reverse_iterator<_UnsafeType> _Type;
  55. };
  56. template<typename _Iterator>
  57. inline std::reverse_iterator<typename _Unsafe_type<_Iterator>::_Type>
  58. __unsafe(const std::reverse_iterator<_Iterator>& __it)
  59. {
  60. typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
  61. return std::reverse_iterator<_UnsafeType>(__unsafe(__it.base()));
  62. }
  63. #else
  64. template<typename _Iterator>
  65. inline auto
  66. __unsafe(const std::reverse_iterator<_Iterator>& __it)
  67. -> decltype(std::__make_reverse_iterator(__unsafe(__it.base())))
  68. { return std::__make_reverse_iterator(__unsafe(__it.base())); }
  69. #endif
  70. #if __cplusplus >= 201103L
  71. // Help Debug mode to see through move_iterator.
  72. template<typename _Iterator>
  73. inline bool
  74. __valid_range(const std::move_iterator<_Iterator>& __first,
  75. const std::move_iterator<_Iterator>& __last,
  76. typename _Distance_traits<_Iterator>::__type& __dist)
  77. { return __valid_range(__first.base(), __last.base(), __dist); }
  78. template<typename _Iterator>
  79. inline typename _Distance_traits<_Iterator>::__type
  80. __get_distance(const std::move_iterator<_Iterator>& __first,
  81. const std::move_iterator<_Iterator>& __last)
  82. { return __get_distance(__first.base(), __last.base()); }
  83. template<typename _Iterator, typename _Size>
  84. inline bool
  85. __can_advance(const std::move_iterator<_Iterator>& __it, _Size __n)
  86. { return __can_advance(__it.base(), __n); }
  87. template<typename _Iterator>
  88. inline auto
  89. __unsafe(const std::move_iterator<_Iterator>& __it)
  90. -> decltype(std::make_move_iterator(__unsafe(__it.base())))
  91. { return std::make_move_iterator(__unsafe(__it.base())); }
  92. template<typename _Iterator>
  93. inline auto
  94. __base(const std::move_iterator<_Iterator>& __it)
  95. -> decltype(std::make_move_iterator(__base(__it.base())))
  96. { return std::make_move_iterator(__base(__it.base())); }
  97. #endif
  98. }
  99. #endif