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 00061 #ifndef __GLIBCPP_INTERNAL_STACK_H 00062 #define __GLIBCPP_INTERNAL_STACK_H 00063 00064 #include <bits/concept_check.h> 00065 00066 namespace std 00067 { 00068 00069 // Forward declarations of operators == and <, needed for friend declaration. 00070 00071 template <class _Tp, 00072 class _Sequence = deque<_Tp> > 00073 class stack; 00074 00075 template <class _Tp, class _Seq> 00076 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y); 00077 00078 template <class _Tp, class _Seq> 00079 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y); 00080 00081 00082 template <class _Tp, class _Sequence> 00083 class stack 00084 { 00085 // concept requirements 00086 __glibcpp_class_requires(_Tp, _SGIAssignableConcept) 00087 __glibcpp_class_requires(_Sequence, _BackInsertionSequenceConcept) 00088 typedef typename _Sequence::value_type _Sequence_value_type; 00089 __glibcpp_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept); 00090 00091 template <class _Tp1, class _Seq1> 00092 friend bool operator== (const stack<_Tp1, _Seq1>&, 00093 const stack<_Tp1, _Seq1>&); 00094 template <class _Tp1, class _Seq1> 00095 friend bool operator< (const stack<_Tp1, _Seq1>&, 00096 const stack<_Tp1, _Seq1>&); 00097 public: 00098 typedef typename _Sequence::value_type value_type; 00099 typedef typename _Sequence::size_type size_type; 00100 typedef _Sequence container_type; 00101 00102 typedef typename _Sequence::reference reference; 00103 typedef typename _Sequence::const_reference const_reference; 00104 protected: 00105 _Sequence c; 00106 public: 00107 stack() : c() {} 00108 explicit stack(const _Sequence& __s) : c(__s) {} 00109 00110 bool empty() const { return c.empty(); } 00111 size_type size() const { return c.size(); } 00112 reference top() { return c.back(); } 00113 const_reference top() const { return c.back(); } 00114 void push(const value_type& __x) { c.push_back(__x); } 00115 void pop() { c.pop_back(); } 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.c == __y.c; 00122 } 00123 00124 template <class _Tp, class _Seq> 00125 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y) 00126 { 00127 return __x.c < __y.c; 00128 } 00129 00130 template <class _Tp, class _Seq> 00131 bool operator!=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y) 00132 { 00133 return !(__x == __y); 00134 } 00135 00136 template <class _Tp, class _Seq> 00137 bool operator>(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y) 00138 { 00139 return __y < __x; 00140 } 00141 00142 template <class _Tp, class _Seq> 00143 bool operator<=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y) 00144 { 00145 return !(__y < __x); 00146 } 00147 00148 template <class _Tp, class _Seq> 00149 bool operator>=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y) 00150 { 00151 return !(__x < __y); 00152 } 00153 00154 } // namespace std 00155 00156 #endif /* __GLIBCPP_INTERNAL_STACK_H */ 00157 00158 // Local Variables: 00159 // mode:C++ 00160 // End:

Generated on Wed Sep 29 13:54:53 2004 for libstdc++-v3 Source by doxygen 1.3.7