home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / iterator.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  4.8 KB  |  140 lines

  1. #ifndef __ITERATOR_CC
  2. #define __ITERATOR_CC
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. /***************************************************************************
  5.  *
  6.  * iterator.cc - Non-inline definitions for the Standard Library iterators
  7.  *
  8.  * $Id:
  9.  *
  10.  ***************************************************************************
  11.  *
  12.  * Copyright (c) 1994
  13.  * Hewlett-Packard Company
  14.  *
  15.  * Permission to use, copy, modify, distribute and sell this software
  16.  * and its documentation for any purpose is hereby granted without fee,
  17.  * provided that the above copyright notice appear in all copies and
  18.  * that both that copyright notice and this permission notice appear
  19.  * in supporting documentation.  Hewlett-Packard Company makes no
  20.  * representations about the suitability of this software for any
  21.  * purpose.  It is provided "as is" without express or implied warranty.
  22.  *
  23.  *
  24.  ***************************************************************************
  25.  *
  26.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  27.  *
  28.  * This computer software is owned by Rogue Wave Software, Inc. and is
  29.  * protected by U.S. copyright laws and other laws and by international
  30.  * treaties.  This computer software is furnished by Rogue Wave Software,
  31.  * Inc. pursuant to a written license agreement and may be used, copied,
  32.  * transmitted, and stored only in accordance with the terms of such
  33.  * license and with the inclusion of the above copyright notice.  This
  34.  * computer software or any other copies thereof may not be provided or
  35.  * otherwise made available to any other person.
  36.  *
  37.  * U.S. Government Restricted Rights.  This computer software is provided
  38.  * with Restricted Rights.  Use, duplication, or disclosure by the
  39.  * Government is subject to restrictions as set forth in subparagraph (c)
  40.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  41.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  42.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  43.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  44.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  45.  *
  46.  **************************************************************************/
  47. #include <stdcomp.h>
  48.  
  49. #ifndef _RWSTD_NO_NAMESPACE
  50. namespace std {
  51. #endif
  52.  
  53.   template <class InputIterator, class Distance>
  54.   void __distance (InputIterator first, InputIterator last, Distance& n, 
  55.                    input_iterator_tag)
  56.   {
  57.     while (first != last) { ++first; ++n; }
  58.   }
  59.  
  60.   template <class ForwardIterator, class Distance>
  61.   void __distance (ForwardIterator first, ForwardIterator last, Distance& n, 
  62.                    forward_iterator_tag)
  63.   {
  64.     while (first != last) { ++first; ++n; }
  65.   }
  66.  
  67.   template <class BidirectionalIterator, class Distance>
  68.   void __distance (BidirectionalIterator first, BidirectionalIterator last, 
  69.                    Distance& n, bidirectional_iterator_tag)
  70.   {
  71.     while (first != last) { ++first; ++n; }
  72.   }
  73. #ifdef _RWSTD_NO_BASE_CLASS_MATCH
  74. //
  75. // We include assert() to test for possible problem in advance().
  76. // Furthermore, we FORCE assert() to always expand.
  77. //
  78. #ifdef  NDEBUG
  79. #define __RW_NDEBUG
  80. #undef  NDEBUG
  81. #endif
  82. #ifndef _RWSTD_NO_NEW_HEADER
  83. #include <cassert>
  84. #else
  85. #include <assert.h>
  86. #endif
  87.  
  88. #endif /*_RWSTD_NO_BASE_CLASS_MATCH*/
  89.   template <class InputIterator, class Distance>
  90.   void __advance (InputIterator& i, Distance n, input_iterator_tag)
  91.   {
  92. #ifdef _RWSTD_NO_BASE_CLASS_MATCH
  93.     //
  94.     // All uses of advance() end up calling this template, even
  95.     // when advance() is being invoked on a bidirectional or random
  96.     // iterator.  We need to check that n is non-negative, or else
  97.     // this algorithm will fail horribly.  We MUST document the
  98.     // restriction that advance() only be called with non-negative
  99.     // Distance.  There don't appear to be any _EXPLICIT uses of advance()
  100.     // with a negative Distance argument in the STL library itself.
  101.     //
  102.     // This assert() is ALWAYS on -- see how it's included'd above.
  103.     //
  104.     assert(n >= 0);
  105. #endif /*_RWSTD_NO_BASE_CLASS_MATCH*/
  106.     while (n--) ++i;
  107.   }
  108.  
  109. //
  110. // Don't forget to turn off expansion of assert() if that's what the
  111. // user expects.
  112. //
  113. #ifdef  __RW_NDEBUG
  114. #define NDEBUG
  115. #undef  __RW_NDEBUG
  116. #endif
  117.  
  118.   template <class ForwardIterator, class Distance>
  119.   void __advance (ForwardIterator& i, Distance n, forward_iterator_tag)
  120.   {
  121.     while (n--) ++i;
  122.   }
  123.  
  124.   template <class BidirectionalIterator, class Distance>
  125.   void __advance (BidirectionalIterator& i, Distance n, 
  126.                   bidirectional_iterator_tag)
  127.   {
  128.     if (n >= 1)
  129.       while (n--) ++i;
  130.     else
  131.       while (n++) --i;
  132.   }
  133.  
  134. #ifndef _RWSTD_NO_NAMESPACE
  135. }
  136. #endif
  137.  
  138. #pragma option pop
  139. #endif /* __ITERATOR_CC */
  140.