2 //===---------------------------- stack -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
20 template <class T, class Container = deque<T>>
24 typedef Container container_type;
25 typedef typename container_type::value_type value_type;
26 typedef typename container_type::reference reference;
27 typedef typename container_type::const_reference const_reference;
28 typedef typename container_type::size_type size_type;
37 stack(const stack& q) = default;
38 stack(stack&& q) = default;
40 stack& operator=(const stack& q) = default;
41 stack& operator=(stack&& q) = default;
43 explicit stack(const container_type& c);
44 explicit stack(container_type&& c);
45 template <class Alloc> explicit stack(const Alloc& a);
46 template <class Alloc> stack(const container_type& c, const Alloc& a);
47 template <class Alloc> stack(container_type&& c, const Alloc& a);
48 template <class Alloc> stack(const stack& c, const Alloc& a);
49 template <class Alloc> stack(stack&& c, const Alloc& a);
52 size_type size() const;
54 const_reference top() const;
56 void push(const value_type& x);
57 void push(value_type&& x);
58 template <class... Args> void emplace(Args&&... args);
61 void swap(stack& c) noexcept(noexcept(swap(c, q.c)));
64 template <class T, class Container>
65 bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
66 template <class T, class Container>
67 bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
68 template <class T, class Container>
69 bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
70 template <class T, class Container>
71 bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
72 template <class T, class Container>
73 bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
74 template <class T, class Container>
75 bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
77 template <class T, class Container>
78 void swap(stack<T, Container>& x, stack<T, Container>& y)
79 noexcept(noexcept(x.swap(y)));
88 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
89 #pragma GCC system_header
92 _LIBCPP_BEGIN_NAMESPACE_STD
94 template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TYPE_VIS_ONLY stack;
96 template <class _Tp, class _Container>
97 _LIBCPP_INLINE_VISIBILITY
99 operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
101 template <class _Tp, class _Container>
102 _LIBCPP_INLINE_VISIBILITY
104 operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
106 template <class _Tp, class _Container /*= deque<_Tp>*/>
107 class _LIBCPP_TYPE_VIS_ONLY stack
110 typedef _Container container_type;
111 typedef typename container_type::value_type value_type;
112 typedef typename container_type::reference reference;
113 typedef typename container_type::const_reference const_reference;
114 typedef typename container_type::size_type size_type;
120 _LIBCPP_INLINE_VISIBILITY
122 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
125 _LIBCPP_INLINE_VISIBILITY
126 stack(const stack& __q) : c(__q.c) {}
128 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
129 _LIBCPP_INLINE_VISIBILITY
131 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
132 : c(_VSTD::move(__q.c)) {}
133 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
135 _LIBCPP_INLINE_VISIBILITY
136 stack& operator=(const stack& __q) {c = __q.c; return *this;}
138 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
139 _LIBCPP_INLINE_VISIBILITY
140 stack& operator=(stack&& __q)
141 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
142 {c = _VSTD::move(__q.c); return *this;}
143 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
145 _LIBCPP_INLINE_VISIBILITY
146 explicit stack(const container_type& __c) : c(__c) {}
147 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
148 _LIBCPP_INLINE_VISIBILITY
149 explicit stack(container_type&& __c) : c(_VSTD::move(__c)) {}
150 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
151 template <class _Alloc>
152 _LIBCPP_INLINE_VISIBILITY
153 explicit stack(const _Alloc& __a,
154 typename enable_if<uses_allocator<container_type,
155 _Alloc>::value>::type* = 0)
157 template <class _Alloc>
158 _LIBCPP_INLINE_VISIBILITY
159 stack(const container_type& __c, const _Alloc& __a,
160 typename enable_if<uses_allocator<container_type,
161 _Alloc>::value>::type* = 0)
163 template <class _Alloc>
164 _LIBCPP_INLINE_VISIBILITY
165 stack(const stack& __s, const _Alloc& __a,
166 typename enable_if<uses_allocator<container_type,
167 _Alloc>::value>::type* = 0)
169 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
170 template <class _Alloc>
171 _LIBCPP_INLINE_VISIBILITY
172 stack(container_type&& __c, const _Alloc& __a,
173 typename enable_if<uses_allocator<container_type,
174 _Alloc>::value>::type* = 0)
175 : c(_VSTD::move(__c), __a) {}
176 template <class _Alloc>
177 _LIBCPP_INLINE_VISIBILITY
178 stack(stack&& __s, const _Alloc& __a,
179 typename enable_if<uses_allocator<container_type,
180 _Alloc>::value>::type* = 0)
181 : c(_VSTD::move(__s.c), __a) {}
182 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
184 _LIBCPP_INLINE_VISIBILITY
185 bool empty() const {return c.empty();}
186 _LIBCPP_INLINE_VISIBILITY
187 size_type size() const {return c.size();}
188 _LIBCPP_INLINE_VISIBILITY
189 reference top() {return c.back();}
190 _LIBCPP_INLINE_VISIBILITY
191 const_reference top() const {return c.back();}
193 _LIBCPP_INLINE_VISIBILITY
194 void push(const value_type& __v) {c.push_back(__v);}
195 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
196 _LIBCPP_INLINE_VISIBILITY
197 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
198 #ifndef _LIBCPP_HAS_NO_VARIADICS
199 template <class... _Args>
200 _LIBCPP_INLINE_VISIBILITY
201 void emplace(_Args&&... __args)
202 {c.emplace_back(_VSTD::forward<_Args>(__args)...);}
203 #endif // _LIBCPP_HAS_NO_VARIADICS
204 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
205 _LIBCPP_INLINE_VISIBILITY
206 void pop() {c.pop_back();}
208 _LIBCPP_INLINE_VISIBILITY
209 void swap(stack& __s)
210 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
216 template <class T1, class _C1>
219 operator==(const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
221 template <class T1, class _C1>
224 operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
227 template <class _Tp, class _Container>
228 inline _LIBCPP_INLINE_VISIBILITY
230 operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
232 return __x.c == __y.c;
235 template <class _Tp, class _Container>
236 inline _LIBCPP_INLINE_VISIBILITY
238 operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
240 return __x.c < __y.c;
243 template <class _Tp, class _Container>
244 inline _LIBCPP_INLINE_VISIBILITY
246 operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
248 return !(__x == __y);
251 template <class _Tp, class _Container>
252 inline _LIBCPP_INLINE_VISIBILITY
254 operator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
259 template <class _Tp, class _Container>
260 inline _LIBCPP_INLINE_VISIBILITY
262 operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
267 template <class _Tp, class _Container>
268 inline _LIBCPP_INLINE_VISIBILITY
270 operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
275 template <class _Tp, class _Container>
276 inline _LIBCPP_INLINE_VISIBILITY
278 swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
279 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
284 template <class _Tp, class _Container, class _Alloc>
285 struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<stack<_Tp, _Container>, _Alloc>
286 : public uses_allocator<_Container, _Alloc>
290 _LIBCPP_END_NAMESPACE_STD
292 #endif // _LIBCPP_STACK