197403Sobrien// HP/SGI iterator extensions -*- C++ -*-
297403Sobrien
3169691Skan// Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
497403Sobrien//
597403Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
697403Sobrien// software; you can redistribute it and/or modify it under the
797403Sobrien// terms of the GNU General Public License as published by the
897403Sobrien// Free Software Foundation; either version 2, or (at your option)
997403Sobrien// any later version.
1097403Sobrien
1197403Sobrien// This library is distributed in the hope that it will be useful,
1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1497403Sobrien// GNU General Public License for more details.
1597403Sobrien
1697403Sobrien// You should have received a copy of the GNU General Public License along
1797403Sobrien// with this library; see the file COPYING.  If not, write to the Free
18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
1997403Sobrien// USA.
2097403Sobrien
2197403Sobrien// As a special exception, you may use this file as part of a free software
2297403Sobrien// library without restriction.  Specifically, if other files instantiate
2397403Sobrien// templates or use macros or inline functions from this file, or you compile
2497403Sobrien// this file and link it with other files to produce an executable, this
2597403Sobrien// file does not by itself cause the resulting executable to be covered by
2697403Sobrien// the GNU General Public License.  This exception does not however
2797403Sobrien// invalidate any other reasons why the executable file might be covered by
2897403Sobrien// the GNU General Public License.
2997403Sobrien
3097403Sobrien/*
3197403Sobrien *
3297403Sobrien * Copyright (c) 1994
3397403Sobrien * Hewlett-Packard Company
3497403Sobrien *
3597403Sobrien * Permission to use, copy, modify, distribute and sell this software
3697403Sobrien * and its documentation for any purpose is hereby granted without fee,
3797403Sobrien * provided that the above copyright notice appear in all copies and
3897403Sobrien * that both that copyright notice and this permission notice appear
3997403Sobrien * in supporting documentation.  Hewlett-Packard Company makes no
4097403Sobrien * representations about the suitability of this software for any
4197403Sobrien * purpose.  It is provided "as is" without express or implied warranty.
4297403Sobrien *
4397403Sobrien *
4497403Sobrien * Copyright (c) 1996-1998
4597403Sobrien * Silicon Graphics Computer Systems, Inc.
4697403Sobrien *
4797403Sobrien * Permission to use, copy, modify, distribute and sell this software
4897403Sobrien * and its documentation for any purpose is hereby granted without fee,
4997403Sobrien * provided that the above copyright notice appear in all copies and
5097403Sobrien * that both that copyright notice and this permission notice appear
5197403Sobrien * in supporting documentation.  Silicon Graphics makes no
5297403Sobrien * representations about the suitability of this software for any
5397403Sobrien * purpose.  It is provided "as is" without express or implied warranty.
5497403Sobrien */
5597403Sobrien
5697403Sobrien/** @file ext/iterator
5797403Sobrien *  This file is a GNU extension to the Standard C++ Library (possibly
58169691Skan *  containing extensions from the HP/SGI STL subset).
5997403Sobrien */
6097403Sobrien
6197403Sobrien#ifndef _EXT_ITERATOR
62132720Skan#define _EXT_ITERATOR 1
6397403Sobrien
6497403Sobrien#pragma GCC system_header
65132720Skan
6697403Sobrien#include <bits/concept_check.h>
6797403Sobrien#include <iterator>
6897403Sobrien
69169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
70169691Skan
71132720Skan  // There are two signatures for distance.  In addition to the one
72132720Skan  // taking two iterators and returning a result, there is another
73132720Skan  // taking two iterators and a reference-to-result variable, and
74132720Skan  // returning nothing.  The latter seems to be an SGI extension.
75132720Skan  // -- pedwards
7697403Sobrien  template<typename _InputIterator, typename _Distance>
7797403Sobrien    inline void
7897403Sobrien    __distance(_InputIterator __first, _InputIterator __last,
7997403Sobrien	       _Distance& __n, std::input_iterator_tag)
8097403Sobrien    {
8197403Sobrien      // concept requirements
82132720Skan      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
83169691Skan      while (__first != __last)
84169691Skan	{
85169691Skan	  ++__first;
86169691Skan	  ++__n;
87169691Skan	}
8897403Sobrien    }
8997403Sobrien
9097403Sobrien  template<typename _RandomAccessIterator, typename _Distance>
9197403Sobrien    inline void
92132720Skan    __distance(_RandomAccessIterator __first, _RandomAccessIterator __last,
9397403Sobrien	       _Distance& __n, std::random_access_iterator_tag)
9497403Sobrien    {
9597403Sobrien      // concept requirements
96169691Skan      __glibcxx_function_requires(_RandomAccessIteratorConcept<
97169691Skan				  _RandomAccessIterator>)
9897403Sobrien      __n += __last - __first;
9997403Sobrien    }
10097403Sobrien
101102782Skan  /**
102102782Skan   *  This is an SGI extension.
103102782Skan   *  @ingroup SGIextensions
104102782Skan   *  @doctodo
105102782Skan  */
10697403Sobrien  template<typename _InputIterator, typename _Distance>
10797403Sobrien    inline void
10897403Sobrien    distance(_InputIterator __first, _InputIterator __last,
10997403Sobrien             _Distance& __n)
11097403Sobrien    {
11197403Sobrien      // concept requirements -- taken care of in __distance
11297403Sobrien      __distance(__first, __last, __n, std::__iterator_category(__first));
11397403Sobrien    }
11497403Sobrien
115169691Skan_GLIBCXX_END_NAMESPACE
116169691Skan
117132720Skan#endif
11897403Sobrien
119