1*700637cbSDimitry Andric// -*- C++ -*- 2*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 3*700637cbSDimitry Andric// 4*700637cbSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*700637cbSDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 6*700637cbSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*700637cbSDimitry Andric// 8*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 9*700637cbSDimitry Andric 10*700637cbSDimitry Andric#ifndef _LIBCPP___CXX03_STACK 11*700637cbSDimitry Andric#define _LIBCPP___CXX03_STACK 12*700637cbSDimitry Andric 13*700637cbSDimitry Andric/* 14*700637cbSDimitry Andric stack synopsis 15*700637cbSDimitry Andric 16*700637cbSDimitry Andricnamespace std 17*700637cbSDimitry Andric{ 18*700637cbSDimitry Andric 19*700637cbSDimitry Andrictemplate <class T, class Container = deque<T>> 20*700637cbSDimitry Andricclass stack 21*700637cbSDimitry Andric{ 22*700637cbSDimitry Andricpublic: 23*700637cbSDimitry Andric typedef Container container_type; 24*700637cbSDimitry Andric typedef typename container_type::value_type value_type; 25*700637cbSDimitry Andric typedef typename container_type::reference reference; 26*700637cbSDimitry Andric typedef typename container_type::const_reference const_reference; 27*700637cbSDimitry Andric typedef typename container_type::size_type size_type; 28*700637cbSDimitry Andric 29*700637cbSDimitry Andricprotected: 30*700637cbSDimitry Andric container_type c; 31*700637cbSDimitry Andric 32*700637cbSDimitry Andricpublic: 33*700637cbSDimitry Andric stack() = default; 34*700637cbSDimitry Andric ~stack() = default; 35*700637cbSDimitry Andric 36*700637cbSDimitry Andric stack(const stack& q) = default; 37*700637cbSDimitry Andric stack(stack&& q) = default; 38*700637cbSDimitry Andric 39*700637cbSDimitry Andric stack& operator=(const stack& q) = default; 40*700637cbSDimitry Andric stack& operator=(stack&& q) = default; 41*700637cbSDimitry Andric 42*700637cbSDimitry Andric explicit stack(const container_type& c); 43*700637cbSDimitry Andric explicit stack(container_type&& c); 44*700637cbSDimitry Andric template <class InputIterator> stack(InputIterator first, InputIterator last); // since C++23 45*700637cbSDimitry Andric template<container-compatible-range<T> R> stack(from_range_t, R&& rg); // since C++23 46*700637cbSDimitry Andric template <class Alloc> explicit stack(const Alloc& a); 47*700637cbSDimitry Andric template <class Alloc> stack(const container_type& c, const Alloc& a); 48*700637cbSDimitry Andric template <class Alloc> stack(container_type&& c, const Alloc& a); 49*700637cbSDimitry Andric template <class Alloc> stack(const stack& c, const Alloc& a); 50*700637cbSDimitry Andric template <class Alloc> stack(stack&& c, const Alloc& a); 51*700637cbSDimitry Andric template<class InputIterator, class Alloc> 52*700637cbSDimitry Andric stack(InputIterator first, InputIterator last, const Alloc&); // since C++23 53*700637cbSDimitry Andric template<container-compatible-range<T> R, class Alloc> 54*700637cbSDimitry Andric stack(from_range_t, R&& rg, const Alloc&); // since C++23 55*700637cbSDimitry Andric 56*700637cbSDimitry Andric bool empty() const; 57*700637cbSDimitry Andric size_type size() const; 58*700637cbSDimitry Andric reference top(); 59*700637cbSDimitry Andric const_reference top() const; 60*700637cbSDimitry Andric 61*700637cbSDimitry Andric void push(const value_type& x); 62*700637cbSDimitry Andric void push(value_type&& x); 63*700637cbSDimitry Andric template<container-compatible-range<T> R> 64*700637cbSDimitry Andric void push_range(R&& rg); // C++23 65*700637cbSDimitry Andric template <class... Args> reference emplace(Args&&... args); // reference in C++17 66*700637cbSDimitry Andric void pop(); 67*700637cbSDimitry Andric 68*700637cbSDimitry Andric void swap(stack& c) noexcept(is_nothrow_swappable_v<Container>) 69*700637cbSDimitry Andric}; 70*700637cbSDimitry Andric 71*700637cbSDimitry Andrictemplate<class Container> 72*700637cbSDimitry Andric stack(Container) -> stack<typename Container::value_type, Container>; // C++17 73*700637cbSDimitry Andric 74*700637cbSDimitry Andrictemplate<class InputIterator> 75*700637cbSDimitry Andric stack(InputIterator, InputIterator) -> stack<iter-value-type<InputIterator>>; // since C++23 76*700637cbSDimitry Andric 77*700637cbSDimitry Andrictemplate<ranges::input_range R> 78*700637cbSDimitry Andric stack(from_range_t, R&&) -> stack<ranges::range_value_t<R>>; // since C++23 79*700637cbSDimitry Andric 80*700637cbSDimitry Andrictemplate<class Container, class Allocator> 81*700637cbSDimitry Andric stack(Container, Allocator) -> stack<typename Container::value_type, Container>; // C++17 82*700637cbSDimitry Andric 83*700637cbSDimitry Andrictemplate<class InputIterator, class Allocator> 84*700637cbSDimitry Andric stack(InputIterator, InputIterator, Allocator) 85*700637cbSDimitry Andric -> stack<iter-value-type<InputIterator>, 86*700637cbSDimitry Andric deque<iter-value-type<InputIterator>, Allocator>>; // since C++23 87*700637cbSDimitry Andric 88*700637cbSDimitry Andrictemplate<ranges::input_range R, class Allocator> 89*700637cbSDimitry Andric stack(from_range_t, R&&, Allocator) 90*700637cbSDimitry Andric -> stack<ranges::range_value_t<R>, deque<ranges::range_value_t<R>, Allocator>>; // since C++23 91*700637cbSDimitry Andric 92*700637cbSDimitry Andrictemplate <class T, class Container> 93*700637cbSDimitry Andric bool operator==(const stack<T, Container>& x, const stack<T, Container>& y); 94*700637cbSDimitry Andrictemplate <class T, class Container> 95*700637cbSDimitry Andric bool operator< (const stack<T, Container>& x, const stack<T, Container>& y); 96*700637cbSDimitry Andrictemplate <class T, class Container> 97*700637cbSDimitry Andric bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y); 98*700637cbSDimitry Andrictemplate <class T, class Container> 99*700637cbSDimitry Andric bool operator> (const stack<T, Container>& x, const stack<T, Container>& y); 100*700637cbSDimitry Andrictemplate <class T, class Container> 101*700637cbSDimitry Andric bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y); 102*700637cbSDimitry Andrictemplate <class T, class Container> 103*700637cbSDimitry Andric bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y); 104*700637cbSDimitry Andrictemplate<class T, three_way_comparable Container> 105*700637cbSDimitry Andric compare_three_way_result_t<Container> 106*700637cbSDimitry Andric operator<=>(const stack<T, Container>& x, const stack<T, Container>& y); // since C++20 107*700637cbSDimitry Andric 108*700637cbSDimitry Andrictemplate <class T, class Container> 109*700637cbSDimitry Andric void swap(stack<T, Container>& x, stack<T, Container>& y) 110*700637cbSDimitry Andric noexcept(noexcept(x.swap(y))); 111*700637cbSDimitry Andric 112*700637cbSDimitry Andric} // std 113*700637cbSDimitry Andric 114*700637cbSDimitry Andric*/ 115*700637cbSDimitry Andric 116*700637cbSDimitry Andric#include <__cxx03/__config> 117*700637cbSDimitry Andric#include <__cxx03/__fwd/stack.h> 118*700637cbSDimitry Andric#include <__cxx03/__iterator/back_insert_iterator.h> 119*700637cbSDimitry Andric#include <__cxx03/__iterator/iterator_traits.h> 120*700637cbSDimitry Andric#include <__cxx03/__memory/uses_allocator.h> 121*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_same.h> 122*700637cbSDimitry Andric#include <__cxx03/__utility/forward.h> 123*700637cbSDimitry Andric#include <__cxx03/deque> 124*700637cbSDimitry Andric#include <__cxx03/version> 125*700637cbSDimitry Andric 126*700637cbSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 127*700637cbSDimitry Andric# pragma GCC system_header 128*700637cbSDimitry Andric#endif 129*700637cbSDimitry Andric 130*700637cbSDimitry Andric_LIBCPP_PUSH_MACROS 131*700637cbSDimitry Andric#include <__cxx03/__undef_macros> 132*700637cbSDimitry Andric 133*700637cbSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 134*700637cbSDimitry Andric 135*700637cbSDimitry Andrictemplate <class _Tp, class _Container> 136*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); 137*700637cbSDimitry Andric 138*700637cbSDimitry Andrictemplate <class _Tp, class _Container> 139*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator<(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); 140*700637cbSDimitry Andric 141*700637cbSDimitry Andrictemplate <class _Tp, class _Container /*= deque<_Tp>*/> 142*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS stack { 143*700637cbSDimitry Andricpublic: 144*700637cbSDimitry Andric typedef _Container container_type; 145*700637cbSDimitry Andric typedef typename container_type::value_type value_type; 146*700637cbSDimitry Andric typedef typename container_type::reference reference; 147*700637cbSDimitry Andric typedef typename container_type::const_reference const_reference; 148*700637cbSDimitry Andric typedef typename container_type::size_type size_type; 149*700637cbSDimitry Andric static_assert(is_same<_Tp, value_type>::value, ""); 150*700637cbSDimitry Andric 151*700637cbSDimitry Andricprotected: 152*700637cbSDimitry Andric container_type c; 153*700637cbSDimitry Andric 154*700637cbSDimitry Andricpublic: 155*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI stack() : c() {} 156*700637cbSDimitry Andric 157*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI stack(const stack& __q) : c(__q.c) {} 158*700637cbSDimitry Andric 159*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI stack& operator=(const stack& __q) { 160*700637cbSDimitry Andric c = __q.c; 161*700637cbSDimitry Andric return *this; 162*700637cbSDimitry Andric } 163*700637cbSDimitry Andric 164*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit stack(const container_type& __c) : c(__c) {} 165*700637cbSDimitry Andric 166*700637cbSDimitry Andric template <class _Alloc> 167*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit stack(const _Alloc& __a, 168*700637cbSDimitry Andric __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) 169*700637cbSDimitry Andric : c(__a) {} 170*700637cbSDimitry Andric template <class _Alloc> 171*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI 172*700637cbSDimitry Andric stack(const container_type& __c, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) 173*700637cbSDimitry Andric : c(__c, __a) {} 174*700637cbSDimitry Andric template <class _Alloc> 175*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI 176*700637cbSDimitry Andric stack(const stack& __s, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) 177*700637cbSDimitry Andric : c(__s.c, __a) {} 178*700637cbSDimitry Andric 179*700637cbSDimitry Andric _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); } 180*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); } 181*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI reference top() { return c.back(); } 182*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.back(); } 183*700637cbSDimitry Andric 184*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); } 185*700637cbSDimitry Andric 186*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void pop() { c.pop_back(); } 187*700637cbSDimitry Andric 188*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void swap(stack& __s) { 189*700637cbSDimitry Andric using std::swap; 190*700637cbSDimitry Andric swap(c, __s.c); 191*700637cbSDimitry Andric } 192*700637cbSDimitry Andric 193*700637cbSDimitry Andric _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; } 194*700637cbSDimitry Andric 195*700637cbSDimitry Andric template <class _T1, class _OtherContainer> 196*700637cbSDimitry Andric friend bool operator==(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y); 197*700637cbSDimitry Andric 198*700637cbSDimitry Andric template <class _T1, class _OtherContainer> 199*700637cbSDimitry Andric friend bool operator<(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y); 200*700637cbSDimitry Andric}; 201*700637cbSDimitry Andric 202*700637cbSDimitry Andrictemplate <class _Tp, class _Container> 203*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { 204*700637cbSDimitry Andric return __x.c == __y.c; 205*700637cbSDimitry Andric} 206*700637cbSDimitry Andric 207*700637cbSDimitry Andrictemplate <class _Tp, class _Container> 208*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { 209*700637cbSDimitry Andric return __x.c < __y.c; 210*700637cbSDimitry Andric} 211*700637cbSDimitry Andric 212*700637cbSDimitry Andrictemplate <class _Tp, class _Container> 213*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { 214*700637cbSDimitry Andric return !(__x == __y); 215*700637cbSDimitry Andric} 216*700637cbSDimitry Andric 217*700637cbSDimitry Andrictemplate <class _Tp, class _Container> 218*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { 219*700637cbSDimitry Andric return __y < __x; 220*700637cbSDimitry Andric} 221*700637cbSDimitry Andric 222*700637cbSDimitry Andrictemplate <class _Tp, class _Container> 223*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { 224*700637cbSDimitry Andric return !(__x < __y); 225*700637cbSDimitry Andric} 226*700637cbSDimitry Andric 227*700637cbSDimitry Andrictemplate <class _Tp, class _Container> 228*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { 229*700637cbSDimitry Andric return !(__y < __x); 230*700637cbSDimitry Andric} 231*700637cbSDimitry Andric 232*700637cbSDimitry Andrictemplate <class _Tp, class _Container, __enable_if_t<__is_swappable_v<_Container>, int> = 0> 233*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y) { 234*700637cbSDimitry Andric __x.swap(__y); 235*700637cbSDimitry Andric} 236*700637cbSDimitry Andric 237*700637cbSDimitry Andrictemplate <class _Tp, class _Container, class _Alloc> 238*700637cbSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> { 239*700637cbSDimitry Andric}; 240*700637cbSDimitry Andric 241*700637cbSDimitry Andric_LIBCPP_END_NAMESPACE_STD 242*700637cbSDimitry Andric 243*700637cbSDimitry Andric_LIBCPP_POP_MACROS 244*700637cbSDimitry Andric 245*700637cbSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) 246*700637cbSDimitry Andric# include <__cxx03/functional> 247*700637cbSDimitry Andric# include <__cxx03/type_traits> 248*700637cbSDimitry Andric#endif 249*700637cbSDimitry Andric 250*700637cbSDimitry Andric#endif // _LIBCPP___CXX03_STACK 251