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 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  *
00015  * Copyright (c) 1996,1997
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */
00026 
00027 /* NOTE: This is an internal header file, included by other STL headers.
00028  *   You should not attempt to use it directly.
00029  */
00030 
00031 #ifndef __SGI_STL_INTERNAL_STACK_H
00032 #define __SGI_STL_INTERNAL_STACK_H
00033 
00034 #include <bits/concept_check.h>
00035 
00036 namespace std
00037 {
00038 
00039 // Forward declarations of operators == and <, needed for friend declaration.
00040 
00041 template <class _Tp, 
00042           class _Sequence = deque<_Tp> >
00043 class stack;
00044 
00045 template <class _Tp, class _Seq>
00046 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
00047 
00048 template <class _Tp, class _Seq>
00049 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
00050 
00051 
00052 template <class _Tp, class _Sequence>
00053 class stack
00054 {
00055   // concept requirements
00056   __glibcpp_class_requires(_Tp, _SGIAssignableConcept);
00057   __glibcpp_class_requires(_Sequence, _BackInsertionSequenceConcept);
00058   typedef typename _Sequence::value_type _Sequence_value_type;
00059   __glibcpp_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept);
00060 
00061   template <class _Tp1, class _Seq1>
00062   friend bool operator== (const stack<_Tp1, _Seq1>&,
00063                           const stack<_Tp1, _Seq1>&);
00064   template <class _Tp1, class _Seq1>
00065   friend bool operator< (const stack<_Tp1, _Seq1>&,
00066                          const stack<_Tp1, _Seq1>&);
00067 public:
00068   typedef typename _Sequence::value_type      value_type;
00069   typedef typename _Sequence::size_type       size_type;
00070   typedef          _Sequence                  container_type;
00071 
00072   typedef typename _Sequence::reference       reference;
00073   typedef typename _Sequence::const_reference const_reference;
00074 protected:
00075   _Sequence c;
00076 public:
00077   stack() : c() {}
00078   explicit stack(const _Sequence& __s) : c(__s) {}
00079 
00080   bool empty() const { return c.empty(); }
00081   size_type size() const { return c.size(); }
00082   reference top() { return c.back(); }
00083   const_reference top() const { return c.back(); }
00084   void push(const value_type& __x) { c.push_back(__x); }
00085   void pop() { c.pop_back(); }
00086 };
00087 
00088 template <class _Tp, class _Seq>
00089 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00090 {
00091   return __x.c == __y.c;
00092 }
00093 
00094 template <class _Tp, class _Seq>
00095 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00096 {
00097   return __x.c < __y.c;
00098 }
00099 
00100 template <class _Tp, class _Seq>
00101 bool operator!=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00102 {
00103   return !(__x == __y);
00104 }
00105 
00106 template <class _Tp, class _Seq>
00107 bool operator>(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00108 {
00109   return __y < __x;
00110 }
00111 
00112 template <class _Tp, class _Seq>
00113 bool operator<=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00114 {
00115   return !(__y < __x);
00116 }
00117 
00118 template <class _Tp, class _Seq>
00119 bool operator>=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00120 {
00121   return !(__x < __y);
00122 }
00123 
00124 } // namespace std
00125 
00126 #endif /* __SGI_STL_INTERNAL_STACK_H */
00127 
00128 // Local Variables:
00129 // mode:C++
00130 // End:

Generated at Tue May 1 16:28:39 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001