// iterator standard header
#ifndef _ITERATOR_
#define _ITERATOR_

#pragma info(none)
#ifndef __CHKHDR__
#  pragma report(level, E)
#endif
#pragma info(restore)

#if __IBMCPP__ < 400
#error This file to be used only with IBM VisualAge C++ v4 and later compilers.
#endif /* __IBMCPP__ */

#pragma namemangling(ansi)

   /********************************************************************/
   /*  <iterator> header file                                          */
   /*                                                                  */
   /*  VisualAge C++, Version 4.0                                      */
   /*    Licensed Material - Property of IBM                           */
   /*                                                                  */
   /*  5801-AAR and Other Materials                                    */
   /*                                                                  */
   /*  (c) Copyright IBM Corp 1991, 1998. All rights reserved.         */
   /*                                                                  */
   /*                                                                  */
   /*  Licensed Materials.                                             */
   /*                                                                  */
   /*  Dinkum C++ Library                                              */
   /*  Copyright (c) 1998.  Licensed to IBM Corp. and its suppliers.   */
   /*                                                                  */
   /********************************************************************/

#include <xutility>
_STD_BEGIN
		// TEMPLATE CLASS back_insert_iterator
template<class _C>
	class back_insert_iterator
		: public _Outit {
public:
	typedef _C container_type;
	typedef typename _C::reference reference;
	typedef typename _C::value_type value_type;
	explicit back_insert_iterator(_C& _X)
		: container(&_X) {}
	back_insert_iterator<_C>& operator=(
		typename _C::const_reference _V)
		{container->push_back(_V);
		return (*this); }
	back_insert_iterator<_C>& operator*()
		{return (*this); }
	back_insert_iterator<_C>& operator++()
		{return (*this); }
	back_insert_iterator<_C> operator++(int)
		{return (*this); }
protected:
	_C *container;
	};
template<class _C> inline
	back_insert_iterator<_C> back_inserter(_C& _X)
	{return (back_insert_iterator<_C>(_X)); }
		// TEMPLATE CLASS front_insert_iterator
template<class _C>
	class front_insert_iterator
		: public _Outit {
public:
	typedef _C container_type;
	typedef typename _C::reference reference;
	typedef typename _C::value_type value_type;
	explicit front_insert_iterator(_C& _X)
		: container(&_X) {}
	front_insert_iterator<_C>& operator=(
		typename _C::const_reference _V)
		{container->push_front(_V);
		return (*this); }
	front_insert_iterator<_C>& operator*()
		{return (*this); }
	front_insert_iterator<_C>& operator++()
		{return (*this); }
	front_insert_iterator<_C> operator++(int)
		{return (*this); }
protected:
	_C *container;
	};
template<class _C> inline
	front_insert_iterator<_C> front_inserter(_C& _X)
	{return (front_insert_iterator<_C>(_X)); }
		// TEMPLATE CLASS insert_iterator
template<class _C>
	class insert_iterator
		: public _Outit {
public:
	typedef _C container_type;
	typedef typename _C::reference reference;
	typedef typename _C::value_type value_type;
	insert_iterator(_C& _X, typename _C::iterator _I)
		: container(&_X), iter(_I) {}
	insert_iterator<_C>& operator=(
		typename _C::const_reference _V)
		{iter = container->insert(iter, _V);
		++iter;
		return (*this); }
	insert_iterator<_C>& operator*()
		{return (*this); }
	insert_iterator<_C>& operator++()
		{return (*this); }
	insert_iterator<_C>& operator++(int)
		{return (*this); }
protected:
	_C *container;
	typename _C::iterator iter;
	};
template<class _C, class _XI> inline
	insert_iterator<_C> inserter(_C& _X, _XI _I)
	{return (insert_iterator<_C>(_X, _C::iterator(_I))); }
		// TEMPLATE CLASS istream_iterator
template<class _Ty, class _E _TDEF(char),
	class _Tr _TDEF(char_traits<_E>),
	class _Dist _TDEF(ptrdiff_t)>
	class istream_iterator
		: public iterator<input_iterator_tag, _Ty, _Dist,
			_Ty *, _Ty&> {
public:
	typedef istream_iterator<_Ty, _E, _Tr, _Dist> _Myt;
	typedef _E char_type;
	typedef _Tr traits_type;
	typedef basic_istream<_E, _Tr> istream_type;
	istream_iterator()
		: _Istr(0) {}
	istream_iterator(istream_type& _I)
		: _Istr(&_I) {_Getval(); }
	const _Ty& operator*() const
		{return (_Val); }
	const _Ty *operator->() const
		{return (&**this); }
	_Myt& operator++()
		{_Getval();
		return (*this); }
	_Myt operator++(int)
		{_Myt _Tmp = *this;
		_Getval();
		return (_Tmp); }
	bool _Equal(const _Myt& _X) const
		{return (_Istr == _X._Istr); }
protected:
	void _Getval()
		{if (_Istr != 0 && !(*_Istr >> _Val))
			_Istr = 0; }
	istream_type *_Istr;
	_Ty _Val;
	};
template<class _Ty, class _E, class _Tr, class _Dist> inline
	bool operator==(
		const istream_iterator<_Ty, _E, _Tr, _Dist>& _X,
		const istream_iterator<_Ty, _E, _Tr, _Dist>& _Y)
	{return (_X._Equal(_Y)); }
template<class _Ty, class _E, class _Tr, class _Dist> inline
	bool operator!=(
		const istream_iterator<_Ty, _E, _Tr, _Dist>& _X,
		const istream_iterator<_Ty, _E, _Tr, _Dist>& _Y)
	{return (!(_X == _Y)); }
		// TEMPLATE CLASS ostream_iterator
template<class _Ty, class _E _TDEF(char),
	class _Tr _TDEF(char_traits<_E>) >
	class ostream_iterator
		: public _Outit {
public:
	typedef _Ty value_type;
	typedef _E char_type;
	typedef _Tr traits_type;
	typedef basic_ostream<_E, _Tr> ostream_type;
	ostream_iterator(ostream_type& _O,
		const _E *_D = 0)
		: _Ostr(&_O), _Delim(_D) {}
	ostream_iterator<_Ty, _E, _Tr>& operator=(const _Ty& _X)
		{*_Ostr << _X;
		if (_Delim != 0)
			*_Ostr << _Delim;
		return (*this); }
	ostream_iterator<_Ty, _E, _Tr>& operator*()
		{return (*this); }
	ostream_iterator<_Ty, _E, _Tr>& operator++()
		{return (*this); }
	ostream_iterator<_Ty, _E, _Tr> operator++(int)
		{return (*this); }
protected:
	const _E *_Delim;
	ostream_type *_Ostr;
	};
		// TEMPLATE FUNCTION _Val_type
template<class _It> inline
	typename iterator_traits<_It>::value_type *_Val_type(_It)
	{return (0); }
		// TEMPLATE FUNCTION advance
template<class _II, class _D> inline
	void advance(_II& _I, _D _N)
	{_Advance(_I, _N, _Iter_cat(_I)); }
template<class _II, class _D> inline
	void _Advance(_II& _I, _D _N, input_iterator_tag)
	{for (; 0 < _N; --_N)
		++_I; }
template<class _FI, class _D> inline
	void _Advance(_FI& _I, _D _N, forward_iterator_tag)
	{for (; 0 < _N; --_N)
		++_I; }
template<class _BI, class _D> inline
	void _Advance(_BI& _I, _D _N, bidirectional_iterator_tag)
	{for (; 0 < _N; --_N)
		++_I;
	for (; _N < 0; ++_N)
		--_I; }
template<class _RI, class _D> inline
	void _Advance(_RI& _I, _D _N, random_access_iterator_tag)
	{_I += _N; }
		// TEMPLATE FUNCTION _Dist_type
template<class _It> inline
	typename iterator_traits<_It>::difference_type *_Dist_type(_It)
	{return (0); }
_STD_END

#pragma namemangling()

#pragma info(none)
#ifndef __CHKHDR__
#  pragma report(pop)
#endif
#pragma info(restore)

#endif /* _ITERATOR_ */

/*
 * Copyright (c) 1995 by P.J. Plauger.  ALL RIGHTS RESERVED. 
 * Consult your license regarding permissions and restrictions.
 */

/*
 * This file is derived from software bearing the following
 * restrictions:
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this
 * software and its documentation for any purpose is hereby
 * granted without fee, provided that the above copyright notice
 * appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation.
 * Hewlett-Packard Company makes no representations about the
 * suitability of this software for any purpose. It is provided
 * "as is" without express or implied warranty.
V2.2:0081 */
