]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/include/bits/stl_iterator_base_types.h
Move from CPP to CXX.
[gcc.git] / libstdc++-v3 / include / bits / stl_iterator_base_types.h
CommitLineData
42526146
PE
1// Types used in iterator implementation -*- C++ -*-
2
8f94053d 3// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
42526146
PE
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
725dc051
BK
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
729e3d3f
PE
56/** @file stl_iterator_base_types.h
57 * This is an internal header file, included by other library headers.
58 * You should not attempt to use it directly.
82b61df5
PE
59 *
60 * This file contains all of the general iterator-related utility types,
61 * such as iterator_traits and struct iterator.
725dc051
BK
62 */
63
3d7c150e
BK
64#ifndef _ITERATOR_BASE_TYPES_H
65#define _ITERATOR_BASE_TYPES_H 1
725dc051 66
aa53cb52 67#pragma GCC system_header
725dc051 68
d53d7f6e
PE
69namespace std
70{
840ceb34
PE
71 //@{
72 /**
82b61df5
PE
73 * @defgroup iterator_tags Iterator Tags
74 * These are empty types, used to distinguish different iterators. The
75 * distinction is not made by what they contain, but simply by what they
76 * are. Different underlying algorithms can then be used based on the
77 * different operations supporetd by different iterator types.
82b61df5
PE
78 */
79 /// Marking input iterators.
02d92e3b 80 struct input_iterator_tag {};
82b61df5 81 /// Marking output iterators.
02d92e3b 82 struct output_iterator_tag {};
82b61df5 83 /// Forward iterators support a superset of input iterator operations.
02d92e3b 84 struct forward_iterator_tag : public input_iterator_tag {};
82b61df5 85 /// Bidirectional iterators support a superset of forward iterator operations.
02d92e3b 86 struct bidirectional_iterator_tag : public forward_iterator_tag {};
82b61df5 87 /// Random-access iterators support a superset of bidirectional iterator operations.
02d92e3b 88 struct random_access_iterator_tag : public bidirectional_iterator_tag {};
82b61df5 89 //@}
02d92e3b 90
02d92e3b 91
82b61df5 92 /**
aa2d5ba2
PE
93 * @brief Common %iterator class.
94 *
8f94053d 95 * This class does nothing but define nested typedefs. %Iterator classes
82b61df5
PE
96 * can inherit from this class to save some work. The typedefs are then
97 * used in specializations and overloading.
8f94053d
PE
98 *
99 * In particular, there are no default implementations of requirements
100 * such as @c operator++ and the like. (How could there be?)
82b61df5 101 */
02d92e3b 102 template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t,
aa2d5ba2
PE
103 typename _Pointer = _Tp*, typename _Reference = _Tp&>
104 struct iterator
105 {
82b61df5 106 /// One of the @link iterator_tags tag types@endlink.
02d92e3b 107 typedef _Category iterator_category;
82b61df5 108 /// The type "pointed to" by the iterator.
02d92e3b 109 typedef _Tp value_type;
82b61df5 110 /// Distance between iterators is represented as this type.
02d92e3b 111 typedef _Distance difference_type;
82b61df5 112 /// This type represents a pointer-to-value_type.
02d92e3b 113 typedef _Pointer pointer;
82b61df5 114 /// This type represents a reference-to-value_type.
02d92e3b
SW
115 typedef _Reference reference;
116 };
117
82b61df5
PE
118 /**
119 * This class does nothing but define nested typedefs. The general
120 * version simply "forwards" the nested typedefs from the Iterator
121 * argument. Specialized versions for pointers and pointers-to-const
122 * provide tighter, more correct semantics.
123 */
02d92e3b
SW
124 template<typename _Iterator>
125 struct iterator_traits {
126 typedef typename _Iterator::iterator_category iterator_category;
127 typedef typename _Iterator::value_type value_type;
128 typedef typename _Iterator::difference_type difference_type;
129 typedef typename _Iterator::pointer pointer;
130 typedef typename _Iterator::reference reference;
131 };
132
133 template<typename _Tp>
134 struct iterator_traits<_Tp*> {
135 typedef random_access_iterator_tag iterator_category;
136 typedef _Tp value_type;
137 typedef ptrdiff_t difference_type;
138 typedef _Tp* pointer;
139 typedef _Tp& reference;
140 };
141
142 template<typename _Tp>
143 struct iterator_traits<const _Tp*> {
144 typedef random_access_iterator_tag iterator_category;
145 typedef _Tp value_type;
146 typedef ptrdiff_t difference_type;
147 typedef const _Tp* pointer;
148 typedef const _Tp& reference;
149 };
150
82b61df5 151 /**
04b7c941 152 * @if maint
82b61df5
PE
153 * This function is not a part of the C++ standard but is syntactic
154 * sugar for internal library use only.
04b7c941 155 * @endif
82b61df5 156 */
02d92e3b
SW
157 template<typename _Iter>
158 inline typename iterator_traits<_Iter>::iterator_category
159 __iterator_category(const _Iter&)
160 { return typename iterator_traits<_Iter>::iterator_category(); }
725dc051 161
d53d7f6e 162} // namespace std
725dc051 163
3d7c150e 164#endif /* _ITERATOR_BASE_TYPES_H */
725dc051 165
This page took 0.290102 seconds and 5 git commands to generate.