Whole document tree
    

Whole document tree

stl_iterator_base_types.h Source File
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 // Types used in iterator implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 /*
00031  *
00032  * Copyright (c) 1994
00033  * Hewlett-Packard Company
00034  *
00035  * Permission to use, copy, modify, distribute and sell this software
00036  * and its documentation for any purpose is hereby granted without fee,
00037  * provided that the above copyright notice appear in all copies and
00038  * that both that copyright notice and this permission notice appear
00039  * in supporting documentation.  Hewlett-Packard Company makes no
00040  * representations about the suitability of this software for any
00041  * purpose.  It is provided "as is" without express or implied warranty.
00042  *
00043  *
00044  * Copyright (c) 1996-1998
00045  * Silicon Graphics Computer Systems, Inc.
00046  *
00047  * Permission to use, copy, modify, distribute and sell this software
00048  * and its documentation for any purpose is hereby granted without fee,
00049  * provided that the above copyright notice appear in all copies and
00050  * that both that copyright notice and this permission notice appear
00051  * in supporting documentation.  Silicon Graphics makes no
00052  * representations about the suitability of this software for any
00053  * purpose.  It is provided "as is" without express or implied warranty.
00054  */
00055 
00056 /* NOTE: This is an internal header file, included by other STL headers.
00057  *   You should not attempt to use it directly.
00058  */
00059 
00060 #ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
00061 #define __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
00062 
00063 // This file contains all of the general iterator-related utility
00064 // types, such as iterator_traits and struct iterator.
00065 // The internal file stl_iterator.h contains predefined iterators, 
00066 // such as front_insert_iterator and istream_iterator.
00067 
00068 #pragma GCC system_header
00069 
00070 #include <bits/std_cstddef.h>     // for ptrdiff_t
00071 
00072 
00073 namespace std
00074 {
00075 
00076 struct input_iterator_tag {};
00077 struct output_iterator_tag {};
00078 struct forward_iterator_tag : public input_iterator_tag {};
00079 struct bidirectional_iterator_tag : public forward_iterator_tag {};
00080 struct random_access_iterator_tag : public bidirectional_iterator_tag {};
00081 
00082 // The base classes input_iterator, output_iterator, forward_iterator,
00083 // bidirectional_iterator, and random_access_iterator are not part of
00084 // the C++ standard.  (They have been replaced by struct iterator.)
00085 // They are included for backward compatibility with the HP STL.
00086 
00087 template <class _Tp, class _Distance> struct input_iterator {
00088   typedef input_iterator_tag iterator_category;
00089   typedef _Tp                value_type;
00090   typedef _Distance          difference_type;
00091   typedef _Tp*               pointer;
00092   typedef _Tp&               reference;
00093 };
00094 
00095 struct output_iterator {
00096   typedef output_iterator_tag iterator_category;
00097   typedef void                value_type;
00098   typedef void                difference_type;
00099   typedef void                pointer;
00100   typedef void                reference;
00101 };
00102 
00103 template <class _Tp, class _Distance> struct forward_iterator {
00104   typedef forward_iterator_tag iterator_category;
00105   typedef _Tp                  value_type;
00106   typedef _Distance            difference_type;
00107   typedef _Tp*                 pointer;
00108   typedef _Tp&                 reference;
00109 };
00110 
00111 
00112 template <class _Tp, class _Distance> struct bidirectional_iterator {
00113   typedef bidirectional_iterator_tag iterator_category;
00114   typedef _Tp                        value_type;
00115   typedef _Distance                  difference_type;
00116   typedef _Tp*                       pointer;
00117   typedef _Tp&                       reference;
00118 };
00119 
00120 template <class _Tp, class _Distance> struct random_access_iterator {
00121   typedef random_access_iterator_tag iterator_category;
00122   typedef _Tp                        value_type;
00123   typedef _Distance                  difference_type;
00124   typedef _Tp*                       pointer;
00125   typedef _Tp&                       reference;
00126 };
00127 
00128 template <class _Category, class _Tp, class _Distance = ptrdiff_t,
00129           class _Pointer = _Tp*, class _Reference = _Tp&>
00130 struct iterator {
00131   typedef _Category  iterator_category;
00132   typedef _Tp        value_type;
00133   typedef _Distance  difference_type;
00134   typedef _Pointer   pointer;
00135   typedef _Reference reference;
00136 };
00137 
00138 template <class _Iterator>
00139 struct iterator_traits {
00140   typedef typename _Iterator::iterator_category iterator_category;
00141   typedef typename _Iterator::value_type        value_type;
00142   typedef typename _Iterator::difference_type   difference_type;
00143   typedef typename _Iterator::pointer           pointer;
00144   typedef typename _Iterator::reference         reference;
00145 };
00146 
00147 template <class _Tp>
00148 struct iterator_traits<_Tp*> {
00149   typedef random_access_iterator_tag iterator_category;
00150   typedef _Tp                         value_type;
00151   typedef ptrdiff_t                   difference_type;
00152   typedef _Tp*                        pointer;
00153   typedef _Tp&                        reference;
00154 };
00155 
00156 template <class _Tp>
00157 struct iterator_traits<const _Tp*> {
00158   typedef random_access_iterator_tag iterator_category;
00159   typedef _Tp                         value_type;
00160   typedef ptrdiff_t                   difference_type;
00161   typedef const _Tp*                  pointer;
00162   typedef const _Tp&                  reference;
00163 };
00164 
00165 // The overloaded functions iterator_category, distance_type, and
00166 // value_type are not part of the C++ standard.  (They have been
00167 // replaced by struct iterator_traits.)  They are included for
00168 // backward compatibility with the HP STL.
00169 
00170 // We introduce internal names for these functions.
00171 
00172 template <class _Iter>
00173 inline typename iterator_traits<_Iter>::iterator_category
00174 __iterator_category(const _Iter&)
00175 {
00176   typedef typename iterator_traits<_Iter>::iterator_category _Category;
00177   return _Category();
00178 }
00179 
00180 template <class _Iter>
00181 inline typename iterator_traits<_Iter>::difference_type*
00182 __distance_type(const _Iter&)
00183 {
00184   return static_cast<typename iterator_traits<_Iter>::difference_type*>(0);
00185 }
00186 
00187 template <class _Iter>
00188 inline typename iterator_traits<_Iter>::value_type*
00189 __value_type(const _Iter&)
00190 {
00191   return static_cast<typename iterator_traits<_Iter>::value_type*>(0);
00192 }
00193 
00194 template <class _Iter>
00195 inline typename iterator_traits<_Iter>::iterator_category
00196 iterator_category(const _Iter& __i) { return __iterator_category(__i); }
00197 
00198 
00199 template <class _Iter>
00200 inline typename iterator_traits<_Iter>::difference_type*
00201 distance_type(const _Iter& __i) { return __distance_type(__i); }
00202 
00203 template <class _Iter>
00204 inline typename iterator_traits<_Iter>::value_type*
00205 value_type(const _Iter& __i) { return __value_type(__i); }
00206 
00207 } // namespace std
00208 
00209 #endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H */
00210 
00211 
00212 // Local Variables:
00213 // mode:C++
00214 // End:

Generated on Mon Apr 8 03:11:41 2002 for libstdc++-v3 Source by doxygen1.2.15