Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_STACK |
| 11 | #define _LIBCPP_STACK |
| 12 | |
| 13 | /* |
| 14 | stack synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template <class T, class Container = deque<T>> |
| 20 | class stack |
| 21 | { |
| 22 | public: |
| 23 | typedef Container container_type; |
| 24 | typedef typename container_type::value_type value_type; |
| 25 | typedef typename container_type::reference reference; |
| 26 | typedef typename container_type::const_reference const_reference; |
| 27 | typedef typename container_type::size_type size_type; |
| 28 | |
| 29 | protected: |
| 30 | container_type c; |
| 31 | |
| 32 | public: |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 33 | stack() = default; |
| 34 | ~stack() = default; |
| 35 | |
| 36 | stack(const stack& q) = default; |
| 37 | stack(stack&& q) = default; |
| 38 | |
| 39 | stack& operator=(const stack& q) = default; |
| 40 | stack& operator=(stack&& q) = default; |
| 41 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | explicit stack(const container_type& c); |
| 43 | explicit stack(container_type&& c); |
Nikolas Klauser | f0b3d87 | 2022-01-06 12:36:07 +0100 | [diff] [blame] | 44 | template <class InputIterator> stack(InputIterator first, InputIterator last); // since C++23 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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); |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 48 | template <class Alloc> stack(const stack& c, const Alloc& a); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | template <class Alloc> stack(stack&& c, const Alloc& a); |
Nikolas Klauser | f0b3d87 | 2022-01-06 12:36:07 +0100 | [diff] [blame] | 50 | template<class InputIterator, class Alloc> |
| 51 | stack(InputIterator first, InputIterator last, const Alloc&); // since C++23 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 | |
| 53 | bool empty() const; |
| 54 | size_type size() const; |
| 55 | reference top(); |
| 56 | const_reference top() const; |
| 57 | |
| 58 | void push(const value_type& x); |
| 59 | void push(value_type&& x); |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 60 | template <class... Args> reference emplace(Args&&... args); // reference in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 61 | void pop(); |
| 62 | |
Eric Fiselier | 6bfed25 | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 63 | void swap(stack& c) noexcept(is_nothrow_swappable_v<Container>) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
Marshall Clow | 592d995 | 2018-05-22 01:57:53 +0000 | [diff] [blame] | 66 | template<class Container> |
| 67 | stack(Container) -> stack<typename Container::value_type, Container>; // C++17 |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 68 | |
Nikolas Klauser | f0b3d87 | 2022-01-06 12:36:07 +0100 | [diff] [blame] | 69 | template<class InputIterator> |
| 70 | stack(InputIterator, InputIterator) -> stack<iter-value-type<InputIterator>>; // since C++23 |
| 71 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 72 | template<class Container, class Allocator> |
Marshall Clow | 592d995 | 2018-05-22 01:57:53 +0000 | [diff] [blame] | 73 | stack(Container, Allocator) -> stack<typename Container::value_type, Container>; // C++17 |
| 74 | |
Nikolas Klauser | f0b3d87 | 2022-01-06 12:36:07 +0100 | [diff] [blame] | 75 | template<class InputIterator, class Allocator> |
| 76 | stack(InputIterator, InputIterator, Allocator) |
| 77 | -> stack<iter-value-type<InputIterator>, |
| 78 | deque<iter-value-type<InputIterator>, Allocator>>; // since C++23 |
| 79 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 | template <class T, class Container> |
| 81 | bool operator==(const stack<T, Container>& x, const stack<T, Container>& y); |
| 82 | template <class T, class Container> |
| 83 | bool operator< (const stack<T, Container>& x, const stack<T, Container>& y); |
| 84 | template <class T, class Container> |
| 85 | bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y); |
| 86 | template <class T, class Container> |
| 87 | bool operator> (const stack<T, Container>& x, const stack<T, Container>& y); |
| 88 | template <class T, class Container> |
| 89 | bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y); |
| 90 | template <class T, class Container> |
| 91 | bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y); |
| 92 | |
| 93 | template <class T, class Container> |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 94 | void swap(stack<T, Container>& x, stack<T, Container>& y) |
| 95 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 96 | |
| 97 | } // std |
| 98 | |
| 99 | */ |
| 100 | |
Louis Dionne | b4fce35 | 2022-03-25 12:55:36 -0400 | [diff] [blame] | 101 | #include <__assert> // all public C++ headers provide the assertion handler |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 102 | #include <__config> |
Nikolas Klauser | f0b3d87 | 2022-01-06 12:36:07 +0100 | [diff] [blame] | 103 | #include <__iterator/iterator_traits.h> |
Christopher Di Bella | 55d7a82 | 2021-07-01 09:25:35 -0400 | [diff] [blame] | 104 | #include <__memory/uses_allocator.h> |
Christopher Di Bella | 41f26e8 | 2021-06-05 02:47:47 +0000 | [diff] [blame] | 105 | #include <__utility/forward.h> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | #include <deque> |
Nikolas Klauser | f0b3d87 | 2022-01-06 12:36:07 +0100 | [diff] [blame] | 107 | #include <type_traits> |
Mark de Wever | ce8f12c | 2021-12-22 18:14:14 +0100 | [diff] [blame] | 108 | #include <version> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 109 | |
Nikolas Klauser | a0e0edb | 2022-06-16 22:43:46 +0200 | [diff] [blame] | 110 | // standard-mandated includes |
Nikolas Klauser | 71619e7 | 2022-09-22 18:05:08 +0200 | [diff] [blame] | 111 | |
| 112 | // [stack.syn] |
Nikolas Klauser | a0e0edb | 2022-06-16 22:43:46 +0200 | [diff] [blame] | 113 | #include <compare> |
| 114 | #include <initializer_list> |
| 115 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 116 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 117 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 118 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 119 | |
| 120 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 121 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 122 | template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS stack; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 123 | |
| 124 | template <class _Tp, class _Container> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 125 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | bool |
| 127 | operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); |
| 128 | |
| 129 | template <class _Tp, class _Container> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 130 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 131 | bool |
| 132 | operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); |
| 133 | |
Marshall Clow | 9e1b845 | 2015-02-18 17:51:56 +0000 | [diff] [blame] | 134 | template <class _Tp, class _Container /*= deque<_Tp>*/> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 135 | class _LIBCPP_TEMPLATE_VIS stack |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 136 | { |
| 137 | public: |
| 138 | typedef _Container container_type; |
| 139 | typedef typename container_type::value_type value_type; |
| 140 | typedef typename container_type::reference reference; |
| 141 | typedef typename container_type::const_reference const_reference; |
| 142 | typedef typename container_type::size_type size_type; |
Marshall Clow | b8825f0 | 2016-03-14 17:58:11 +0000 | [diff] [blame] | 143 | static_assert((is_same<_Tp, value_type>::value), "" ); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 144 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 145 | protected: |
| 146 | container_type c; |
| 147 | |
| 148 | public: |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 149 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 150 | stack() |
| 151 | _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) |
| 152 | : c() {} |
| 153 | |
| 154 | _LIBCPP_INLINE_VISIBILITY |
| 155 | stack(const stack& __q) : c(__q.c) {} |
| 156 | |
Eric Fiselier | 33cc2f0 | 2017-04-18 21:16:26 +0000 | [diff] [blame] | 157 | _LIBCPP_INLINE_VISIBILITY |
| 158 | stack& operator=(const stack& __q) {c = __q.c; return *this;} |
| 159 | |
| 160 | |
| 161 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 162 | _LIBCPP_INLINE_VISIBILITY |
| 163 | stack(stack&& __q) |
| 164 | _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 165 | : c(_VSTD::move(__q.c)) {} |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 166 | |
| 167 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 168 | stack& operator=(stack&& __q) |
| 169 | _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 170 | {c = _VSTD::move(__q.c); return *this;} |
Eric Fiselier | 33cc2f0 | 2017-04-18 21:16:26 +0000 | [diff] [blame] | 171 | |
| 172 | _LIBCPP_INLINE_VISIBILITY |
| 173 | explicit stack(container_type&& __c) : c(_VSTD::move(__c)) {} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 174 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 175 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 176 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 177 | explicit stack(const container_type& __c) : c(__c) {} |
Eric Fiselier | 33cc2f0 | 2017-04-18 21:16:26 +0000 | [diff] [blame] | 178 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 179 | template <class _Alloc> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 180 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 181 | explicit stack(const _Alloc& __a, |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 182 | __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 183 | : c(__a) {} |
| 184 | template <class _Alloc> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 185 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | stack(const container_type& __c, const _Alloc& __a, |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 187 | __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 188 | : c(__c, __a) {} |
| 189 | template <class _Alloc> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 190 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 191 | stack(const stack& __s, const _Alloc& __a, |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 192 | __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 | : c(__s.c, __a) {} |
Eric Fiselier | 33cc2f0 | 2017-04-18 21:16:26 +0000 | [diff] [blame] | 194 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 195 | template <class _Alloc> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 196 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 197 | stack(container_type&& __c, const _Alloc& __a, |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 198 | __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 199 | : c(_VSTD::move(__c), __a) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 200 | template <class _Alloc> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 201 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 202 | stack(stack&& __s, const _Alloc& __a, |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 203 | __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 204 | : c(_VSTD::move(__s.c), __a) {} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 205 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 206 | |
Nikolas Klauser | f0b3d87 | 2022-01-06 12:36:07 +0100 | [diff] [blame] | 207 | #if _LIBCPP_STD_VER > 20 |
| 208 | template <class _InputIterator, |
| 209 | class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>> |
| 210 | _LIBCPP_HIDE_FROM_ABI |
| 211 | stack(_InputIterator __first, _InputIterator __last) : c(__first, __last) {} |
| 212 | |
| 213 | template <class _InputIterator, |
| 214 | class _Alloc, |
| 215 | class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
| 216 | class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>> |
| 217 | _LIBCPP_HIDE_FROM_ABI |
| 218 | stack(_InputIterator __first, _InputIterator __last, const _Alloc& __alloc) : c(__first, __last, __alloc) {} |
| 219 | #endif |
| 220 | |
Marshall Clow | 425f575 | 2017-11-15 05:51:26 +0000 | [diff] [blame] | 221 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 222 | bool empty() const {return c.empty();} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 223 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | size_type size() const {return c.size();} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 225 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 226 | reference top() {return c.back();} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 227 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 228 | const_reference top() const {return c.back();} |
| 229 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 230 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 231 | void push(const value_type& __v) {c.push_back(__v);} |
Eric Fiselier | 33cc2f0 | 2017-04-18 21:16:26 +0000 | [diff] [blame] | 232 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 233 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 234 | void push(value_type&& __v) {c.push_back(_VSTD::move(__v));} |
Eric Fiselier | 33cc2f0 | 2017-04-18 21:16:26 +0000 | [diff] [blame] | 235 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 236 | template <class... _Args> |
| 237 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 238 | #if _LIBCPP_STD_VER > 14 |
Marshall Clow | 8874685 | 2018-01-24 22:42:25 +0000 | [diff] [blame] | 239 | decltype(auto) emplace(_Args&&... __args) |
Eric Fiselier | 34ba5b9 | 2016-07-21 03:20:17 +0000 | [diff] [blame] | 240 | { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 241 | #else |
| 242 | void emplace(_Args&&... __args) |
| 243 | { c.emplace_back(_VSTD::forward<_Args>(__args)...);} |
| 244 | #endif |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 245 | #endif // _LIBCPP_CXX03_LANG |
Eric Fiselier | 33cc2f0 | 2017-04-18 21:16:26 +0000 | [diff] [blame] | 246 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 247 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 248 | void pop() {c.pop_back();} |
| 249 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 250 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 251 | void swap(stack& __s) |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 252 | _NOEXCEPT_(__is_nothrow_swappable<container_type>::value) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 253 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 254 | using _VSTD::swap; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 255 | swap(c, __s.c); |
| 256 | } |
| 257 | |
| 258 | template <class T1, class _C1> |
| 259 | friend |
| 260 | bool |
| 261 | operator==(const stack<T1, _C1>& __x, const stack<T1, _C1>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 262 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | template <class T1, class _C1> |
| 264 | friend |
| 265 | bool |
| 266 | operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y); |
| 267 | }; |
| 268 | |
Nikolas Klauser | f0b3d87 | 2022-01-06 12:36:07 +0100 | [diff] [blame] | 269 | #if _LIBCPP_STD_VER > 14 |
Marshall Clow | 592d995 | 2018-05-22 01:57:53 +0000 | [diff] [blame] | 270 | template<class _Container, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 271 | class = enable_if_t<!__is_allocator<_Container>::value> |
Marshall Clow | 592d995 | 2018-05-22 01:57:53 +0000 | [diff] [blame] | 272 | > |
| 273 | stack(_Container) |
| 274 | -> stack<typename _Container::value_type, _Container>; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 275 | |
Marshall Clow | 592d995 | 2018-05-22 01:57:53 +0000 | [diff] [blame] | 276 | template<class _Container, |
| 277 | class _Alloc, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 278 | class = enable_if_t<!__is_allocator<_Container>::value>, |
| 279 | class = enable_if_t<uses_allocator<_Container, _Alloc>::value> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 280 | > |
Marshall Clow | 592d995 | 2018-05-22 01:57:53 +0000 | [diff] [blame] | 281 | stack(_Container, _Alloc) |
| 282 | -> stack<typename _Container::value_type, _Container>; |
| 283 | #endif |
| 284 | |
Nikolas Klauser | f0b3d87 | 2022-01-06 12:36:07 +0100 | [diff] [blame] | 285 | #if _LIBCPP_STD_VER > 20 |
| 286 | template<class _InputIterator, |
| 287 | class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>> |
| 288 | stack(_InputIterator, _InputIterator) |
| 289 | -> stack<__iter_value_type<_InputIterator>>; |
| 290 | |
| 291 | template<class _InputIterator, |
| 292 | class _Alloc, |
| 293 | class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
| 294 | class = __enable_if_t<__is_allocator<_Alloc>::value>> |
| 295 | stack(_InputIterator, _InputIterator, _Alloc) |
| 296 | -> stack<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>; |
| 297 | #endif |
| 298 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 299 | template <class _Tp, class _Container> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 300 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 301 | bool |
| 302 | operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) |
| 303 | { |
| 304 | return __x.c == __y.c; |
| 305 | } |
| 306 | |
| 307 | template <class _Tp, class _Container> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 308 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | bool |
| 310 | operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) |
| 311 | { |
| 312 | return __x.c < __y.c; |
| 313 | } |
| 314 | |
| 315 | template <class _Tp, class _Container> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 316 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 317 | bool |
| 318 | operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) |
| 319 | { |
| 320 | return !(__x == __y); |
| 321 | } |
| 322 | |
| 323 | template <class _Tp, class _Container> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 324 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 325 | bool |
| 326 | operator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) |
| 327 | { |
| 328 | return __y < __x; |
| 329 | } |
| 330 | |
| 331 | template <class _Tp, class _Container> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 332 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 333 | bool |
| 334 | operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) |
| 335 | { |
| 336 | return !(__x < __y); |
| 337 | } |
| 338 | |
| 339 | template <class _Tp, class _Container> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 340 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 341 | bool |
| 342 | operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) |
| 343 | { |
| 344 | return !(__y < __x); |
| 345 | } |
| 346 | |
| 347 | template <class _Tp, class _Container> |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 348 | inline _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 349 | __enable_if_t<__is_swappable<_Container>::value, void> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 350 | swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y) |
Howard Hinnant | e0da4a1 | 2011-06-04 22:09:19 +0000 | [diff] [blame] | 351 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | { |
| 353 | __x.swap(__y); |
| 354 | } |
| 355 | |
| 356 | template <class _Tp, class _Container, class _Alloc> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 357 | struct _LIBCPP_TEMPLATE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 358 | : public uses_allocator<_Container, _Alloc> |
| 359 | { |
| 360 | }; |
| 361 | |
| 362 | _LIBCPP_END_NAMESPACE_STD |
| 363 | |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 364 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
Nikolas Klauser | 1e4ae5d | 2022-11-02 20:27:42 +0100 | [diff] [blame] | 365 | # include <concepts> |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 366 | # include <functional> |
| 367 | #endif |
| 368 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 369 | #endif // _LIBCPP_STACK |