1 // Types used in iterator implementation -*- C++ -*-
3 // Copyright (C) 2001 Free Software Foundation, Inc.
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)
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.
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,
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.
33 * Hewlett-Packard Company
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.
44 * Copyright (c) 1996-1998
45 * Silicon Graphics Computer Systems, Inc.
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.
56 /* NOTE: This is an internal header file, included by other STL headers.
57 * You should not attempt to use it directly.
60 #ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
61 #define __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
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.
68 #pragma GCC system_header
70 #include <bits/std_cstddef.h> // for ptrdiff_t
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
{};
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.
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
;
92 typedef _Tp
& reference
;
95 struct output_iterator
{
96 typedef output_iterator_tag iterator_category
;
97 typedef void value_type
;
98 typedef void difference_type
;
100 typedef void reference
;
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
;
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
;
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
;
128 template <class _Category
, class _Tp
, class _Distance
= ptrdiff_t,
129 class _Pointer
= _Tp
*, class _Reference
= _Tp
&>
131 typedef _Category iterator_category
;
132 typedef _Tp value_type
;
133 typedef _Distance difference_type
;
134 typedef _Pointer pointer
;
135 typedef _Reference reference
;
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
;
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
;
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
;
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.
170 // We introduce internal names for these functions.
172 template <class _Iter
>
173 inline typename iterator_traits
<_Iter
>::iterator_category
174 __iterator_category(const _Iter
&)
176 typedef typename iterator_traits
<_Iter
>::iterator_category _Category
;
180 template <class _Iter
>
181 inline typename iterator_traits
<_Iter
>::difference_type
*
182 __distance_type(const _Iter
&)
184 return static_cast<typename iterator_traits
<_Iter
>::difference_type
*>(0);
187 template <class _Iter
>
188 inline typename iterator_traits
<_Iter
>::value_type
*
189 __value_type(const _Iter
&)
191 return static_cast<typename iterator_traits
<_Iter
>::value_type
*>(0);
194 template <class _Iter
>
195 inline typename iterator_traits
<_Iter
>::iterator_category
196 iterator_category(const _Iter
& __i
) { return __iterator_category(__i
); }
199 template <class _Iter
>
200 inline typename iterator_traits
<_Iter
>::difference_type
*
201 distance_type(const _Iter
& __i
) { return __distance_type(__i
); }
203 template <class _Iter
>
204 inline typename iterator_traits
<_Iter
>::value_type
*
205 value_type(const _Iter
& __i
) { return __value_type(__i
); }
209 #endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H */