Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/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_STACK
0011 #define _LIBCPP_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 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0117 #  include <__cxx03/stack>
0118 #else
0119 #  include <__algorithm/ranges_copy.h>
0120 #  include <__config>
0121 #  include <__fwd/stack.h>
0122 #  include <__iterator/back_insert_iterator.h>
0123 #  include <__iterator/iterator_traits.h>
0124 #  include <__memory/uses_allocator.h>
0125 #  include <__ranges/access.h>
0126 #  include <__ranges/concepts.h>
0127 #  include <__ranges/container_compatible_range.h>
0128 #  include <__ranges/from_range.h>
0129 #  include <__type_traits/is_same.h>
0130 #  include <__utility/forward.h>
0131 #  include <deque>
0132 #  include <version>
0133 
0134 // standard-mandated includes
0135 
0136 // [stack.syn]
0137 #  include <compare>
0138 #  include <initializer_list>
0139 
0140 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0141 #    pragma GCC system_header
0142 #  endif
0143 
0144 _LIBCPP_PUSH_MACROS
0145 #  include <__undef_macros>
0146 
0147 _LIBCPP_BEGIN_NAMESPACE_STD
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>
0153 _LIBCPP_HIDE_FROM_ABI bool operator<(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
0154 
0155 template <class _Tp, class _Container /*= deque<_Tp>*/>
0156 class _LIBCPP_TEMPLATE_VIS stack {
0157 public:
0158   typedef _Container container_type;
0159   typedef typename container_type::value_type value_type;
0160   typedef typename container_type::reference reference;
0161   typedef typename container_type::const_reference const_reference;
0162   typedef typename container_type::size_type size_type;
0163   static_assert(is_same<_Tp, value_type>::value, "");
0164 
0165 protected:
0166   container_type c;
0167 
0168 public:
0169   _LIBCPP_HIDE_FROM_ABI stack() _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) : c() {}
0170 
0171   _LIBCPP_HIDE_FROM_ABI stack(const stack& __q) : c(__q.c) {}
0172 
0173   _LIBCPP_HIDE_FROM_ABI stack& operator=(const stack& __q) {
0174     c = __q.c;
0175     return *this;
0176   }
0177 
0178 #  ifndef _LIBCPP_CXX03_LANG
0179   _LIBCPP_HIDE_FROM_ABI stack(stack&& __q) noexcept(is_nothrow_move_constructible<container_type>::value)
0180       : c(std::move(__q.c)) {}
0181 
0182   _LIBCPP_HIDE_FROM_ABI stack& operator=(stack&& __q) noexcept(is_nothrow_move_assignable<container_type>::value) {
0183     c = std::move(__q.c);
0184     return *this;
0185   }
0186 
0187   _LIBCPP_HIDE_FROM_ABI explicit stack(container_type&& __c) : c(std::move(__c)) {}
0188 #  endif // _LIBCPP_CXX03_LANG
0189 
0190   _LIBCPP_HIDE_FROM_ABI explicit stack(const container_type& __c) : c(__c) {}
0191 
0192   template <class _Alloc>
0193   _LIBCPP_HIDE_FROM_ABI explicit stack(const _Alloc& __a,
0194                                        __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0195       : c(__a) {}
0196   template <class _Alloc>
0197   _LIBCPP_HIDE_FROM_ABI
0198   stack(const container_type& __c, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0199       : c(__c, __a) {}
0200   template <class _Alloc>
0201   _LIBCPP_HIDE_FROM_ABI
0202   stack(const stack& __s, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0203       : c(__s.c, __a) {}
0204 #  ifndef _LIBCPP_CXX03_LANG
0205   template <class _Alloc>
0206   _LIBCPP_HIDE_FROM_ABI
0207   stack(container_type&& __c, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0208       : c(std::move(__c), __a) {}
0209   template <class _Alloc>
0210   _LIBCPP_HIDE_FROM_ABI
0211   stack(stack&& __s, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
0212       : c(std::move(__s.c), __a) {}
0213 #  endif // _LIBCPP_CXX03_LANG
0214 
0215 #  if _LIBCPP_STD_VER >= 23
0216   template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
0217   _LIBCPP_HIDE_FROM_ABI stack(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
0218 
0219   template <_ContainerCompatibleRange<_Tp> _Range>
0220   _LIBCPP_HIDE_FROM_ABI stack(from_range_t, _Range&& __range) : c(from_range, std::forward<_Range>(__range)) {}
0221 
0222   template <class _InputIterator,
0223             class _Alloc,
0224             __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0,
0225             __enable_if_t<uses_allocator<container_type, _Alloc>::value, int>        = 0>
0226   _LIBCPP_HIDE_FROM_ABI stack(_InputIterator __first, _InputIterator __last, const _Alloc& __alloc)
0227       : c(__first, __last, __alloc) {}
0228 
0229   template <_ContainerCompatibleRange<_Tp> _Range,
0230             class _Alloc,
0231             __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
0232   _LIBCPP_HIDE_FROM_ABI stack(from_range_t, _Range&& __range, const _Alloc& __alloc)
0233       : c(from_range, std::forward<_Range>(__range), __alloc) {}
0234 
0235 #  endif
0236 
0237   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
0238   _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
0239   _LIBCPP_HIDE_FROM_ABI reference top() { return c.back(); }
0240   _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.back(); }
0241 
0242   _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); }
0243 #  ifndef _LIBCPP_CXX03_LANG
0244   _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v) { c.push_back(std::move(__v)); }
0245 
0246 #    if _LIBCPP_STD_VER >= 23
0247   template <_ContainerCompatibleRange<_Tp> _Range>
0248   _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
0249     if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
0250       c.append_range(std::forward<_Range>(__range));
0251     } else {
0252       ranges::copy(std::forward<_Range>(__range), std::back_inserter(c));
0253     }
0254   }
0255 #    endif
0256 
0257   template <class... _Args>
0258   _LIBCPP_HIDE_FROM_ABI
0259 #    if _LIBCPP_STD_VER >= 17
0260   decltype(auto)
0261   emplace(_Args&&... __args) {
0262     return c.emplace_back(std::forward<_Args>(__args)...);
0263   }
0264 #    else
0265   void
0266   emplace(_Args&&... __args) {
0267     c.emplace_back(std::forward<_Args>(__args)...);
0268   }
0269 #    endif
0270 #  endif // _LIBCPP_CXX03_LANG
0271 
0272   _LIBCPP_HIDE_FROM_ABI void pop() { c.pop_back(); }
0273 
0274   _LIBCPP_HIDE_FROM_ABI void swap(stack& __s) _NOEXCEPT_(__is_nothrow_swappable_v<container_type>) {
0275     using std::swap;
0276     swap(c, __s.c);
0277   }
0278 
0279   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
0280 
0281   template <class _T1, class _OtherContainer>
0282   friend bool operator==(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
0283 
0284   template <class _T1, class _OtherContainer>
0285   friend bool operator<(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
0286 };
0287 
0288 #  if _LIBCPP_STD_VER >= 17
0289 template <class _Container, class = enable_if_t<!__is_allocator<_Container>::value> >
0290 stack(_Container) -> stack<typename _Container::value_type, _Container>;
0291 
0292 template <class _Container,
0293           class _Alloc,
0294           class = enable_if_t<!__is_allocator<_Container>::value>,
0295           class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
0296 stack(_Container, _Alloc) -> stack<typename _Container::value_type, _Container>;
0297 #  endif
0298 
0299 #  if _LIBCPP_STD_VER >= 23
0300 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
0301 stack(_InputIterator, _InputIterator) -> stack<__iter_value_type<_InputIterator>>;
0302 
0303 template <ranges::input_range _Range>
0304 stack(from_range_t, _Range&&) -> stack<ranges::range_value_t<_Range>>;
0305 
0306 template <class _InputIterator,
0307           class _Alloc,
0308           __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0,
0309           __enable_if_t<__is_allocator<_Alloc>::value, int>                        = 0>
0310 stack(_InputIterator,
0311       _InputIterator,
0312       _Alloc) -> stack<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
0313 
0314 template <ranges::input_range _Range, class _Alloc, __enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
0315 stack(from_range_t,
0316       _Range&&,
0317       _Alloc) -> stack<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
0318 
0319 #  endif
0320 
0321 template <class _Tp, class _Container>
0322 inline _LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0323   return __x.c == __y.c;
0324 }
0325 
0326 template <class _Tp, class _Container>
0327 inline _LIBCPP_HIDE_FROM_ABI bool operator<(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0328   return __x.c < __y.c;
0329 }
0330 
0331 template <class _Tp, class _Container>
0332 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0333   return !(__x == __y);
0334 }
0335 
0336 template <class _Tp, class _Container>
0337 inline _LIBCPP_HIDE_FROM_ABI bool operator>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0338   return __y < __x;
0339 }
0340 
0341 template <class _Tp, class _Container>
0342 inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0343   return !(__x < __y);
0344 }
0345 
0346 template <class _Tp, class _Container>
0347 inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0348   return !(__y < __x);
0349 }
0350 
0351 #  if _LIBCPP_STD_VER >= 20
0352 
0353 template <class _Tp, three_way_comparable _Container>
0354 _LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container>
0355 operator<=>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
0356   // clang 16 bug: declaring `friend operator<=>` causes "use of overloaded operator '*' is ambiguous" errors
0357   return __x.__get_container() <=> __y.__get_container();
0358 }
0359 
0360 #  endif
0361 
0362 template <class _Tp, class _Container, __enable_if_t<__is_swappable_v<_Container>, int> = 0>
0363 inline _LIBCPP_HIDE_FROM_ABI void swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
0364     _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
0365   __x.swap(__y);
0366 }
0367 
0368 template <class _Tp, class _Container, class _Alloc>
0369 struct _LIBCPP_TEMPLATE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {
0370 };
0371 
0372 _LIBCPP_END_NAMESPACE_STD
0373 
0374 _LIBCPP_POP_MACROS
0375 
0376 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0377 #    include <concepts>
0378 #    include <functional>
0379 #    include <type_traits>
0380 #  endif
0381 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0382 
0383 #endif // _LIBCPP_STACK