57 #define _STL_STACK_H 1
61 #if __cplusplus >= 201103L
62 # include <bits/uses_allocator.h>
64 #if __glibcxx_containers_ranges
69 namespace std _GLIBCXX_VISIBILITY(default)
71 _GLIBCXX_BEGIN_NAMESPACE_VERSION
73 #if __glibcxx_format_ranges
74 template<
typename,
typename>
class formatter;
106 template<
typename _Tp,
typename _Sequence = deque<_Tp> >
109 #ifdef _GLIBCXX_CONCEPT_CHECKS
111 typedef typename _Sequence::value_type _Sequence_value_type;
112 # if __cplusplus < 201103L
113 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
114 __glibcxx_class_requires(_Sequence, _BackInsertionSequenceConcept)
116 __glibcxx_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept)
119 template<
typename _Tp1,
typename _Seq1>
123 template<
typename _Tp1,
typename _Seq1>
127 #if __cpp_lib_three_way_comparison
128 template<
typename _Tp1, three_way_comparable _Seq1>
133 #if __cplusplus >= 201103L
134 template<
typename _Alloc>
135 using _Uses =
typename
138 #if __cplusplus >= 201703L
143 "value_type must be the same as the underlying container");
148 typedef typename _Sequence::value_type value_type;
149 typedef typename _Sequence::reference reference;
150 typedef typename _Sequence::const_reference const_reference;
151 typedef typename _Sequence::size_type size_type;
152 typedef _Sequence container_type;
163 #if __cplusplus < 201103L
165 stack(
const _Sequence& __c = _Sequence())
168 template<
typename _Seq = _Sequence,
typename _Requires =
typename
174 stack(
const _Sequence& __c)
178 stack(_Sequence&& __c)
181 #ifdef __glibcxx_adaptor_iterator_pair_constructor
182 template<
typename _InputIterator,
183 typename = _RequireInputIter<_InputIterator>>
184 stack(_InputIterator __first, _InputIterator __last)
185 : c(__first, __last) { }
188 #if __glibcxx_containers_ranges
193 template<__detail::__container_compatible_range<_Tp> _Rg>
194 stack(from_range_t, _Rg&& __rg)
195 : c(ranges::to<_Sequence>(
std::
forward<_Rg>(__rg)))
202 template<__detail::__container_compatible_range<_Tp> _Rg,
204 stack(from_range_t, _Rg&& __rg,
const _Alloc& __a)
205 : c(ranges::to<_Sequence>(
std::
forward<_Rg>(__rg), __a))
209 template<
typename _Alloc,
typename _Requires = _Uses<_Alloc>>
211 stack(
const _Alloc& __a)
214 template<
typename _Alloc,
typename _Requires = _Uses<_Alloc>>
215 stack(
const _Sequence& __c,
const _Alloc& __a)
218 template<
typename _Alloc,
typename _Requires = _Uses<_Alloc>>
219 stack(_Sequence&& __c,
const _Alloc& __a)
222 template<
typename _Alloc,
typename _Requires = _Uses<_Alloc>>
226 template<
typename _Alloc,
typename _Requires = _Uses<_Alloc>>
230 #if __cplusplus > 202002L
231 template<
typename _InputIterator,
typename _Alloc,
232 typename = _RequireInputIter<_InputIterator>,
233 typename = _Uses<_Alloc>>
234 stack(_InputIterator __first, _InputIterator __last,
const _Alloc& __a)
235 : c(__first, __last, __a) { }
242 _GLIBCXX_NODISCARD
bool
244 {
return c.empty(); }
260 __glibcxx_requires_nonempty();
272 __glibcxx_requires_nonempty();
287 { c.push_back(__x); }
289 #if __cplusplus >= 201103L
291 push(value_type&& __x)
294 #if __cplusplus > 201402L
295 template<
typename... _Args>
297 emplace(_Args&&... __args)
298 {
return c.emplace_back(std::forward<_Args>(__args)...); }
300 template<
typename... _Args>
302 emplace(_Args&&... __args)
303 { c.emplace_back(std::forward<_Args>(__args)...); }
307 #if __glibcxx_containers_ranges
308 template<__detail::__container_compatible_range<_Tp> _Rg>
310 push_range(_Rg&& __rg)
312 if constexpr (requires { c.append_range(std::forward<_Rg>(__rg)); })
313 c.append_range(std::forward<_Rg>(__rg));
333 __glibcxx_requires_nonempty();
337 #if __cplusplus >= 201103L
340 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
341 noexcept(__is_nothrow_swappable<_Sequence>::value)
343 noexcept(__is_nothrow_swappable<_Tp>::value)
351 #if __glibcxx_format_ranges
352 friend class formatter<
stack<_Tp, _Sequence>, char>;
353 friend class formatter<
stack<_Tp, _Sequence>, wchar_t>;
357 #if __cpp_deduction_guides >= 201606
358 template<
typename _Container,
359 typename = _RequireNotAllocator<_Container>>
360 stack(_Container) -> stack<typename _Container::value_type, _Container>;
362 template<
typename _Container,
typename _Allocator,
363 typename = _RequireNotAllocator<_Container>>
364 stack(_Container, _Allocator)
365 -> stack<typename _Container::value_type, _Container>;
367 #ifdef __glibcxx_adaptor_iterator_pair_constructor
368 template<
typename _InputIterator,
370 =
typename iterator_traits<_InputIterator>::value_type,
371 typename = _RequireInputIter<_InputIterator>>
372 stack(_InputIterator, _InputIterator) -> stack<_ValT>;
374 template<
typename _InputIterator,
typename _Allocator,
376 =
typename iterator_traits<_InputIterator>::value_type,
377 typename = _RequireInputIter<_InputIterator>,
378 typename = _RequireAllocator<_Allocator>>
379 stack(_InputIterator, _InputIterator, _Allocator)
380 -> stack<_ValT, deque<_ValT, _Allocator>>;
383 #if __glibcxx_containers_ranges
384 template<ranges::input_range _Rg>
385 stack(from_range_t, _Rg&&) -> stack<ranges::range_value_t<_Rg>>;
387 template<ranges::input_range _Rg, __allocator_like _Alloc>
388 stack(from_range_t, _Rg&&, _Alloc)
389 -> stack<ranges::range_value_t<_Rg>,
390 deque<ranges::range_value_t<_Rg>, _Alloc>>;
406 template<
typename _Tp,
typename _Seq>
410 {
return __x.c == __y.c; }
425 template<
typename _Tp,
typename _Seq>
429 {
return __x.c < __y.c; }
432 template<
typename _Tp,
typename _Seq>
436 {
return !(__x == __y); }
439 template<
typename _Tp,
typename _Seq>
443 {
return __y < __x; }
446 template<
typename _Tp,
typename _Seq>
450 {
return !(__y < __x); }
453 template<
typename _Tp,
typename _Seq>
457 {
return !(__x < __y); }
459 #if __cpp_lib_three_way_comparison
460 template<
typename _Tp, three_way_comparable _Seq>
462 inline compare_three_way_result_t<_Seq>
463 operator<=>(
const stack<_Tp, _Seq>& __x,
const stack<_Tp, _Seq>& __y)
464 {
return __x.c <=> __y.c; }
467 #if __cplusplus >= 201103L
468 template<
typename _Tp,
typename _Seq>
470 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__)
472 typename enable_if<__is_swappable<_Seq>::value>::type
476 swap(stack<_Tp, _Seq>& __x, stack<_Tp, _Seq>& __y)
477 noexcept(noexcept(__x.swap(__y)))
480 template<
typename _Tp,
typename _Seq,
typename _Alloc>
481 struct uses_allocator<stack<_Tp, _Seq>, _Alloc>
482 :
public uses_allocator<_Seq, _Alloc>::type { };
485 _GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
ISO C++ entities toplevel namespace is std.
bool operator==(const stack< _Tp, _Seq > &__x, const stack< _Tp, _Seq > &__y)
Stack equality comparison.
bool operator>=(const stack< _Tp, _Seq > &__x, const stack< _Tp, _Seq > &__y)
Based on operator<.
bool operator!=(const stack< _Tp, _Seq > &__x, const stack< _Tp, _Seq > &__y)
Based on operator==.
bool operator<(const stack< _Tp, _Seq > &__x, const stack< _Tp, _Seq > &__y)
Stack ordering relation.
bool operator>(const stack< _Tp, _Seq > &__x, const stack< _Tp, _Seq > &__y)
Based on operator<.
bool operator<=(const stack< _Tp, _Seq > &__x, const stack< _Tp, _Seq > &__y)
Based on operator<.
typename __detail::__cmp3way_res_impl< _Tp, _Up >::type compare_three_way_result_t
[cmp.result], result of three-way comparison
Define a member typedef type only if a boolean constant is true.
A standard container giving FILO behavior.
void pop()
Removes first element.
void push(const value_type &__x)
Add data to the top of the stack.
const_reference top() const
stack()
Default constructor creates no elements.