1 // Types used in iterator implementation -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
34 * Hewlett-Packard Company
36 * Permission to use, copy, modify, distribute and sell this software
37 * and its documentation for any purpose is hereby granted without fee,
38 * provided that the above copyright notice appear in all copies and
39 * that both that copyright notice and this permission notice appear
40 * in supporting documentation. Hewlett-Packard Company makes no
41 * representations about the suitability of this software for any
42 * purpose. It is provided "as is" without express or implied warranty.
45 * Copyright (c) 1996-1998
46 * Silicon Graphics Computer Systems, Inc.
48 * Permission to use, copy, modify, distribute and sell this software
49 * and its documentation for any purpose is hereby granted without fee,
50 * provided that the above copyright notice appear in all copies and
51 * that both that copyright notice and this permission notice appear
52 * in supporting documentation. Silicon Graphics makes no
53 * representations about the suitability of this software for any
54 * purpose. It is provided "as is" without express or implied warranty.
57 /** @file stl_iterator_base_types.h
58 * This is an internal header file, included by other library headers.
59 * You should not attempt to use it directly.
61 * This file contains all of the general iterator-related utility types,
62 * such as iterator_traits and struct iterator.
65 #ifndef _ITERATOR_BASE_TYPES_H
66 #define _ITERATOR_BASE_TYPES_H 1
68 #pragma GCC system_header
70 #include <bits/c++config.h>
73 _GLIBCXX_BEGIN_NAMESPACE(std
)
77 * @defgroup iterator_tags Iterator Tags
78 * These are empty types, used to distinguish different iterators. The
79 * distinction is not made by what they contain, but simply by what they
80 * are. Different underlying algorithms can then be used based on the
81 * different operations supporetd by different iterator types.
83 /// Marking input iterators.
84 struct input_iterator_tag
{};
85 /// Marking output iterators.
86 struct output_iterator_tag
{};
87 /// Forward iterators support a superset of input iterator operations.
88 struct forward_iterator_tag
: public input_iterator_tag
{};
89 /// Bidirectional iterators support a superset of forward iterator
91 struct bidirectional_iterator_tag
: public forward_iterator_tag
{};
92 /// Random-access iterators support a superset of bidirectional iterator
94 struct random_access_iterator_tag
: public bidirectional_iterator_tag
{};
99 * @brief Common %iterator class.
101 * This class does nothing but define nested typedefs. %Iterator classes
102 * can inherit from this class to save some work. The typedefs are then
103 * used in specializations and overloading.
105 * In particular, there are no default implementations of requirements
106 * such as @c operator++ and the like. (How could there be?)
108 template<typename _Category
, typename _Tp
, typename _Distance
= ptrdiff_t,
109 typename _Pointer
= _Tp
*, typename _Reference
= _Tp
&>
112 /// One of the @link iterator_tags tag types@endlink.
113 typedef _Category iterator_category
;
114 /// The type "pointed to" by the iterator.
115 typedef _Tp value_type
;
116 /// Distance between iterators is represented as this type.
117 typedef _Distance difference_type
;
118 /// This type represents a pointer-to-value_type.
119 typedef _Pointer pointer
;
120 /// This type represents a reference-to-value_type.
121 typedef _Reference reference
;
125 * This class does nothing but define nested typedefs. The general
126 * version simply "forwards" the nested typedefs from the Iterator
127 * argument. Specialized versions for pointers and pointers-to-const
128 * provide tighter, more correct semantics.
130 template<typename _Iterator
>
131 struct iterator_traits
133 typedef typename
_Iterator::iterator_category iterator_category
;
134 typedef typename
_Iterator::value_type value_type
;
135 typedef typename
_Iterator::difference_type difference_type
;
136 typedef typename
_Iterator::pointer pointer
;
137 typedef typename
_Iterator::reference reference
;
140 template<typename _Tp
>
141 struct iterator_traits
<_Tp
*>
143 typedef random_access_iterator_tag iterator_category
;
144 typedef _Tp value_type
;
145 typedef ptrdiff_t difference_type
;
146 typedef _Tp
* pointer
;
147 typedef _Tp
& reference
;
150 template<typename _Tp
>
151 struct iterator_traits
<const _Tp
*>
153 typedef random_access_iterator_tag iterator_category
;
154 typedef _Tp value_type
;
155 typedef ptrdiff_t difference_type
;
156 typedef const _Tp
* pointer
;
157 typedef const _Tp
& reference
;
162 * This function is not a part of the C++ standard but is syntactic
163 * sugar for internal library use only.
166 template<typename _Iter
>
167 inline typename iterator_traits
<_Iter
>::iterator_category
168 __iterator_category(const _Iter
&)
169 { return typename iterator_traits
<_Iter
>::iterator_category(); }
171 _GLIBCXX_END_NAMESPACE
173 #endif /* _ITERATOR_BASE_TYPES_H */