stl_iterator.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Debugging support implementation -*- C++ -*-
  2. // Copyright (C) 2015-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 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. #if __cplusplus < 201103L
  41. template<typename _Iterator>
  42. struct __is_safe_random_iterator<std::reverse_iterator<_Iterator> >
  43. : __is_safe_random_iterator<_Iterator>
  44. { };
  45. template<typename _Iterator>
  46. struct _Unsafe_type<std::reverse_iterator<_Iterator> >
  47. {
  48. typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
  49. typedef std::reverse_iterator<_UnsafeType> _Type;
  50. };
  51. template<typename _Iterator>
  52. inline std::reverse_iterator<typename _Unsafe_type<_Iterator>::_Type>
  53. __unsafe(const std::reverse_iterator<_Iterator>& __it)
  54. {
  55. typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
  56. return std::reverse_iterator<_UnsafeType>(__unsafe(__it.base()));
  57. }
  58. #else
  59. template<typename _Iterator>
  60. inline auto
  61. __base(const std::reverse_iterator<_Iterator>& __it)
  62. -> decltype(std::__make_reverse_iterator(__base(__it.base())))
  63. { return std::__make_reverse_iterator(__base(__it.base())); }
  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>
  84. inline auto
  85. __unsafe(const std::move_iterator<_Iterator>& __it)
  86. -> decltype(std::make_move_iterator(__unsafe(__it.base())))
  87. { return std::make_move_iterator(__unsafe(__it.base())); }
  88. template<typename _Iterator>
  89. inline auto
  90. __base(const std::move_iterator<_Iterator>& __it)
  91. -> decltype(std::make_move_iterator(__base(__it.base())))
  92. { return std::make_move_iterator(__base(__it.base())); }
  93. #endif
  94. }
  95. #endif