algo.h: Use std not __STD.
[gcc.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/sequence_concepts.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 // requirements:
56
57 __STL_CLASS_REQUIRES(_Tp, _Assignable);
58 __STL_CLASS_REQUIRES(_Sequence, _BackInsertionSequence);
59 typedef typename _Sequence::value_type _Sequence_value_type;
60 __STL_CLASS_REQUIRES_SAME_TYPE(_Tp, _Sequence_value_type);
61
62
63 template <class _Tp1, class _Seq1>
64 friend bool operator== (const stack<_Tp1, _Seq1>&,
65 const stack<_Tp1, _Seq1>&);
66 template <class _Tp1, class _Seq1>
67 friend bool operator< (const stack<_Tp1, _Seq1>&,
68 const stack<_Tp1, _Seq1>&);
69 public:
70 typedef typename _Sequence::value_type value_type;
71 typedef typename _Sequence::size_type size_type;
72 typedef _Sequence container_type;
73
74 typedef typename _Sequence::reference reference;
75 typedef typename _Sequence::const_reference const_reference;
76 protected:
77 _Sequence c;
78 public:
79 stack() : c() {}
80 explicit stack(const _Sequence& __s) : c(__s) {}
81
82 bool empty() const { return c.empty(); }
83 size_type size() const { return c.size(); }
84 reference top() { return c.back(); }
85 const_reference top() const { return c.back(); }
86 void push(const value_type& __x) { c.push_back(__x); }
87 void pop() { c.pop_back(); }
88 };
89
90 template <class _Tp, class _Seq>
91 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
92 {
93 return __x.c == __y.c;
94 }
95
96 template <class _Tp, class _Seq>
97 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
98 {
99 return __x.c < __y.c;
100 }
101
102 template <class _Tp, class _Seq>
103 bool operator!=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
104 {
105 return !(__x == __y);
106 }
107
108 template <class _Tp, class _Seq>
109 bool operator>(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
110 {
111 return __y < __x;
112 }
113
114 template <class _Tp, class _Seq>
115 bool operator<=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
116 {
117 return !(__y < __x);
118 }
119
120 template <class _Tp, class _Seq>
121 bool operator>=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
122 {
123 return !(__x < __y);
124 }
125
126 } // namespace std
127
128 #endif /* __SGI_STL_INTERNAL_STACK_H */
129
130 // Local Variables:
131 // mode:C++
132 // End: