00001 // Types used in iterator implementation -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 00004 // Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 3, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // Under Section 7 of GPL version 3, you are granted additional 00018 // permissions described in the GCC Runtime Library Exception, version 00019 // 3.1, as published by the Free Software Foundation. 00020 00021 // You should have received a copy of the GNU General Public License and 00022 // a copy of the GCC Runtime Library Exception along with this program; 00023 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00024 // <http://www.gnu.org/licenses/>. 00025 00026 /* 00027 * 00028 * Copyright (c) 1994 00029 * Hewlett-Packard Company 00030 * 00031 * Permission to use, copy, modify, distribute and sell this software 00032 * and its documentation for any purpose is hereby granted without fee, 00033 * provided that the above copyright notice appear in all copies and 00034 * that both that copyright notice and this permission notice appear 00035 * in supporting documentation. Hewlett-Packard Company makes no 00036 * representations about the suitability of this software for any 00037 * purpose. It is provided "as is" without express or implied warranty. 00038 * 00039 * 00040 * Copyright (c) 1996-1998 00041 * Silicon Graphics Computer Systems, Inc. 00042 * 00043 * Permission to use, copy, modify, distribute and sell this software 00044 * and its documentation for any purpose is hereby granted without fee, 00045 * provided that the above copyright notice appear in all copies and 00046 * that both that copyright notice and this permission notice appear 00047 * in supporting documentation. Silicon Graphics makes no 00048 * representations about the suitability of this software for any 00049 * purpose. It is provided "as is" without express or implied warranty. 00050 */ 00051 00052 /** @file stl_iterator_base_types.h 00053 * This is an internal header file, included by other library headers. 00054 * You should not attempt to use it directly. 00055 * 00056 * This file contains all of the general iterator-related utility types, 00057 * such as iterator_traits and struct iterator. 00058 */ 00059 00060 #ifndef _STL_ITERATOR_BASE_TYPES_H 00061 #define _STL_ITERATOR_BASE_TYPES_H 1 00062 00063 #pragma GCC system_header 00064 00065 #include <bits/c++config.h> 00066 #include <cstddef> 00067 00068 _GLIBCXX_BEGIN_NAMESPACE(std) 00069 00070 /** 00071 * @defgroup iterators Iterators 00072 * These are empty types, used to distinguish different iterators. The 00073 * distinction is not made by what they contain, but simply by what they 00074 * are. Different underlying algorithms can then be used based on the 00075 * different operations supported by different iterator types. 00076 */ 00077 //@{ 00078 /// Marking input iterators. 00079 struct input_iterator_tag { }; 00080 /// Marking output iterators. 00081 struct output_iterator_tag { }; 00082 /// Forward iterators support a superset of input iterator operations. 00083 struct forward_iterator_tag : public input_iterator_tag { }; 00084 /// Bidirectional iterators support a superset of forward iterator 00085 /// operations. 00086 struct bidirectional_iterator_tag : public forward_iterator_tag { }; 00087 /// Random-access iterators support a superset of bidirectional iterator 00088 /// operations. 00089 struct random_access_iterator_tag : public bidirectional_iterator_tag { }; 00090 00091 00092 /** 00093 * @brief Common %iterator class. 00094 * 00095 * This class does nothing but define nested typedefs. %Iterator classes 00096 * can inherit from this class to save some work. The typedefs are then 00097 * used in specializations and overloading. 00098 * 00099 * In particular, there are no default implementations of requirements 00100 * such as @c operator++ and the like. (How could there be?) 00101 */ 00102 template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t, 00103 typename _Pointer = _Tp*, typename _Reference = _Tp&> 00104 struct iterator 00105 { 00106 /// One of the @link iterator_tags tag types@endlink. 00107 typedef _Category iterator_category; 00108 /// The type "pointed to" by the iterator. 00109 typedef _Tp value_type; 00110 /// Distance between iterators is represented as this type. 00111 typedef _Distance difference_type; 00112 /// This type represents a pointer-to-value_type. 00113 typedef _Pointer pointer; 00114 /// This type represents a reference-to-value_type. 00115 typedef _Reference reference; 00116 }; 00117 00118 /** 00119 * This class does nothing but define nested typedefs. The general 00120 * version simply "forwards" the nested typedefs from the Iterator 00121 * argument. Specialized versions for pointers and pointers-to-const 00122 * provide tighter, more correct semantics. 00123 */ 00124 template<typename _Iterator> 00125 struct iterator_traits 00126 { 00127 typedef typename _Iterator::iterator_category iterator_category; 00128 typedef typename _Iterator::value_type value_type; 00129 typedef typename _Iterator::difference_type difference_type; 00130 typedef typename _Iterator::pointer pointer; 00131 typedef typename _Iterator::reference reference; 00132 }; 00133 00134 template<typename _Tp> 00135 struct iterator_traits<_Tp*> 00136 { 00137 typedef random_access_iterator_tag iterator_category; 00138 typedef _Tp value_type; 00139 typedef ptrdiff_t difference_type; 00140 typedef _Tp* pointer; 00141 typedef _Tp& reference; 00142 }; 00143 00144 template<typename _Tp> 00145 struct iterator_traits<const _Tp*> 00146 { 00147 typedef random_access_iterator_tag iterator_category; 00148 typedef _Tp value_type; 00149 typedef ptrdiff_t difference_type; 00150 typedef const _Tp* pointer; 00151 typedef const _Tp& reference; 00152 }; 00153 00154 /** 00155 * This function is not a part of the C++ standard but is syntactic 00156 * sugar for internal library use only. 00157 */ 00158 template<typename _Iter> 00159 inline typename iterator_traits<_Iter>::iterator_category 00160 __iterator_category(const _Iter&) 00161 { return typename iterator_traits<_Iter>::iterator_category(); } 00162 00163 //@} 00164 00165 _GLIBCXX_END_NAMESPACE 00166 00167 #endif /* _STL_ITERATOR_BASE_TYPES_H */ 00168