Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / libstdc++-v3 / include / bits / stl_iterator_base_types.h
blob4a8cf1fbe298fd9e153488b3e162a3864d0d6c7a
1 // Types used in iterator implementation -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
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,
20 // USA.
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.
33 * Copyright (c) 1994
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 _STL_ITERATOR_BASE_TYPES_H
66 #define _STL_ITERATOR_BASE_TYPES_H 1
68 #pragma GCC system_header
70 #include <bits/c++config.h>
71 #include <cstddef>
73 _GLIBCXX_BEGIN_NAMESPACE(std)
75 /**
76 * @defgroup iterators Iterators
77 * These are empty types, used to distinguish different iterators. The
78 * distinction is not made by what they contain, but simply by what they
79 * are. Different underlying algorithms can then be used based on the
80 * different operations supported by different iterator types.
82 //@{
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
90 /// operations.
91 struct bidirectional_iterator_tag : public forward_iterator_tag { };
92 /// Random-access iterators support a superset of bidirectional iterator
93 /// operations.
94 struct random_access_iterator_tag : public bidirectional_iterator_tag { };
97 /**
98 * @brief Common %iterator class.
100 * This class does nothing but define nested typedefs. %Iterator classes
101 * can inherit from this class to save some work. The typedefs are then
102 * used in specializations and overloading.
104 * In particular, there are no default implementations of requirements
105 * such as @c operator++ and the like. (How could there be?)
107 template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t,
108 typename _Pointer = _Tp*, typename _Reference = _Tp&>
109 struct iterator
111 /// One of the @link iterator_tags tag types@endlink.
112 typedef _Category iterator_category;
113 /// The type "pointed to" by the iterator.
114 typedef _Tp value_type;
115 /// Distance between iterators is represented as this type.
116 typedef _Distance difference_type;
117 /// This type represents a pointer-to-value_type.
118 typedef _Pointer pointer;
119 /// This type represents a reference-to-value_type.
120 typedef _Reference reference;
124 * This class does nothing but define nested typedefs. The general
125 * version simply "forwards" the nested typedefs from the Iterator
126 * argument. Specialized versions for pointers and pointers-to-const
127 * provide tighter, more correct semantics.
129 template<typename _Iterator>
130 struct iterator_traits
132 typedef typename _Iterator::iterator_category iterator_category;
133 typedef typename _Iterator::value_type value_type;
134 typedef typename _Iterator::difference_type difference_type;
135 typedef typename _Iterator::pointer pointer;
136 typedef typename _Iterator::reference reference;
139 template<typename _Tp>
140 struct iterator_traits<_Tp*>
142 typedef random_access_iterator_tag iterator_category;
143 typedef _Tp value_type;
144 typedef ptrdiff_t difference_type;
145 typedef _Tp* pointer;
146 typedef _Tp& reference;
149 template<typename _Tp>
150 struct iterator_traits<const _Tp*>
152 typedef random_access_iterator_tag iterator_category;
153 typedef _Tp value_type;
154 typedef ptrdiff_t difference_type;
155 typedef const _Tp* pointer;
156 typedef const _Tp& reference;
160 * This function is not a part of the C++ standard but is syntactic
161 * sugar for internal library use only.
163 template<typename _Iter>
164 inline typename iterator_traits<_Iter>::iterator_category
165 __iterator_category(const _Iter&)
166 { return typename iterator_traits<_Iter>::iterator_category(); }
168 //@}
170 _GLIBCXX_END_NAMESPACE
172 #endif /* _STL_ITERATOR_BASE_TYPES_H */