Warning, /include/c++/v1/__cxx03/stack is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009
0010 #ifndef _LIBCPP___CXX03_STACK
0011 #define _LIBCPP___CXX03_STACK
0012
0013 /*
0014 stack synopsis
0015
0016 namespace std
0017 {
0018
0019 template <class T, class Container = deque<T>>
0020 class stack
0021 {
0022 public:
0023 typedef Container container_type;
0024 typedef typename container_type::value_type value_type;
0025 typedef typename container_type::reference reference;
0026 typedef typename container_type::const_reference const_reference;
0027 typedef typename container_type::size_type size_type;
0028
0029 protected:
0030 container_type c;
0031
0032 public:
0033 stack() = default;
0034 ~stack() = default;
0035
0036 stack(const stack& q) = default;
0037 stack(stack&& q) = default;
0038
0039 stack& operator=(const stack& q) = default;
0040 stack& operator=(stack&& q) = default;
0041
0042 explicit stack(const container_type& c);
0043 explicit stack(container_type&& c);
0044 template <class InputIterator> stack(InputIterator first, InputIterator last); // since C++23
0045 template<container-compatible-range<T> R> stack(from_range_t, R&& rg); // since C++23
0046 template <class Alloc> explicit stack(const Alloc& a);
0047 template <class Alloc> stack(const container_type& c, const Alloc& a);
0048 template <class Alloc> stack(container_type&& c, const Alloc& a);
0049 template <class Alloc> stack(const stack& c, const Alloc& a);
0050 template <class Alloc> stack(stack&& c, const Alloc& a);
0051 template<class InputIterator, class Alloc>
0052 stack(InputIterator first, InputIterator last, const Alloc&); // since C++23
0053 template<container-compatible-range<T> R, class Alloc>
0054 stack(from_range_t, R&& rg, const Alloc&); // since C++23
0055
0056 bool empty() const;
0057 size_type size() const;
0058 reference top();
0059 const_reference top() const;
0060
0061 void push(const value_type& x);
0062 void push(value_type&& x);
0063 template<container-compatible-range<T> R>
0064 void push_range(R&& rg); // C++23
0065 template <class... Args> reference emplace(Args&&... args); // reference in C++17
0066 void pop();
0067
0068 void swap(stack& c) noexcept(is_nothrow_swappable_v<Container>)
0069 };
0070
0071 template<class Container>
0072 stack(Container) -> stack<typename Container::value_type, Container>; // C++17
0073
0074 template<class InputIterator>
0075 stack(InputIterator, InputIterator) -> stack<iter-value-type<InputIterator>>; // since C++23
0076
0077 template<ranges::input_range R>
0078 stack(from_range_t, R&&) -> stack<ranges::range_value_t<R>>; // since C++23
0079
0080 template<class Container, class Allocator>
0081 stack(Container, Allocator) -> stack<typename Container::value_type, Container>; // C++17
0082
0083 template<class InputIterator, class Allocator>
0084 stack(InputIterator, InputIterator, Allocator)
0085 -> stack<iter-value-type<InputIterator>,
0086 deque<iter-value-type<InputIterator>, Allocator>>; // since C++23
0087
0088 template<ranges::input_range R, class Allocator>
0089 stack(from_range_t, R&&, Allocator)
0090 -> stack<ranges::range_value_t<R>, deque<ranges::range_value_t<R>, Allocator>>; // since C++23
0091
0092 template <class T, class Container>
0093 bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
0094 template <class T, class Container>
0095 bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
0096 template <class T, class Container>
0097 bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
0098 template <class T, class Container>
0099 bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
0100 template <class T, class Container>
0101 bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
0102 template <class T, class Container>
0103 bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
0104 template<class T, three_way_comparable Container>
0105 compare_three_way_result_t<Container>
0106 operator<=>(const stack<T, Container>& x, const stack<T, Container>& y); // since C++20
0107
0108 template <class T, class Container>
0109 void swap(stack<T, Container>& x, stack<T, Container>& y)
0110 noexcept(noexcept(x.swap(y)));
0111
0112 } // std
0113
0114 */
0115
0116 #include <__cxx03/__algorithm/ranges_copy.h>
0117 #include <__cxx03/__config>
0118 #include <__cxx03/__fwd/stack.h>
0119 #include <__cxx03/__iterator/back_insert_iterator.h>
0120 #include <__cxx03/__iterator/iterator_traits.h>
0121 #include <__cxx03/__memory/uses_allocator.h>
0122 #include <__cxx03/__ranges/access.h>
0123 #include <__cxx03/__ranges/concepts.h>
0124 #include <__cxx03/__ranges/container_compatible_range.h>
0125 #include <__cxx03/__ranges/from_range.h>
0126 #include <__cxx03/__type_traits/is_same.h>
0127 #include <__cxx03/__utility/forward.h>
0128 #include <__cxx03/deque>
0129 #include <__cxx03/version>
0130
0131 // standard-mandated includes
0132
0133 // [stack.syn]
0134 #include <__cxx03/compare>
0135 #include <__cxx03/initializer_list>
0136
0137 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0138 # pragma GCC system_header
0139 #endif
0140
0141 _LIBCPP_PUSH_MACROS
0142 #include <__cxx03/__undef_macros>
0143
0144 _LIBCPP_BEGIN_NAMESPACE_STD
0145
0146 template <class _Tp, class _Container>
0147 _LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
0148
0149 template <class _Tp, class _Container>
0150 _LIBCPP_HIDE_FROM_ABI bool operator<(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
0151
0152 template <class _Tp, class _Container /*= deque<_Tp>*/>
0153 class _LIBCPP_TEMPLATE_VIS stack {
0154 public:
0155 typedef _Container container_type;
0156 typedef typename container_type::value_type value_type;
0157 typedef typename container_type::reference reference;
0158 typedef typename container_type::const_reference const_reference;
0159 typedef typename container_type::size_type size_type;
0160 static_assert(is_same<_Tp, value_type>::value, "");
0161
0162 protected:
0163 container_type c;
0164
0165 public:
0166 _LIBCPP_HIDE_FROM_ABI stack() _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) : c() {}
0167
0168 _LIBCPP_HIDE_FROM_ABI stack(const stack& __q) : c(__q.c) {}
0169
0170 _LIBCPP_HIDE_FROM_ABI stack& operator=(const stack& __q) {
0171 c = __q.c;
0172 return *this;
0173 }
0174
0175 #ifndef _LIBCPP_CXX03_LANG
0176 _LIBCPP_HIDE_FROM_ABI stack(stack&& __q) noexcept(is_nothrow_move_constructible<container_type>::value)
0177 : c(std::move(__q.c)) {}
0178
0179 _LIBCPP_HIDE_FROM_ABI stack& operator=(stack&& __q) noexcept(is_nothrow_move_assignable<container_type>::value) {
0180 c = std::move(__q.c);
0181 return *this;
0182 }
0183
0184 _LIBCPP_HIDE_FROM_ABI explicit stack(container_type&& __c) : c(std::move(__c)) {}
0185 #endif // _LIBCPP_CXX03_LANG
0186
0187 _LIBCPP_HIDE_FROM_ABI explicit stack(const container_type& __c) : c(__c) {}
0188
0189 template <class _Alloc>
0190 _LIBCPP_HIDE_FROM_ABI explicit stack(const _Alloc& __a,
0191 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0192 : c(__a) {}
0193 template <class _Alloc>
0194 _LIBCPP_HIDE_FROM_ABI
0195 stack(const container_type& __c, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0196 : c(__c, __a) {}
0197 template <class _Alloc>
0198 _LIBCPP_HIDE_FROM_ABI
0199 stack(const stack& __s, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0200 : c(__s.c, __a) {}
0201 #ifndef _LIBCPP_CXX03_LANG
0202 template <class _Alloc>
0203 _LIBCPP_HIDE_FROM_ABI
0204 stack(container_type&& __c, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0205 : c(std::move(__c), __a) {}
0206 template <class _Alloc>
0207 _LIBCPP_HIDE_FROM_ABI
0208 stack(stack&& __s, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0209 : c(std::move(__s.c), __a) {}
0210 #endif // _LIBCPP_CXX03_LANG
0211
0212 #if _LIBCPP_STD_VER >= 23
0213 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
0214 _LIBCPP_HIDE_FROM_ABI stack(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
0215
0216 template <_ContainerCompatibleRange<_Tp> _Range>
0217 _LIBCPP_HIDE_FROM_ABI stack(from_range_t, _Range&& __range) : c(from_range, std::forward<_Range>(__range)) {}
0218
0219 template <class _InputIterator,
0220 class _Alloc,
0221 __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0,
0222 __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
0223 _LIBCPP_HIDE_FROM_ABI stack(_InputIterator __first, _InputIterator __last, const _Alloc& __alloc)
0224 : c(__first, __last, __alloc) {}
0225
0226 template <_ContainerCompatibleRange<_Tp> _Range,
0227 class _Alloc,
0228 __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
0229 _LIBCPP_HIDE_FROM_ABI stack(from_range_t, _Range&& __range, const _Alloc& __alloc)
0230 : c(from_range, std::forward<_Range>(__range), __alloc) {}
0231
0232 #endif
0233
0234 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
0235 _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
0236 _LIBCPP_HIDE_FROM_ABI reference top() { return c.back(); }
0237 _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.back(); }
0238
0239 _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); }
0240 #ifndef _LIBCPP_CXX03_LANG
0241 _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v) { c.push_back(std::move(__v)); }
0242
0243 # if _LIBCPP_STD_VER >= 23
0244 template <_ContainerCompatibleRange<_Tp> _Range>
0245 _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
0246 if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
0247 c.append_range(std::forward<_Range>(__range));
0248 } else {
0249 ranges::copy(std::forward<_Range>(__range), std::back_inserter(c));
0250 }
0251 }
0252 # endif
0253
0254 template <class... _Args>
0255 _LIBCPP_HIDE_FROM_ABI
0256 # if _LIBCPP_STD_VER >= 17
0257 decltype(auto)
0258 emplace(_Args&&... __args) {
0259 return c.emplace_back(std::forward<_Args>(__args)...);
0260 }
0261 # else
0262 void
0263 emplace(_Args&&... __args) {
0264 c.emplace_back(std::forward<_Args>(__args)...);
0265 }
0266 # endif
0267 #endif // _LIBCPP_CXX03_LANG
0268
0269 _LIBCPP_HIDE_FROM_ABI void pop() { c.pop_back(); }
0270
0271 _LIBCPP_HIDE_FROM_ABI void swap(stack& __s) _NOEXCEPT_(__is_nothrow_swappable_v<container_type>) {
0272 using std::swap;
0273 swap(c, __s.c);
0274 }
0275
0276 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
0277
0278 template <class _T1, class _OtherContainer>
0279 friend bool operator==(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
0280
0281 template <class _T1, class _OtherContainer>
0282 friend bool operator<(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
0283 };
0284
0285 #if _LIBCPP_STD_VER >= 17
0286 template <class _Container, class = enable_if_t<!__is_allocator<_Container>::value> >
0287 stack(_Container) -> stack<typename _Container::value_type, _Container>;
0288
0289 template <class _Container,
0290 class _Alloc,
0291 class = enable_if_t<!__is_allocator<_Container>::value>,
0292 class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
0293 stack(_Container, _Alloc) -> stack<typename _Container::value_type, _Container>;
0294 #endif
0295
0296 #if _LIBCPP_STD_VER >= 23
0297 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
0298 stack(_InputIterator, _InputIterator) -> stack<__iter_value_type<_InputIterator>>;
0299
0300 template <ranges::input_range _Range>
0301 stack(from_range_t, _Range&&) -> stack<ranges::range_value_t<_Range>>;
0302
0303 template <class _InputIterator,
0304 class _Alloc,
0305 __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0,
0306 __enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
0307 stack(_InputIterator,
0308 _InputIterator,
0309 _Alloc) -> stack<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
0310
0311 template <ranges::input_range _Range, class _Alloc, __enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
0312 stack(from_range_t,
0313 _Range&&,
0314 _Alloc) -> stack<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
0315
0316 #endif
0317
0318 template <class _Tp, class _Container>
0319 inline _LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0320 return __x.c == __y.c;
0321 }
0322
0323 template <class _Tp, class _Container>
0324 inline _LIBCPP_HIDE_FROM_ABI bool operator<(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0325 return __x.c < __y.c;
0326 }
0327
0328 template <class _Tp, class _Container>
0329 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0330 return !(__x == __y);
0331 }
0332
0333 template <class _Tp, class _Container>
0334 inline _LIBCPP_HIDE_FROM_ABI bool operator>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0335 return __y < __x;
0336 }
0337
0338 template <class _Tp, class _Container>
0339 inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0340 return !(__x < __y);
0341 }
0342
0343 template <class _Tp, class _Container>
0344 inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0345 return !(__y < __x);
0346 }
0347
0348 #if _LIBCPP_STD_VER >= 20
0349
0350 template <class _Tp, three_way_comparable _Container>
0351 _LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container>
0352 operator<=>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0353 // clang 16 bug: declaring `friend operator<=>` causes "use of overloaded operator '*' is ambiguous" errors
0354 return __x.__get_container() <=> __y.__get_container();
0355 }
0356
0357 #endif
0358
0359 template <class _Tp, class _Container, __enable_if_t<__is_swappable_v<_Container>, int> = 0>
0360 inline _LIBCPP_HIDE_FROM_ABI void swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
0361 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
0362 __x.swap(__y);
0363 }
0364
0365 template <class _Tp, class _Container, class _Alloc>
0366 struct _LIBCPP_TEMPLATE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {
0367 };
0368
0369 _LIBCPP_END_NAMESPACE_STD
0370
0371 _LIBCPP_POP_MACROS
0372
0373 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0374 # include <__cxx03/concepts>
0375 # include <__cxx03/functional>
0376 # include <__cxx03/type_traits>
0377 #endif
0378
0379 #endif // _LIBCPP___CXX03_STACK