LCOV - code coverage report
Current view: directory - tools/gcc-4.5/include/c++/4.5.2/bits - stl_iterator_base_types.h (source / functions) Found Hit Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2012-06-02 Functions: 46 9 19.6 %

       1                 : // Types used in iterator implementation -*- C++ -*-
       2                 : 
       3                 : // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
       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 3, or (at your option)
      10                 : // any later version.
      11                 : 
      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.
      16                 : 
      17                 : // Under Section 7 of GPL version 3, you are granted additional
      18                 : // permissions described in the GCC Runtime Library Exception, version
      19                 : // 3.1, as published by the Free Software Foundation.
      20                 : 
      21                 : // You should have received a copy of the GNU General Public License and
      22                 : // a copy of the GCC Runtime Library Exception along with this program;
      23                 : // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
      24                 : // <http://www.gnu.org/licenses/>.
      25                 : 
      26                 : /*
      27                 :  *
      28                 :  * Copyright (c) 1994
      29                 :  * Hewlett-Packard Company
      30                 :  *
      31                 :  * Permission to use, copy, modify, distribute and sell this software
      32                 :  * and its documentation for any purpose is hereby granted without fee,
      33                 :  * provided that the above copyright notice appear in all copies and
      34                 :  * that both that copyright notice and this permission notice appear
      35                 :  * in supporting documentation.  Hewlett-Packard Company makes no
      36                 :  * representations about the suitability of this software for any
      37                 :  * purpose.  It is provided "as is" without express or implied warranty.
      38                 :  *
      39                 :  *
      40                 :  * Copyright (c) 1996-1998
      41                 :  * Silicon Graphics Computer Systems, Inc.
      42                 :  *
      43                 :  * Permission to use, copy, modify, distribute and sell this software
      44                 :  * and its documentation for any purpose is hereby granted without fee,
      45                 :  * provided that the above copyright notice appear in all copies and
      46                 :  * that both that copyright notice and this permission notice appear
      47                 :  * in supporting documentation.  Silicon Graphics makes no
      48                 :  * representations about the suitability of this software for any
      49                 :  * purpose.  It is provided "as is" without express or implied warranty.
      50                 :  */
      51                 : 
      52                 : /** @file stl_iterator_base_types.h
      53                 :  *  This is an internal header file, included by other library headers.
      54                 :  *  You should not attempt to use it directly.
      55                 :  *
      56                 :  *  This file contains all of the general iterator-related utility types,
      57                 :  *  such as iterator_traits and struct iterator.
      58                 :  */
      59                 : 
      60                 : #ifndef _STL_ITERATOR_BASE_TYPES_H
      61                 : #define _STL_ITERATOR_BASE_TYPES_H 1
      62                 : 
      63                 : #pragma GCC system_header
      64                 : 
      65                 : #include <bits/c++config.h>
      66                 : #include <cstddef>
      67                 : 
      68                 : _GLIBCXX_BEGIN_NAMESPACE(std)
      69                 : 
      70                 :   /**
      71                 :    *  @defgroup iterators Iterators
      72                 :    *  Abstractions for uniform iterating through various underlying types.
      73                 :   */
      74                 :   //@{ 
      75                 : 
      76                 :   /**
      77                 :    *  @defgroup iterator_tags Iterator Tags
      78                 :    *  These are empty types, used to distinguish different iterators.  The
      79                 :    *  distinction is not made by what they contain, but simply by what they
      80                 :    *  are.  Different underlying algorithms can then be used based on the
      81                 :    *  different operations supported by different iterator types.
      82                 :   */
      83                 :   //@{ 
      84                 :   ///  Marking input iterators.
      85                 :   struct input_iterator_tag { };
      86                 : 
      87                 :   ///  Marking output iterators.
      88                 :   struct output_iterator_tag { };
      89                 : 
      90                 :   /// Forward iterators support a superset of input iterator operations.
      91                 :   struct forward_iterator_tag : public input_iterator_tag { };
      92                 : 
      93                 :   /// Bidirectional iterators support a superset of forward iterator
      94                 :   /// operations.
      95                 :   struct bidirectional_iterator_tag : public forward_iterator_tag { };
      96                 : 
      97                 :   /// Random-access iterators support a superset of bidirectional
      98                 :   /// iterator operations.
      99                 :   struct random_access_iterator_tag : public bidirectional_iterator_tag { };
     100                 :   //@}
     101                 : 
     102                 :   /**
     103                 :    *  @brief  Common %iterator class.
     104                 :    *
     105                 :    *  This class does nothing but define nested typedefs.  %Iterator classes
     106                 :    *  can inherit from this class to save some work.  The typedefs are then
     107                 :    *  used in specializations and overloading.
     108                 :    *
     109                 :    *  In particular, there are no default implementations of requirements
     110                 :    *  such as @c operator++ and the like.  (How could there be?)
     111                 :   */
     112                 :   template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t,
     113                 :            typename _Pointer = _Tp*, typename _Reference = _Tp&>
     114                 :     struct iterator
     115             389 :     {
     116                 :       /// One of the @link iterator_tags tag types@endlink.
     117                 :       typedef _Category  iterator_category;
     118                 :       /// The type "pointed to" by the iterator.
     119                 :       typedef _Tp        value_type;
     120                 :       /// Distance between iterators is represented as this type.
     121                 :       typedef _Distance  difference_type;
     122                 :       /// This type represents a pointer-to-value_type.
     123                 :       typedef _Pointer   pointer;
     124                 :       /// This type represents a reference-to-value_type.
     125                 :       typedef _Reference reference;
     126                 :     };
     127                 : 
     128                 :   /**
     129                 :    *  @brief  Traits class for iterators.
     130                 :    *
     131                 :    *  This class does nothing but define nested typedefs.  The general
     132                 :    *  version simply @a forwards the nested typedefs from the Iterator
     133                 :    *  argument.  Specialized versions for pointers and pointers-to-const
     134                 :    *  provide tighter, more correct semantics.
     135                 :   */
     136                 :   template<typename _Iterator>
     137                 :     struct iterator_traits
     138                 :     {
     139                 :       typedef typename _Iterator::iterator_category iterator_category;
     140                 :       typedef typename _Iterator::value_type        value_type;
     141                 :       typedef typename _Iterator::difference_type   difference_type;
     142                 :       typedef typename _Iterator::pointer           pointer;
     143                 :       typedef typename _Iterator::reference         reference;
     144                 :     };
     145                 : 
     146                 :   /// Partial specialization for pointer types.
     147                 :   template<typename _Tp>
     148                 :     struct iterator_traits<_Tp*>
     149                 :     {
     150                 :       typedef random_access_iterator_tag iterator_category;
     151                 :       typedef _Tp                         value_type;
     152                 :       typedef ptrdiff_t                   difference_type;
     153                 :       typedef _Tp*                        pointer;
     154                 :       typedef _Tp&                        reference;
     155                 :     };
     156                 : 
     157                 :   /// Partial specialization for const pointer types.
     158                 :   template<typename _Tp>
     159                 :     struct iterator_traits<const _Tp*>
     160                 :     {
     161                 :       typedef random_access_iterator_tag iterator_category;
     162                 :       typedef _Tp                         value_type;
     163                 :       typedef ptrdiff_t                   difference_type;
     164                 :       typedef const _Tp*                  pointer;
     165                 :       typedef const _Tp&                  reference;
     166                 :     };
     167                 : 
     168                 :   /**
     169                 :    *  This function is not a part of the C++ standard but is syntactic
     170                 :    *  sugar for internal library use only.
     171                 :   */
     172                 :   template<typename _Iter>
     173                 :     inline typename iterator_traits<_Iter>::iterator_category
     174            1714 :     __iterator_category(const _Iter&)
     175            1714 :     { return typename iterator_traits<_Iter>::iterator_category(); }
     176                 : 
     177                 :   //@}
     178                 : 
     179                 : _GLIBCXX_END_NAMESPACE
     180                 : 
     181                 : #endif /* _STL_ITERATOR_BASE_TYPES_H */
     182                 : 

Generated by: LCOV version 1.7