]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/stl_iterator_base_types.h
New concept checking implementation.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / stl_iterator_base_types.h
1 /*
2 *
3 * Copyright (c) 1994
4 * Hewlett-Packard Company
5 *
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Hewlett-Packard Company makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 *
15 * Copyright (c) 1996-1998
16 * Silicon Graphics Computer Systems, Inc.
17 *
18 * Permission to use, copy, modify, distribute and sell this software
19 * and its documentation for any purpose is hereby granted without fee,
20 * provided that the above copyright notice appear in all copies and
21 * that both that copyright notice and this permission notice appear
22 * in supporting documentation. Silicon Graphics makes no
23 * representations about the suitability of this software for any
24 * purpose. It is provided "as is" without express or implied warranty.
25 */
26
27 /* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
29 */
30
31 #ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
32 #define __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
33
34 // This file contains all of the general iterator-related utility
35 // types, such as iterator_traits and struct iterator.
36 // The internal file stl_iterator.h contains predefined iterators,
37 // such as front_insert_iterator and istream_iterator.
38
39 #pragma GCC system header
40
41 namespace std
42 {
43
44 struct input_iterator_tag {};
45 struct output_iterator_tag {};
46 struct forward_iterator_tag : public input_iterator_tag {};
47 struct bidirectional_iterator_tag : public forward_iterator_tag {};
48 struct random_access_iterator_tag : public bidirectional_iterator_tag {};
49
50 // The base classes input_iterator, output_iterator, forward_iterator,
51 // bidirectional_iterator, and random_access_iterator are not part of
52 // the C++ standard. (They have been replaced by struct iterator.)
53 // They are included for backward compatibility with the HP STL.
54
55 template <class _Tp, class _Distance> struct input_iterator {
56 typedef input_iterator_tag iterator_category;
57 typedef _Tp value_type;
58 typedef _Distance difference_type;
59 typedef _Tp* pointer;
60 typedef _Tp& reference;
61 };
62
63 struct output_iterator {
64 typedef output_iterator_tag iterator_category;
65 typedef void value_type;
66 typedef void difference_type;
67 typedef void pointer;
68 typedef void reference;
69 };
70
71 template <class _Tp, class _Distance> struct forward_iterator {
72 typedef forward_iterator_tag iterator_category;
73 typedef _Tp value_type;
74 typedef _Distance difference_type;
75 typedef _Tp* pointer;
76 typedef _Tp& reference;
77 };
78
79
80 template <class _Tp, class _Distance> struct bidirectional_iterator {
81 typedef bidirectional_iterator_tag iterator_category;
82 typedef _Tp value_type;
83 typedef _Distance difference_type;
84 typedef _Tp* pointer;
85 typedef _Tp& reference;
86 };
87
88 template <class _Tp, class _Distance> struct random_access_iterator {
89 typedef random_access_iterator_tag iterator_category;
90 typedef _Tp value_type;
91 typedef _Distance difference_type;
92 typedef _Tp* pointer;
93 typedef _Tp& reference;
94 };
95
96 template <class _Category, class _Tp, class _Distance = ptrdiff_t,
97 class _Pointer = _Tp*, class _Reference = _Tp&>
98 struct iterator {
99 typedef _Category iterator_category;
100 typedef _Tp value_type;
101 typedef _Distance difference_type;
102 typedef _Pointer pointer;
103 typedef _Reference reference;
104 };
105
106 template <class _Iterator>
107 struct iterator_traits {
108 typedef typename _Iterator::iterator_category iterator_category;
109 typedef typename _Iterator::value_type value_type;
110 typedef typename _Iterator::difference_type difference_type;
111 typedef typename _Iterator::pointer pointer;
112 typedef typename _Iterator::reference reference;
113 };
114
115 template <class _Tp>
116 struct iterator_traits<_Tp*> {
117 typedef random_access_iterator_tag iterator_category;
118 typedef _Tp value_type;
119 typedef ptrdiff_t difference_type;
120 typedef _Tp* pointer;
121 typedef _Tp& reference;
122 };
123
124 template <class _Tp>
125 struct iterator_traits<const _Tp*> {
126 typedef random_access_iterator_tag iterator_category;
127 typedef _Tp value_type;
128 typedef ptrdiff_t difference_type;
129 typedef const _Tp* pointer;
130 typedef const _Tp& reference;
131 };
132
133 // The overloaded functions iterator_category, distance_type, and
134 // value_type are not part of the C++ standard. (They have been
135 // replaced by struct iterator_traits.) They are included for
136 // backward compatibility with the HP STL.
137
138 // We introduce internal names for these functions.
139
140 template <class _Iter>
141 inline typename iterator_traits<_Iter>::iterator_category
142 __iterator_category(const _Iter&)
143 {
144 typedef typename iterator_traits<_Iter>::iterator_category _Category;
145 return _Category();
146 }
147
148 template <class _Iter>
149 inline typename iterator_traits<_Iter>::difference_type*
150 __distance_type(const _Iter&)
151 {
152 return static_cast<typename iterator_traits<_Iter>::difference_type*>(0);
153 }
154
155 template <class _Iter>
156 inline typename iterator_traits<_Iter>::value_type*
157 __value_type(const _Iter&)
158 {
159 return static_cast<typename iterator_traits<_Iter>::value_type*>(0);
160 }
161
162 template <class _Iter>
163 inline typename iterator_traits<_Iter>::iterator_category
164 iterator_category(const _Iter& __i) { return __iterator_category(__i); }
165
166
167 template <class _Iter>
168 inline typename iterator_traits<_Iter>::difference_type*
169 distance_type(const _Iter& __i) { return __distance_type(__i); }
170
171 template <class _Iter>
172 inline typename iterator_traits<_Iter>::value_type*
173 value_type(const _Iter& __i) { return __value_type(__i); }
174
175 } // namespace std
176
177 #endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H */
178
179
180 // Local Variables:
181 // mode:C++
182 // End: