Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

stl_iterator_base_types.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  *
00015  * Copyright (c) 1996-1998
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */
00026 
00027 /* NOTE: This is an internal header file, included by other STL headers.
00028  *   You should not attempt to use it directly.
00029  */
00030 
00031 #ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
00032 #define __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
00033 
00034 // This file contains all of the general iterator-related utility
00035 // types, such as iterator_traits and struct iterator.
00036 // The internal file stl_iterator.h contains predefined iterators, 
00037 // such as front_insert_iterator and istream_iterator.
00038 
00039 #pragma GCC system_header
00040 
00041 #include <bits/std_cstddef.h>     // for ptrdiff_t
00042 
00043 
00044 namespace std
00045 {
00046 
00047 struct input_iterator_tag {};
00048 struct output_iterator_tag {};
00049 struct forward_iterator_tag : public input_iterator_tag {};
00050 struct bidirectional_iterator_tag : public forward_iterator_tag {};
00051 struct random_access_iterator_tag : public bidirectional_iterator_tag {};
00052 
00053 // The base classes input_iterator, output_iterator, forward_iterator,
00054 // bidirectional_iterator, and random_access_iterator are not part of
00055 // the C++ standard.  (They have been replaced by struct iterator.)
00056 // They are included for backward compatibility with the HP STL.
00057 
00058 template <class _Tp, class _Distance> struct input_iterator {
00059   typedef input_iterator_tag iterator_category;
00060   typedef _Tp                value_type;
00061   typedef _Distance          difference_type;
00062   typedef _Tp*               pointer;
00063   typedef _Tp&               reference;
00064 };
00065 
00066 struct output_iterator {
00067   typedef output_iterator_tag iterator_category;
00068   typedef void                value_type;
00069   typedef void                difference_type;
00070   typedef void                pointer;
00071   typedef void                reference;
00072 };
00073 
00074 template <class _Tp, class _Distance> struct forward_iterator {
00075   typedef forward_iterator_tag iterator_category;
00076   typedef _Tp                  value_type;
00077   typedef _Distance            difference_type;
00078   typedef _Tp*                 pointer;
00079   typedef _Tp&                 reference;
00080 };
00081 
00082 
00083 template <class _Tp, class _Distance> struct bidirectional_iterator {
00084   typedef bidirectional_iterator_tag iterator_category;
00085   typedef _Tp                        value_type;
00086   typedef _Distance                  difference_type;
00087   typedef _Tp*                       pointer;
00088   typedef _Tp&                       reference;
00089 };
00090 
00091 template <class _Tp, class _Distance> struct random_access_iterator {
00092   typedef random_access_iterator_tag iterator_category;
00093   typedef _Tp                        value_type;
00094   typedef _Distance                  difference_type;
00095   typedef _Tp*                       pointer;
00096   typedef _Tp&                       reference;
00097 };
00098 
00099 template <class _Category, class _Tp, class _Distance = ptrdiff_t,
00100           class _Pointer = _Tp*, class _Reference = _Tp&>
00101 struct iterator {
00102   typedef _Category  iterator_category;
00103   typedef _Tp        value_type;
00104   typedef _Distance  difference_type;
00105   typedef _Pointer   pointer;
00106   typedef _Reference reference;
00107 };
00108 
00109 template <class _Iterator>
00110 struct iterator_traits {
00111   typedef typename _Iterator::iterator_category iterator_category;
00112   typedef typename _Iterator::value_type        value_type;
00113   typedef typename _Iterator::difference_type   difference_type;
00114   typedef typename _Iterator::pointer           pointer;
00115   typedef typename _Iterator::reference         reference;
00116 };
00117 
00118 template <class _Tp>
00119 struct iterator_traits<_Tp*> {
00120   typedef random_access_iterator_tag iterator_category;
00121   typedef _Tp                         value_type;
00122   typedef ptrdiff_t                   difference_type;
00123   typedef _Tp*                        pointer;
00124   typedef _Tp&                        reference;
00125 };
00126 
00127 template <class _Tp>
00128 struct iterator_traits<const _Tp*> {
00129   typedef random_access_iterator_tag iterator_category;
00130   typedef _Tp                         value_type;
00131   typedef ptrdiff_t                   difference_type;
00132   typedef const _Tp*                  pointer;
00133   typedef const _Tp&                  reference;
00134 };
00135 
00136 // The overloaded functions iterator_category, distance_type, and
00137 // value_type are not part of the C++ standard.  (They have been
00138 // replaced by struct iterator_traits.)  They are included for
00139 // backward compatibility with the HP STL.
00140 
00141 // We introduce internal names for these functions.
00142 
00143 template <class _Iter>
00144 inline typename iterator_traits<_Iter>::iterator_category
00145 __iterator_category(const _Iter&)
00146 {
00147   typedef typename iterator_traits<_Iter>::iterator_category _Category;
00148   return _Category();
00149 }
00150 
00151 template <class _Iter>
00152 inline typename iterator_traits<_Iter>::difference_type*
00153 __distance_type(const _Iter&)
00154 {
00155   return static_cast<typename iterator_traits<_Iter>::difference_type*>(0);
00156 }
00157 
00158 template <class _Iter>
00159 inline typename iterator_traits<_Iter>::value_type*
00160 __value_type(const _Iter&)
00161 {
00162   return static_cast<typename iterator_traits<_Iter>::value_type*>(0);
00163 }
00164 
00165 template <class _Iter>
00166 inline typename iterator_traits<_Iter>::iterator_category
00167 iterator_category(const _Iter& __i) { return __iterator_category(__i); }
00168 
00169 
00170 template <class _Iter>
00171 inline typename iterator_traits<_Iter>::difference_type*
00172 distance_type(const _Iter& __i) { return __distance_type(__i); }
00173 
00174 template <class _Iter>
00175 inline typename iterator_traits<_Iter>::value_type*
00176 value_type(const _Iter& __i) { return __value_type(__i); }
00177 
00178 } // namespace std
00179 
00180 #endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H */
00181 
00182 
00183 // Local Variables:
00184 // mode:C++
00185 // End:

Generated at Tue May 1 16:28:39 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001