// stack standard header
#pragma once
#ifndef _STACK_
#define _STACK_
#ifndef RC_INVOKED
#include <deque>

 #pragma pack(push,_CRT_PACKING)
 #pragma warning(push,3)
_STD_BEGIN
		// TEMPLATE CLASS stack
template<class _Ty,
	class _Container = deque<_Ty> >
	class stack
	{	// LIFO queue implemented with a container
public:
	typedef stack<_Ty, _Container> _Myt;
	typedef _Container container_type;
	typedef typename _Container::value_type value_type;
	typedef typename _Container::size_type size_type;
	typedef typename _Container::reference reference;
	typedef typename _Container::const_reference const_reference;

	stack()
		: c()
		{	// construct with empty container
		}

	stack(const _Myt& _Right)
		: c(_Right.c)
		{	// construct by copying _Right
		}

	explicit stack(const _Container& _Cont)
		: c(_Cont)
		{	// construct by copying specified container
		}

	_Myt& operator=(const _Myt& _Right)
		{	// assign by copying _Right
		c = _Right.c;
		return (*this);
		}

	stack(_Myt&& _Right)
		: c(_STD move(_Right.c))
		{	// construct by moving _Right
		}

	explicit stack(_Container&& _Cont)
		: c(_STD move(_Cont))
		{	// construct by copying specified container
		}

	_Myt& operator=(_Myt&& _Right)
		{	// assign by moving _Right
		c = _STD move(_Right.c);
		return (*this);
		}

	void push(value_type&& _Val)
		{	// insert element at beginning
		c.push_back(_STD move(_Val));
		}

	template<class _Valty>
		void emplace(_Valty&& _Val)
		{	// insert element at beginning
		c.emplace_back(_STD forward<_Valty>(_Val));
		}

	void swap(_Myt&& _Right)
		{	// exchange contents with movable _Right
		c.swap(_STD move(_Right.c));
		}

	bool empty() const
		{	// test if stack is empty
		return (c.empty());
		}

	size_type size() const
		{	// test length of stack
		return (c.size());
		}

	reference top()
		{	// return last element of mutable stack
		return (c.back());
		}

	const_reference top() const
		{	// return last element of nonmutable stack
		return (c.back());
		}

	void push(const value_type& _Val)
		{	// insert element at end
		c.push_back(_Val);
		}

	void pop()
		{	// erase last element
		c.pop_back();
		}

	const _Container& _Get_container() const
		{	// get reference to container
		return (c);
		}

	void swap(_Myt& _Right)
		{	// exchange contents with _Right
		c.swap(_Right.c);
		}

protected:
	_Container c;	// the underlying container
	};

		// stack TEMPLATE FUNCTIONS
template<class _Ty,
	class _Container> inline
	void swap(stack<_Ty, _Container>& _Left,
		stack<_Ty, _Container>& _Right)
	{	// swap _Left and _Right stacks
	_Left.swap(_Right);
	}

template<class _Ty,
	class _Container> inline
	void swap(stack<_Ty, _Container>& _Left,
		stack<_Ty, _Container>&& _Right)
	{	// swap _Left and _Right stacks
	typedef stack<_Ty, _Container> _Myt;
	_Left.swap(_STD forward<_Myt>(_Right));
	}

template<class _Ty,
	class _Container> inline
	void swap(stack<_Ty, _Container>&& _Left,
		stack<_Ty, _Container>& _Right)
	{	// swap _Left and _Right stacks
	typedef stack<_Ty, _Container> _Myt;
	_Right.swap(_STD forward<_Myt>(_Left));
	}

template<class _Ty,
	class _Container> inline
	bool operator==(const stack<_Ty, _Container>& _Left,
		const stack<_Ty, _Container>& _Right)
	{	// test for stack equality
	return (_Left._Get_container() == _Right._Get_container());
	}

template<class _Ty,
	class _Container> inline
	bool operator!=(const stack<_Ty, _Container>& _Left,
		const stack<_Ty, _Container>& _Right)
	{	// test for stack inequality
	return (!(_Left == _Right));
	}

template<class _Ty,
	class _Container> inline
	bool operator<(const stack<_Ty, _Container>& _Left,
		const stack<_Ty, _Container>& _Right)
	{	// test if _Left < _Right for stacks
	return (_Left._Get_container() < _Right._Get_container());
	}

template<class _Ty,
	class _Container> inline
	bool operator>(const stack<_Ty, _Container>& _Left,
		const stack<_Ty, _Container>& _Right)
	{	// test if _Left > _Right for stacks
	return (_Right < _Left);
	}

template<class _Ty,
	class _Container> inline
	bool operator<=(const stack<_Ty, _Container>& _Left,
		const stack<_Ty, _Container>& _Right)
	{	// test if _Left <= _Right for stacks
	return (!(_Right < _Left));
	}

template<class _Ty,
	class _Container> inline
	bool operator>=(const stack<_Ty, _Container>& _Left,
		const stack<_Ty, _Container>& _Right)
	{	// test if _Left >= _Right for stacks
	return (!(_Left < _Right));
	}
_STD_END
 #pragma warning(pop)
 #pragma pack(pop)

#endif /* RC_INVOKED */
#endif /* _STACK_ */

/*
 * 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.
 */

/*
 * Copyright (c) 1992-2009 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V5.20:0009 */
