4 * Hewlett-Packard Company
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.
15 * Copyright (c) 1996-1998
16 * Silicon Graphics Computer Systems, Inc.
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.
27 /* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
31 #ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
32 #define __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
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.
39 #pragma GCC system header
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
{};
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.
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
;
60 typedef _Tp
& reference
;
63 struct output_iterator
{
64 typedef output_iterator_tag iterator_category
;
65 typedef void value_type
;
66 typedef void difference_type
;
68 typedef void reference
;
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
;
76 typedef _Tp
& reference
;
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
;
85 typedef _Tp
& reference
;
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
;
93 typedef _Tp
& reference
;
96 template <class _Category
, class _Tp
, class _Distance
= ptrdiff_t,
97 class _Pointer
= _Tp
*, class _Reference
= _Tp
&>
99 typedef _Category iterator_category
;
100 typedef _Tp value_type
;
101 typedef _Distance difference_type
;
102 typedef _Pointer pointer
;
103 typedef _Reference reference
;
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
;
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
;
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
;
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.
138 // We introduce internal names for these functions.
140 template <class _Iter
>
141 inline typename iterator_traits
<_Iter
>::iterator_category
142 __iterator_category(const _Iter
&)
144 typedef typename iterator_traits
<_Iter
>::iterator_category _Category
;
148 template <class _Iter
>
149 inline typename iterator_traits
<_Iter
>::difference_type
*
150 __distance_type(const _Iter
&)
152 return static_cast<typename iterator_traits
<_Iter
>::difference_type
*>(0);
155 template <class _Iter
>
156 inline typename iterator_traits
<_Iter
>::value_type
*
157 __value_type(const _Iter
&)
159 return static_cast<typename iterator_traits
<_Iter
>::value_type
*>(0);
162 template <class _Iter
>
163 inline typename iterator_traits
<_Iter
>::iterator_category
164 iterator_category(const _Iter
& __i
) { return __iterator_category(__i
); }
167 template <class _Iter
>
168 inline typename iterator_traits
<_Iter
>::difference_type
*
169 distance_type(const _Iter
& __i
) { return __distance_type(__i
); }
171 template <class _Iter
>
172 inline typename iterator_traits
<_Iter
>::value_type
*
173 value_type(const _Iter
& __i
) { return __value_type(__i
); }
177 #endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H */