OSDN Git Service

2001-04-02 Phil Edwards <pme@sources.redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / stl_stack.h
1 /*
2  *
3  * Copyright (c) 1994
4  * Hewlett-Packard Company
5  *
6  * Permission to use, copy, modify, distribute and sell this software
7  * and its documentation for any purpose is hereby granted without fee,
8  * provided that the above copyright notice appear in all copies and
9  * that both that copyright notice and this permission notice appear
10  * in supporting documentation.  Hewlett-Packard Company makes no
11  * representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  *
15  * Copyright (c) 1996,1997
16  * Silicon Graphics Computer Systems, Inc.
17  *
18  * Permission to use, copy, modify, distribute and sell this software
19  * and its documentation for any purpose is hereby granted without fee,
20  * provided that the above copyright notice appear in all copies and
21  * that both that copyright notice and this permission notice appear
22  * in supporting documentation.  Silicon Graphics makes no
23  * representations about the suitability of this software for any
24  * purpose.  It is provided "as is" without express or implied warranty.
25  */
26
27 /* NOTE: This is an internal header file, included by other STL headers.
28  *   You should not attempt to use it directly.
29  */
30
31 #ifndef __SGI_STL_INTERNAL_STACK_H
32 #define __SGI_STL_INTERNAL_STACK_H
33
34 #include <bits/concept_check.h>
35
36 namespace std
37 {
38
39 // Forward declarations of operators == and <, needed for friend declaration.
40
41 template <class _Tp, 
42           class _Sequence = deque<_Tp> >
43 class stack;
44
45 template <class _Tp, class _Seq>
46 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
47
48 template <class _Tp, class _Seq>
49 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
50
51
52 template <class _Tp, class _Sequence>
53 class stack
54 {
55   // concept requirements
56   glibcpp_class_requires(_Tp, SGIAssignableConcept);
57   glibcpp_class_requires(_Sequence, BackInsertionSequenceConcept);
58   typedef typename _Sequence::value_type _Sequence_value_type;
59   glibcpp_class_requires2(_Tp, _Sequence_value_type, SameTypeConcept);
60
61   template <class _Tp1, class _Seq1>
62   friend bool operator== (const stack<_Tp1, _Seq1>&,
63                           const stack<_Tp1, _Seq1>&);
64   template <class _Tp1, class _Seq1>
65   friend bool operator< (const stack<_Tp1, _Seq1>&,
66                          const stack<_Tp1, _Seq1>&);
67 public:
68   typedef typename _Sequence::value_type      value_type;
69   typedef typename _Sequence::size_type       size_type;
70   typedef          _Sequence                  container_type;
71
72   typedef typename _Sequence::reference       reference;
73   typedef typename _Sequence::const_reference const_reference;
74 protected:
75   _Sequence c;
76 public:
77   stack() : c() {}
78   explicit stack(const _Sequence& __s) : c(__s) {}
79
80   bool empty() const { return c.empty(); }
81   size_type size() const { return c.size(); }
82   reference top() { return c.back(); }
83   const_reference top() const { return c.back(); }
84   void push(const value_type& __x) { c.push_back(__x); }
85   void pop() { c.pop_back(); }
86 };
87
88 template <class _Tp, class _Seq>
89 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
90 {
91   return __x.c == __y.c;
92 }
93
94 template <class _Tp, class _Seq>
95 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
96 {
97   return __x.c < __y.c;
98 }
99
100 template <class _Tp, class _Seq>
101 bool operator!=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
102 {
103   return !(__x == __y);
104 }
105
106 template <class _Tp, class _Seq>
107 bool operator>(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
108 {
109   return __y < __x;
110 }
111
112 template <class _Tp, class _Seq>
113 bool operator<=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
114 {
115   return !(__y < __x);
116 }
117
118 template <class _Tp, class _Seq>
119 bool operator>=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
120 {
121   return !(__x < __y);
122 }
123
124 } // namespace std
125
126 #endif /* __SGI_STL_INTERNAL_STACK_H */
127
128 // Local Variables:
129 // mode:C++
130 // End: