10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_STACK 110b57cec5SDimitry Andric#define _LIBCPP_STACK 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric stack synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andrictemplate <class T, class Container = deque<T>> 200b57cec5SDimitry Andricclass stack 210b57cec5SDimitry Andric{ 220b57cec5SDimitry Andricpublic: 230b57cec5SDimitry Andric typedef Container container_type; 240b57cec5SDimitry Andric typedef typename container_type::value_type value_type; 250b57cec5SDimitry Andric typedef typename container_type::reference reference; 260b57cec5SDimitry Andric typedef typename container_type::const_reference const_reference; 270b57cec5SDimitry Andric typedef typename container_type::size_type size_type; 280b57cec5SDimitry Andric 290b57cec5SDimitry Andricprotected: 300b57cec5SDimitry Andric container_type c; 310b57cec5SDimitry Andric 320b57cec5SDimitry Andricpublic: 330b57cec5SDimitry Andric stack() = default; 340b57cec5SDimitry Andric ~stack() = default; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric stack(const stack& q) = default; 370b57cec5SDimitry Andric stack(stack&& q) = default; 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric stack& operator=(const stack& q) = default; 400b57cec5SDimitry Andric stack& operator=(stack&& q) = default; 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric explicit stack(const container_type& c); 430b57cec5SDimitry Andric explicit stack(container_type&& c); 4404eeddc0SDimitry Andric template <class InputIterator> stack(InputIterator first, InputIterator last); // since C++23 45*06c3fb27SDimitry Andric template<container-compatible-range<T> R> stack(from_range_t, R&& rg); // since C++23 460b57cec5SDimitry Andric template <class Alloc> explicit stack(const Alloc& a); 470b57cec5SDimitry Andric template <class Alloc> stack(const container_type& c, const Alloc& a); 480b57cec5SDimitry Andric template <class Alloc> stack(container_type&& c, const Alloc& a); 490b57cec5SDimitry Andric template <class Alloc> stack(const stack& c, const Alloc& a); 500b57cec5SDimitry Andric template <class Alloc> stack(stack&& c, const Alloc& a); 5104eeddc0SDimitry Andric template<class InputIterator, class Alloc> 5204eeddc0SDimitry Andric stack(InputIterator first, InputIterator last, const Alloc&); // since C++23 53*06c3fb27SDimitry Andric template<container-compatible-range<T> R, class Alloc> 54*06c3fb27SDimitry Andric stack(from_range_t, R&& rg, const Alloc&); // since C++23 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric bool empty() const; 570b57cec5SDimitry Andric size_type size() const; 580b57cec5SDimitry Andric reference top(); 590b57cec5SDimitry Andric const_reference top() const; 600b57cec5SDimitry Andric 610b57cec5SDimitry Andric void push(const value_type& x); 620b57cec5SDimitry Andric void push(value_type&& x); 63*06c3fb27SDimitry Andric template<container-compatible-range<T> R> 64*06c3fb27SDimitry Andric void push_range(R&& rg); // C++23 650b57cec5SDimitry Andric template <class... Args> reference emplace(Args&&... args); // reference in C++17 660b57cec5SDimitry Andric void pop(); 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric void swap(stack& c) noexcept(is_nothrow_swappable_v<Container>) 690b57cec5SDimitry Andric}; 700b57cec5SDimitry Andric 710b57cec5SDimitry Andrictemplate<class Container> 720b57cec5SDimitry Andric stack(Container) -> stack<typename Container::value_type, Container>; // C++17 730b57cec5SDimitry Andric 7404eeddc0SDimitry Andrictemplate<class InputIterator> 7504eeddc0SDimitry Andric stack(InputIterator, InputIterator) -> stack<iter-value-type<InputIterator>>; // since C++23 7604eeddc0SDimitry Andric 77*06c3fb27SDimitry Andrictemplate<ranges::input_range R> 78*06c3fb27SDimitry Andric stack(from_range_t, R&&) -> stack<ranges::range_value_t<R>>; // since C++23 79*06c3fb27SDimitry Andric 800b57cec5SDimitry Andrictemplate<class Container, class Allocator> 810b57cec5SDimitry Andric stack(Container, Allocator) -> stack<typename Container::value_type, Container>; // C++17 820b57cec5SDimitry Andric 8304eeddc0SDimitry Andrictemplate<class InputIterator, class Allocator> 8404eeddc0SDimitry Andric stack(InputIterator, InputIterator, Allocator) 8504eeddc0SDimitry Andric -> stack<iter-value-type<InputIterator>, 8604eeddc0SDimitry Andric deque<iter-value-type<InputIterator>, Allocator>>; // since C++23 8704eeddc0SDimitry Andric 88*06c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator> 89*06c3fb27SDimitry Andric stack(from_range_t, R&&, Allocator) 90*06c3fb27SDimitry Andric -> stack<ranges::range_value_t<R>, deque<ranges::range_value_t<R>, Allocator>>; // since C++23 91*06c3fb27SDimitry Andric 920b57cec5SDimitry Andrictemplate <class T, class Container> 930b57cec5SDimitry Andric bool operator==(const stack<T, Container>& x, const stack<T, Container>& y); 940b57cec5SDimitry Andrictemplate <class T, class Container> 950b57cec5SDimitry Andric bool operator< (const stack<T, Container>& x, const stack<T, Container>& y); 960b57cec5SDimitry Andrictemplate <class T, class Container> 970b57cec5SDimitry Andric bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y); 980b57cec5SDimitry Andrictemplate <class T, class Container> 990b57cec5SDimitry Andric bool operator> (const stack<T, Container>& x, const stack<T, Container>& y); 1000b57cec5SDimitry Andrictemplate <class T, class Container> 1010b57cec5SDimitry Andric bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y); 1020b57cec5SDimitry Andrictemplate <class T, class Container> 1030b57cec5SDimitry Andric bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y); 104*06c3fb27SDimitry Andrictemplate<class T, three_way_comparable Container> 105*06c3fb27SDimitry Andric compare_three_way_result_t<Container> 106*06c3fb27SDimitry Andric operator<=>(const stack<T, Container>& x, const stack<T, Container>& y); // since C++20 1070b57cec5SDimitry Andric 1080b57cec5SDimitry Andrictemplate <class T, class Container> 1090b57cec5SDimitry Andric void swap(stack<T, Container>& x, stack<T, Container>& y) 1100b57cec5SDimitry Andric noexcept(noexcept(x.swap(y))); 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric} // std 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric*/ 1150b57cec5SDimitry Andric 116*06c3fb27SDimitry Andric#include <__algorithm/ranges_copy.h> 11781ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 1180b57cec5SDimitry Andric#include <__config> 119*06c3fb27SDimitry Andric#include <__iterator/back_insert_iterator.h> 12004eeddc0SDimitry Andric#include <__iterator/iterator_traits.h> 121fe6060f1SDimitry Andric#include <__memory/uses_allocator.h> 122*06c3fb27SDimitry Andric#include <__ranges/access.h> 123*06c3fb27SDimitry Andric#include <__ranges/concepts.h> 124*06c3fb27SDimitry Andric#include <__ranges/container_compatible_range.h> 125*06c3fb27SDimitry Andric#include <__ranges/from_range.h> 126*06c3fb27SDimitry Andric#include <__type_traits/is_same.h> 127fe6060f1SDimitry Andric#include <__utility/forward.h> 1280b57cec5SDimitry Andric#include <deque> 12904eeddc0SDimitry Andric#include <version> 1300b57cec5SDimitry Andric 13181ad6265SDimitry Andric// standard-mandated includes 132bdd1243dSDimitry Andric 133bdd1243dSDimitry Andric// [stack.syn] 13481ad6265SDimitry Andric#include <compare> 13581ad6265SDimitry Andric#include <initializer_list> 13681ad6265SDimitry Andric 1370b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1380b57cec5SDimitry Andric# pragma GCC system_header 1390b57cec5SDimitry Andric#endif 1400b57cec5SDimitry Andric 1410b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andrictemplate <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS stack; 1440b57cec5SDimitry Andric 1450b57cec5SDimitry Andrictemplate <class _Tp, class _Container> 1460b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 1470b57cec5SDimitry Andricbool 1480b57cec5SDimitry Andricoperator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); 1490b57cec5SDimitry Andric 1500b57cec5SDimitry Andrictemplate <class _Tp, class _Container> 1510b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 1520b57cec5SDimitry Andricbool 1530b57cec5SDimitry Andricoperator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andrictemplate <class _Tp, class _Container /*= deque<_Tp>*/> 1560b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS stack 1570b57cec5SDimitry Andric{ 1580b57cec5SDimitry Andricpublic: 1590b57cec5SDimitry Andric typedef _Container container_type; 1600b57cec5SDimitry Andric typedef typename container_type::value_type value_type; 1610b57cec5SDimitry Andric typedef typename container_type::reference reference; 1620b57cec5SDimitry Andric typedef typename container_type::const_reference const_reference; 1630b57cec5SDimitry Andric typedef typename container_type::size_type size_type; 1640b57cec5SDimitry Andric static_assert((is_same<_Tp, value_type>::value), "" ); 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andricprotected: 1670b57cec5SDimitry Andric container_type c; 1680b57cec5SDimitry Andric 1690b57cec5SDimitry Andricpublic: 1700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1710b57cec5SDimitry Andric stack() 1720b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) 1730b57cec5SDimitry Andric : c() {} 1740b57cec5SDimitry Andric 1750b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1760b57cec5SDimitry Andric stack(const stack& __q) : c(__q.c) {} 1770b57cec5SDimitry Andric 1780b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1790b57cec5SDimitry Andric stack& operator=(const stack& __q) {c = __q.c; return *this;} 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric 1820b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1840b57cec5SDimitry Andric stack(stack&& __q) 1850b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value) 1860b57cec5SDimitry Andric : c(_VSTD::move(__q.c)) {} 1870b57cec5SDimitry Andric 1880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1890b57cec5SDimitry Andric stack& operator=(stack&& __q) 1900b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) 1910b57cec5SDimitry Andric {c = _VSTD::move(__q.c); return *this;} 1920b57cec5SDimitry Andric 1930b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1940b57cec5SDimitry Andric explicit stack(container_type&& __c) : c(_VSTD::move(__c)) {} 1950b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1980b57cec5SDimitry Andric explicit stack(const container_type& __c) : c(__c) {} 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andric template <class _Alloc> 2010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2020b57cec5SDimitry Andric explicit stack(const _Alloc& __a, 203349cc55cSDimitry Andric __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) 2040b57cec5SDimitry Andric : c(__a) {} 2050b57cec5SDimitry Andric template <class _Alloc> 2060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2070b57cec5SDimitry Andric stack(const container_type& __c, const _Alloc& __a, 208349cc55cSDimitry Andric __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) 2090b57cec5SDimitry Andric : c(__c, __a) {} 2100b57cec5SDimitry Andric template <class _Alloc> 2110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2120b57cec5SDimitry Andric stack(const stack& __s, const _Alloc& __a, 213349cc55cSDimitry Andric __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) 2140b57cec5SDimitry Andric : c(__s.c, __a) {} 2150b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2160b57cec5SDimitry Andric template <class _Alloc> 2170b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2180b57cec5SDimitry Andric stack(container_type&& __c, const _Alloc& __a, 219349cc55cSDimitry Andric __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) 2200b57cec5SDimitry Andric : c(_VSTD::move(__c), __a) {} 2210b57cec5SDimitry Andric template <class _Alloc> 2220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2230b57cec5SDimitry Andric stack(stack&& __s, const _Alloc& __a, 224349cc55cSDimitry Andric __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0) 2250b57cec5SDimitry Andric : c(_VSTD::move(__s.c), __a) {} 2260b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 2270b57cec5SDimitry Andric 228*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 22904eeddc0SDimitry Andric template <class _InputIterator, 230*06c3fb27SDimitry Andric class = __enable_if_t<__has_input_iterator_category<_InputIterator>::value>> 23104eeddc0SDimitry Andric _LIBCPP_HIDE_FROM_ABI 23204eeddc0SDimitry Andric stack(_InputIterator __first, _InputIterator __last) : c(__first, __last) {} 23304eeddc0SDimitry Andric 234*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 235*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 236*06c3fb27SDimitry Andric stack(from_range_t, _Range&& __range) : c(from_range, std::forward<_Range>(__range)) {} 237*06c3fb27SDimitry Andric 23804eeddc0SDimitry Andric template <class _InputIterator, 23904eeddc0SDimitry Andric class _Alloc, 240*06c3fb27SDimitry Andric class = __enable_if_t<__has_input_iterator_category<_InputIterator>::value>, 24104eeddc0SDimitry Andric class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>> 24204eeddc0SDimitry Andric _LIBCPP_HIDE_FROM_ABI 24304eeddc0SDimitry Andric stack(_InputIterator __first, _InputIterator __last, const _Alloc& __alloc) : c(__first, __last, __alloc) {} 244*06c3fb27SDimitry Andric 245*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range, 246*06c3fb27SDimitry Andric class _Alloc, 247*06c3fb27SDimitry Andric class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>> 248*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 249*06c3fb27SDimitry Andric stack(from_range_t, _Range&& __range, const _Alloc& __alloc) 250*06c3fb27SDimitry Andric : c(from_range, std::forward<_Range>(__range), __alloc) {} 251*06c3fb27SDimitry Andric 25204eeddc0SDimitry Andric#endif 25304eeddc0SDimitry Andric 2540b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 2550b57cec5SDimitry Andric bool empty() const {return c.empty();} 2560b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2570b57cec5SDimitry Andric size_type size() const {return c.size();} 2580b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2590b57cec5SDimitry Andric reference top() {return c.back();} 2600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2610b57cec5SDimitry Andric const_reference top() const {return c.back();} 2620b57cec5SDimitry Andric 2630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2640b57cec5SDimitry Andric void push(const value_type& __v) {c.push_back(__v);} 2650b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2670b57cec5SDimitry Andric void push(value_type&& __v) {c.push_back(_VSTD::move(__v));} 2680b57cec5SDimitry Andric 269*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 270*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 271*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 272*06c3fb27SDimitry Andric void push_range(_Range&& __range) { 273*06c3fb27SDimitry Andric if constexpr (requires (container_type& __c) { 274*06c3fb27SDimitry Andric __c.append_range(std::forward<_Range>(__range)); 275*06c3fb27SDimitry Andric }) { 276*06c3fb27SDimitry Andric c.append_range(std::forward<_Range>(__range)); 277*06c3fb27SDimitry Andric } else { 278*06c3fb27SDimitry Andric ranges::copy(std::forward<_Range>(__range), std::back_inserter(c)); 279*06c3fb27SDimitry Andric } 280*06c3fb27SDimitry Andric } 281*06c3fb27SDimitry Andric#endif 282*06c3fb27SDimitry Andric 2830b57cec5SDimitry Andric template <class... _Args> 2840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 285*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 2860b57cec5SDimitry Andric decltype(auto) emplace(_Args&&... __args) 2870b57cec5SDimitry Andric { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} 2880b57cec5SDimitry Andric#else 2890b57cec5SDimitry Andric void emplace(_Args&&... __args) 2900b57cec5SDimitry Andric { c.emplace_back(_VSTD::forward<_Args>(__args)...);} 2910b57cec5SDimitry Andric#endif 2920b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 2930b57cec5SDimitry Andric 2940b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2950b57cec5SDimitry Andric void pop() {c.pop_back();} 2960b57cec5SDimitry Andric 2970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2980b57cec5SDimitry Andric void swap(stack& __s) 2990b57cec5SDimitry Andric _NOEXCEPT_(__is_nothrow_swappable<container_type>::value) 3000b57cec5SDimitry Andric { 3010b57cec5SDimitry Andric using _VSTD::swap; 3020b57cec5SDimitry Andric swap(c, __s.c); 3030b57cec5SDimitry Andric } 3040b57cec5SDimitry Andric 305bdd1243dSDimitry Andric _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; } 306bdd1243dSDimitry Andric 307*06c3fb27SDimitry Andric template <class _T1, class _OtherContainer> 3080b57cec5SDimitry Andric friend 3090b57cec5SDimitry Andric bool 310*06c3fb27SDimitry Andric operator==(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y); 3110b57cec5SDimitry Andric 312*06c3fb27SDimitry Andric template <class _T1, class _OtherContainer> 3130b57cec5SDimitry Andric friend 3140b57cec5SDimitry Andric bool 315*06c3fb27SDimitry Andric operator< (const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y); 3160b57cec5SDimitry Andric}; 3170b57cec5SDimitry Andric 318*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 3190b57cec5SDimitry Andrictemplate<class _Container, 320349cc55cSDimitry Andric class = enable_if_t<!__is_allocator<_Container>::value> 3210b57cec5SDimitry Andric> 3220b57cec5SDimitry Andricstack(_Container) 3230b57cec5SDimitry Andric -> stack<typename _Container::value_type, _Container>; 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andrictemplate<class _Container, 3260b57cec5SDimitry Andric class _Alloc, 327349cc55cSDimitry Andric class = enable_if_t<!__is_allocator<_Container>::value>, 328349cc55cSDimitry Andric class = enable_if_t<uses_allocator<_Container, _Alloc>::value> 3290b57cec5SDimitry Andric > 3300b57cec5SDimitry Andricstack(_Container, _Alloc) 3310b57cec5SDimitry Andric -> stack<typename _Container::value_type, _Container>; 3320b57cec5SDimitry Andric#endif 3330b57cec5SDimitry Andric 334*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 33504eeddc0SDimitry Andrictemplate<class _InputIterator, 336*06c3fb27SDimitry Andric class = __enable_if_t<__has_input_iterator_category<_InputIterator>::value>> 33704eeddc0SDimitry Andricstack(_InputIterator, _InputIterator) 33804eeddc0SDimitry Andric -> stack<__iter_value_type<_InputIterator>>; 33904eeddc0SDimitry Andric 340*06c3fb27SDimitry Andrictemplate <ranges::input_range _Range> 341*06c3fb27SDimitry Andricstack(from_range_t, _Range&&) -> stack<ranges::range_value_t<_Range>>; 342*06c3fb27SDimitry Andric 34304eeddc0SDimitry Andrictemplate<class _InputIterator, 34404eeddc0SDimitry Andric class _Alloc, 345*06c3fb27SDimitry Andric class = __enable_if_t<__has_input_iterator_category<_InputIterator>::value>, 34604eeddc0SDimitry Andric class = __enable_if_t<__is_allocator<_Alloc>::value>> 34704eeddc0SDimitry Andricstack(_InputIterator, _InputIterator, _Alloc) 34804eeddc0SDimitry Andric -> stack<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>; 349*06c3fb27SDimitry Andric 350*06c3fb27SDimitry Andrictemplate <ranges::input_range _Range, 351*06c3fb27SDimitry Andric class _Alloc, 352*06c3fb27SDimitry Andric class = __enable_if_t<__is_allocator<_Alloc>::value>> 353*06c3fb27SDimitry Andricstack(from_range_t, _Range&&, _Alloc) 354*06c3fb27SDimitry Andric -> stack<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>; 355*06c3fb27SDimitry Andric 35604eeddc0SDimitry Andric#endif 35704eeddc0SDimitry Andric 3580b57cec5SDimitry Andrictemplate <class _Tp, class _Container> 3590b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3600b57cec5SDimitry Andricbool 3610b57cec5SDimitry Andricoperator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 3620b57cec5SDimitry Andric{ 3630b57cec5SDimitry Andric return __x.c == __y.c; 3640b57cec5SDimitry Andric} 3650b57cec5SDimitry Andric 3660b57cec5SDimitry Andrictemplate <class _Tp, class _Container> 3670b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3680b57cec5SDimitry Andricbool 3690b57cec5SDimitry Andricoperator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 3700b57cec5SDimitry Andric{ 3710b57cec5SDimitry Andric return __x.c < __y.c; 3720b57cec5SDimitry Andric} 3730b57cec5SDimitry Andric 3740b57cec5SDimitry Andrictemplate <class _Tp, class _Container> 3750b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3760b57cec5SDimitry Andricbool 3770b57cec5SDimitry Andricoperator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 3780b57cec5SDimitry Andric{ 3790b57cec5SDimitry Andric return !(__x == __y); 3800b57cec5SDimitry Andric} 3810b57cec5SDimitry Andric 3820b57cec5SDimitry Andrictemplate <class _Tp, class _Container> 3830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3840b57cec5SDimitry Andricbool 3850b57cec5SDimitry Andricoperator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 3860b57cec5SDimitry Andric{ 3870b57cec5SDimitry Andric return __y < __x; 3880b57cec5SDimitry Andric} 3890b57cec5SDimitry Andric 3900b57cec5SDimitry Andrictemplate <class _Tp, class _Container> 3910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3920b57cec5SDimitry Andricbool 3930b57cec5SDimitry Andricoperator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 3940b57cec5SDimitry Andric{ 3950b57cec5SDimitry Andric return !(__x < __y); 3960b57cec5SDimitry Andric} 3970b57cec5SDimitry Andric 3980b57cec5SDimitry Andrictemplate <class _Tp, class _Container> 3990b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4000b57cec5SDimitry Andricbool 4010b57cec5SDimitry Andricoperator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 4020b57cec5SDimitry Andric{ 4030b57cec5SDimitry Andric return !(__y < __x); 4040b57cec5SDimitry Andric} 4050b57cec5SDimitry Andric 406*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 407*06c3fb27SDimitry Andric 408*06c3fb27SDimitry Andrictemplate <class _Tp, three_way_comparable _Container> 409*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container> 410*06c3fb27SDimitry Andricoperator<=>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { 411*06c3fb27SDimitry Andric // clang 16 bug: declaring `friend operator<=>` causes "use of overloaded operator '*' is ambiguous" errors 412*06c3fb27SDimitry Andric return __x.__get_container() <=> __y.__get_container(); 413*06c3fb27SDimitry Andric} 414*06c3fb27SDimitry Andric 415*06c3fb27SDimitry Andric#endif 416*06c3fb27SDimitry Andric 4170b57cec5SDimitry Andrictemplate <class _Tp, class _Container> 4180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 419349cc55cSDimitry Andric__enable_if_t<__is_swappable<_Container>::value, void> 4200b57cec5SDimitry Andricswap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y) 4210b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 4220b57cec5SDimitry Andric{ 4230b57cec5SDimitry Andric __x.swap(__y); 4240b57cec5SDimitry Andric} 4250b57cec5SDimitry Andric 4260b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Alloc> 4270b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc> 4280b57cec5SDimitry Andric : public uses_allocator<_Container, _Alloc> 4290b57cec5SDimitry Andric{ 4300b57cec5SDimitry Andric}; 4310b57cec5SDimitry Andric 4320b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 4330b57cec5SDimitry Andric 434bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 435bdd1243dSDimitry Andric# include <concepts> 436bdd1243dSDimitry Andric# include <functional> 437*06c3fb27SDimitry Andric# include <type_traits> 438bdd1243dSDimitry Andric#endif 439bdd1243dSDimitry Andric 4400b57cec5SDimitry Andric#endif // _LIBCPP_STACK 441