Whole document tree
    

Whole document tree

stl_stack.h Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

stl_stack.h

Go to the documentation of this file.
00001 // Stack implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 /*
00031  *
00032  * Copyright (c) 1994
00033  * Hewlett-Packard Company
00034  *
00035  * Permission to use, copy, modify, distribute and sell this software
00036  * and its documentation for any purpose is hereby granted without fee,
00037  * provided that the above copyright notice appear in all copies and
00038  * that both that copyright notice and this permission notice appear
00039  * in supporting documentation.  Hewlett-Packard Company makes no
00040  * representations about the suitability of this software for any
00041  * purpose.  It is provided "as is" without express or implied warranty.
00042  *
00043  *
00044  * Copyright (c) 1996,1997
00045  * Silicon Graphics Computer Systems, Inc.
00046  *
00047  * Permission to use, copy, modify, distribute and sell this software
00048  * and its documentation for any purpose is hereby granted without fee,
00049  * provided that the above copyright notice appear in all copies and
00050  * that both that copyright notice and this permission notice appear
00051  * in supporting documentation.  Silicon Graphics makes no
00052  * representations about the suitability of this software for any
00053  * purpose.  It is provided "as is" without express or implied warranty.
00054  */
00055 
00056 /* NOTE: This is an internal header file, included by other STL headers.
00057  *   You should not attempt to use it directly.
00058  */
00059 
00060 #ifndef __SGI_STL_INTERNAL_STACK_H
00061 #define __SGI_STL_INTERNAL_STACK_H
00062 
00063 #include <bits/concept_check.h>
00064 
00065 namespace std
00066 {
00067 
00068 // Forward declarations of operators == and <, needed for friend declaration.
00069 
00070 template <class _Tp, 
00071           class _Sequence = deque<_Tp> >
00072 class stack;
00073 
00074 template <class _Tp, class _Seq>
00075 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
00076 
00077 template <class _Tp, class _Seq>
00078 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
00079 
00080 
00081 template <class _Tp, class _Sequence>
00082 class stack
00083 {
00084   // concept requirements
00085   __glibcpp_class_requires(_Tp, _SGIAssignableConcept);
00086   __glibcpp_class_requires(_Sequence, _BackInsertionSequenceConcept);
00087   typedef typename _Sequence::value_type _Sequence_value_type;
00088   __glibcpp_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept);
00089 
00090   template <class _Tp1, class _Seq1>
00091   friend bool operator== (const stack<_Tp1, _Seq1>&,
00092                           const stack<_Tp1, _Seq1>&);
00093   template <class _Tp1, class _Seq1>
00094   friend bool operator< (const stack<_Tp1, _Seq1>&,
00095                          const stack<_Tp1, _Seq1>&);
00096 public:
00097   typedef typename _Sequence::value_type      value_type;
00098   typedef typename _Sequence::size_type       size_type;
00099   typedef          _Sequence                  container_type;
00100 
00101   typedef typename _Sequence::reference       reference;
00102   typedef typename _Sequence::const_reference const_reference;
00103 protected:
00104   _Sequence c;
00105 public:
00106   stack() : c() {}
00107   explicit stack(const _Sequence& __s) : c(__s) {}
00108 
00109   bool empty() const { return c.empty(); }
00110   size_type size() const { return c.size(); }
00111   reference top() { return c.back(); }
00112   const_reference top() const { return c.back(); }
00113   void push(const value_type& __x) { c.push_back(__x); }
00114   void pop() { c.pop_back(); }
00115 };
00116 
00117 template <class _Tp, class _Seq>
00118 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00119 {
00120   return __x.c == __y.c;
00121 }
00122 
00123 template <class _Tp, class _Seq>
00124 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00125 {
00126   return __x.c < __y.c;
00127 }
00128 
00129 template <class _Tp, class _Seq>
00130 bool operator!=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00131 {
00132   return !(__x == __y);
00133 }
00134 
00135 template <class _Tp, class _Seq>
00136 bool operator>(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00137 {
00138   return __y < __x;
00139 }
00140 
00141 template <class _Tp, class _Seq>
00142 bool operator<=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00143 {
00144   return !(__y < __x);
00145 }
00146 
00147 template <class _Tp, class _Seq>
00148 bool operator>=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00149 {
00150   return !(__x < __y);
00151 }
00152 
00153 } // namespace std
00154 
00155 #endif /* __SGI_STL_INTERNAL_STACK_H */
00156 
00157 // Local Variables:
00158 // mode:C++
00159 // End:

Generated on Mon Apr 8 03:11:44 2002 for libstdc++-v3 Source by doxygen1.2.15