xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/debug/stl_iterator.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj // Debugging support implementation -*- C++ -*-
2*38fd1498Szrj 
3*38fd1498Szrj // Copyright (C) 2015-2018 Free Software Foundation, Inc.
4*38fd1498Szrj //
5*38fd1498Szrj // This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj // software; you can redistribute it and/or modify it under the
7*38fd1498Szrj // terms of the GNU General Public License as published by the
8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj // any later version.
10*38fd1498Szrj 
11*38fd1498Szrj // This library is distributed in the hope that it will be useful,
12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj // GNU General Public License for more details.
15*38fd1498Szrj 
16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj // 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj 
20*38fd1498Szrj // You should have received a copy of the GNU General Public License and
21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*38fd1498Szrj // <http://www.gnu.org/licenses/>.
24*38fd1498Szrj 
25*38fd1498Szrj /** @file debug/stl_iterator.h
26*38fd1498Szrj  *  This file is a GNU debug extension to the Standard C++ Library.
27*38fd1498Szrj  */
28*38fd1498Szrj 
29*38fd1498Szrj #ifndef _GLIBCXX_DEBUG_STL_ITERATOR_H
30*38fd1498Szrj #define _GLIBCXX_DEBUG_STL_ITERATOR_H 1
31*38fd1498Szrj 
32*38fd1498Szrj #include <debug/helper_functions.h>
33*38fd1498Szrj 
34*38fd1498Szrj namespace __gnu_debug
35*38fd1498Szrj {
36*38fd1498Szrj   // Help Debug mode to see through reverse_iterator.
37*38fd1498Szrj   template<typename _Iterator>
38*38fd1498Szrj     inline bool
__valid_range(const std::reverse_iterator<_Iterator> & __first,const std::reverse_iterator<_Iterator> & __last,typename _Distance_traits<_Iterator>::__type & __dist)39*38fd1498Szrj     __valid_range(const std::reverse_iterator<_Iterator>& __first,
40*38fd1498Szrj 		  const std::reverse_iterator<_Iterator>& __last,
41*38fd1498Szrj 		  typename _Distance_traits<_Iterator>::__type& __dist)
42*38fd1498Szrj     { return __valid_range(__last.base(), __first.base(), __dist); }
43*38fd1498Szrj 
44*38fd1498Szrj   template<typename _Iterator>
45*38fd1498Szrj     inline typename _Distance_traits<_Iterator>::__type
__get_distance(const std::reverse_iterator<_Iterator> & __first,const std::reverse_iterator<_Iterator> & __last)46*38fd1498Szrj     __get_distance(const std::reverse_iterator<_Iterator>& __first,
47*38fd1498Szrj 		   const std::reverse_iterator<_Iterator>& __last)
48*38fd1498Szrj     { return __get_distance(__last.base(), __first.base()); }
49*38fd1498Szrj 
50*38fd1498Szrj #if __cplusplus < 201103L
51*38fd1498Szrj   template<typename _Iterator>
52*38fd1498Szrj     struct __is_safe_random_iterator<std::reverse_iterator<_Iterator> >
53*38fd1498Szrj       : __is_safe_random_iterator<_Iterator>
54*38fd1498Szrj     { };
55*38fd1498Szrj 
56*38fd1498Szrj   template<typename _Iterator>
57*38fd1498Szrj     struct _Unsafe_type<std::reverse_iterator<_Iterator> >
58*38fd1498Szrj     {
59*38fd1498Szrj       typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
60*38fd1498Szrj       typedef std::reverse_iterator<_UnsafeType> _Type;
61*38fd1498Szrj     };
62*38fd1498Szrj 
63*38fd1498Szrj   template<typename _Iterator>
64*38fd1498Szrj     inline std::reverse_iterator<typename _Unsafe_type<_Iterator>::_Type>
65*38fd1498Szrj     __unsafe(const std::reverse_iterator<_Iterator>& __it)
66*38fd1498Szrj     {
67*38fd1498Szrj       typedef typename _Unsafe_type<_Iterator>::_Type _UnsafeType;
68*38fd1498Szrj       return std::reverse_iterator<_UnsafeType>(__unsafe(__it.base()));
69*38fd1498Szrj     }
70*38fd1498Szrj #else
71*38fd1498Szrj   template<typename _Iterator>
72*38fd1498Szrj     inline auto
73*38fd1498Szrj     __base(const std::reverse_iterator<_Iterator>& __it)
74*38fd1498Szrj     -> decltype(std::__make_reverse_iterator(__base(__it.base())))
75*38fd1498Szrj     { return std::__make_reverse_iterator(__base(__it.base())); }
76*38fd1498Szrj 
77*38fd1498Szrj   template<typename _Iterator>
78*38fd1498Szrj     inline auto
79*38fd1498Szrj     __unsafe(const std::reverse_iterator<_Iterator>& __it)
80*38fd1498Szrj     -> decltype(std::__make_reverse_iterator(__unsafe(__it.base())))
81*38fd1498Szrj     { return std::__make_reverse_iterator(__unsafe(__it.base())); }
82*38fd1498Szrj #endif
83*38fd1498Szrj 
84*38fd1498Szrj #if __cplusplus >= 201103L
85*38fd1498Szrj   // Help Debug mode to see through move_iterator.
86*38fd1498Szrj   template<typename _Iterator>
87*38fd1498Szrj     inline bool
88*38fd1498Szrj     __valid_range(const std::move_iterator<_Iterator>& __first,
89*38fd1498Szrj 		  const std::move_iterator<_Iterator>& __last,
90*38fd1498Szrj 		  typename _Distance_traits<_Iterator>::__type& __dist)
91*38fd1498Szrj     { return __valid_range(__first.base(), __last.base(), __dist); }
92*38fd1498Szrj 
93*38fd1498Szrj   template<typename _Iterator>
94*38fd1498Szrj     inline typename _Distance_traits<_Iterator>::__type
95*38fd1498Szrj     __get_distance(const std::move_iterator<_Iterator>& __first,
96*38fd1498Szrj 		   const std::move_iterator<_Iterator>& __last)
97*38fd1498Szrj     { return __get_distance(__first.base(), __last.base()); }
98*38fd1498Szrj 
99*38fd1498Szrj   template<typename _Iterator>
100*38fd1498Szrj     inline auto
101*38fd1498Szrj     __unsafe(const std::move_iterator<_Iterator>& __it)
102*38fd1498Szrj     -> decltype(std::make_move_iterator(__unsafe(__it.base())))
103*38fd1498Szrj     { return std::make_move_iterator(__unsafe(__it.base())); }
104*38fd1498Szrj 
105*38fd1498Szrj   template<typename _Iterator>
106*38fd1498Szrj     inline auto
107*38fd1498Szrj     __base(const std::move_iterator<_Iterator>& __it)
108*38fd1498Szrj     -> decltype(std::make_move_iterator(__base(__it.base())))
109*38fd1498Szrj     { return std::make_move_iterator(__base(__it.base())); }
110*38fd1498Szrj #endif
111*38fd1498Szrj }
112*38fd1498Szrj 
113*38fd1498Szrj #endif
114