algo.h: Add "GPL plus runtime exception" comment block, this time for real.
[gcc.git] / libstdc++-v3 / include / bits / stl_iterator_base_types.h
1 // Types used in iterator implementation -*- C++ -*-
2
3 // Copyright (C) 2001 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /*
31 *
32 * Copyright (c) 1994
33 * Hewlett-Packard Company
34 *
35 * Permission to use, copy, modify, distribute and sell this software
36 * and its documentation for any purpose is hereby granted without fee,
37 * provided that the above copyright notice appear in all copies and
38 * that both that copyright notice and this permission notice appear
39 * in supporting documentation. Hewlett-Packard Company makes no
40 * representations about the suitability of this software for any
41 * purpose. It is provided "as is" without express or implied warranty.
42 *
43 *
44 * Copyright (c) 1996-1998
45 * Silicon Graphics Computer Systems, Inc.
46 *
47 * Permission to use, copy, modify, distribute and sell this software
48 * and its documentation for any purpose is hereby granted without fee,
49 * provided that the above copyright notice appear in all copies and
50 * that both that copyright notice and this permission notice appear
51 * in supporting documentation. Silicon Graphics makes no
52 * representations about the suitability of this software for any
53 * purpose. It is provided "as is" without express or implied warranty.
54 */
55
56 /* NOTE: This is an internal header file, included by other STL headers.
57 * You should not attempt to use it directly.
58 */
59
60 #ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
61 #define __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
62
63 // This file contains all of the general iterator-related utility
64 // types, such as iterator_traits and struct iterator.
65 // The internal file stl_iterator.h contains predefined iterators,
66 // such as front_insert_iterator and istream_iterator.
67
68 #pragma GCC system_header
69
70 #include <bits/std_cstddef.h> // for ptrdiff_t
71
72
73 namespace std
74 {
75
76 struct input_iterator_tag {};
77 struct output_iterator_tag {};
78 struct forward_iterator_tag : public input_iterator_tag {};
79 struct bidirectional_iterator_tag : public forward_iterator_tag {};
80 struct random_access_iterator_tag : public bidirectional_iterator_tag {};
81
82 // The base classes input_iterator, output_iterator, forward_iterator,
83 // bidirectional_iterator, and random_access_iterator are not part of
84 // the C++ standard. (They have been replaced by struct iterator.)
85 // They are included for backward compatibility with the HP STL.
86
87 template <class _Tp, class _Distance> struct input_iterator {
88 typedef input_iterator_tag iterator_category;
89 typedef _Tp value_type;
90 typedef _Distance difference_type;
91 typedef _Tp* pointer;
92 typedef _Tp& reference;
93 };
94
95 struct output_iterator {
96 typedef output_iterator_tag iterator_category;
97 typedef void value_type;
98 typedef void difference_type;
99 typedef void pointer;
100 typedef void reference;
101 };
102
103 template <class _Tp, class _Distance> struct forward_iterator {
104 typedef forward_iterator_tag iterator_category;
105 typedef _Tp value_type;
106 typedef _Distance difference_type;
107 typedef _Tp* pointer;
108 typedef _Tp& reference;
109 };
110
111
112 template <class _Tp, class _Distance> struct bidirectional_iterator {
113 typedef bidirectional_iterator_tag iterator_category;
114 typedef _Tp value_type;
115 typedef _Distance difference_type;
116 typedef _Tp* pointer;
117 typedef _Tp& reference;
118 };
119
120 template <class _Tp, class _Distance> struct random_access_iterator {
121 typedef random_access_iterator_tag iterator_category;
122 typedef _Tp value_type;
123 typedef _Distance difference_type;
124 typedef _Tp* pointer;
125 typedef _Tp& reference;
126 };
127
128 template <class _Category, class _Tp, class _Distance = ptrdiff_t,
129 class _Pointer = _Tp*, class _Reference = _Tp&>
130 struct iterator {
131 typedef _Category iterator_category;
132 typedef _Tp value_type;
133 typedef _Distance difference_type;
134 typedef _Pointer pointer;
135 typedef _Reference reference;
136 };
137
138 template <class _Iterator>
139 struct iterator_traits {
140 typedef typename _Iterator::iterator_category iterator_category;
141 typedef typename _Iterator::value_type value_type;
142 typedef typename _Iterator::difference_type difference_type;
143 typedef typename _Iterator::pointer pointer;
144 typedef typename _Iterator::reference reference;
145 };
146
147 template <class _Tp>
148 struct iterator_traits<_Tp*> {
149 typedef random_access_iterator_tag iterator_category;
150 typedef _Tp value_type;
151 typedef ptrdiff_t difference_type;
152 typedef _Tp* pointer;
153 typedef _Tp& reference;
154 };
155
156 template <class _Tp>
157 struct iterator_traits<const _Tp*> {
158 typedef random_access_iterator_tag iterator_category;
159 typedef _Tp value_type;
160 typedef ptrdiff_t difference_type;
161 typedef const _Tp* pointer;
162 typedef const _Tp& reference;
163 };
164
165 // The overloaded functions iterator_category, distance_type, and
166 // value_type are not part of the C++ standard. (They have been
167 // replaced by struct iterator_traits.) They are included for
168 // backward compatibility with the HP STL.
169
170 // We introduce internal names for these functions.
171
172 template <class _Iter>
173 inline typename iterator_traits<_Iter>::iterator_category
174 __iterator_category(const _Iter&)
175 {
176 typedef typename iterator_traits<_Iter>::iterator_category _Category;
177 return _Category();
178 }
179
180 template <class _Iter>
181 inline typename iterator_traits<_Iter>::difference_type*
182 __distance_type(const _Iter&)
183 {
184 return static_cast<typename iterator_traits<_Iter>::difference_type*>(0);
185 }
186
187 template <class _Iter>
188 inline typename iterator_traits<_Iter>::value_type*
189 __value_type(const _Iter&)
190 {
191 return static_cast<typename iterator_traits<_Iter>::value_type*>(0);
192 }
193
194 template <class _Iter>
195 inline typename iterator_traits<_Iter>::iterator_category
196 iterator_category(const _Iter& __i) { return __iterator_category(__i); }
197
198
199 template <class _Iter>
200 inline typename iterator_traits<_Iter>::difference_type*
201 distance_type(const _Iter& __i) { return __distance_type(__i); }
202
203 template <class _Iter>
204 inline typename iterator_traits<_Iter>::value_type*
205 value_type(const _Iter& __i) { return __value_type(__i); }
206
207 } // namespace std
208
209 #endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H */
210
211
212 // Local Variables:
213 // mode:C++
214 // End: