[stack] (original) (raw)
23.6.6.1 General [stack.general]
Any sequence container supporting operationsback(),push_back()andpop_back()can be used to instantiatestack.
23.6.6.2 Definition [stack.defn]
namespace std { template<class T, class Container = deque<T>> class stack { public: using value_type = typename Container::value_type;using reference = typename Container::reference;using const_reference = typename Container::const_reference;using size_type = typename Container::size_type;using container_type = Container;protected: Container c;public: constexpr stack() : stack(Container()) {} constexpr explicit stack(const Container&);constexpr explicit stack(Container&&);template<class InputIterator> constexpr stack(InputIterator first, InputIterator last);template<container-compatible-range<T> R> constexpr stack(from_range_t, R&& rg);template<class Alloc> constexpr explicit stack(const Alloc&);template<class Alloc> constexpr stack(const Container&, const Alloc&);template<class Alloc> constexpr stack(Container&&, const Alloc&);template<class Alloc> constexpr stack(const stack&, const Alloc&);template<class Alloc> constexpr stack(stack&&, const Alloc&);template<class InputIterator, class Alloc> constexpr stack(InputIterator first, InputIterator last, const Alloc&);template<container-compatible-range<T> R, class Alloc> constexpr stack(from_range_t, R&& rg, const Alloc&);constexpr bool empty() const { return c.empty(); } constexpr size_type size() const { return c.size(); } constexpr reference top() { return c.back(); } constexpr const_reference top() const { return c.back(); } constexpr void push(const value_type& x) { c.push_back(x); } constexpr void push(value_type&& x) { c.push_back(std::move(x)); } template<container-compatible-range<T> R> constexpr void push_range(R&& rg);template<class... Args> constexpr decltype(auto) emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); } constexpr void pop() { c.pop_back(); } constexpr void swap(stack& s) noexcept(is_nothrow_swappable_v<Container>) { using std::swap; swap(c, s.c); } };template<class Container> stack(Container) -> stack<typename Container::value_type, Container>;template<class InputIterator> stack(InputIterator, InputIterator) -> stack<_iter-value-type_<InputIterator>>;template<ranges::input_range R> stack(from_range_t, R&&) -> stack<ranges::range_value_t<R>>;template<class Container, class Allocator> stack(Container, Allocator) -> stack<typename Container::value_type, Container>;template<class InputIterator, class Allocator> stack(InputIterator, InputIterator, Allocator) -> stack<_iter-value-type_<InputIterator>, deque<_iter-value-type_<InputIterator>, Allocator>>;template<ranges::input_range R, class Allocator> stack(from_range_t, R&&, Allocator) -> stack<ranges::range_value_t<R>, deque<ranges::range_value_t<R>, Allocator>>;template<class T, class Container, class Alloc> struct uses_allocator<stack<T, Container>, Alloc> : uses_allocator<Container, Alloc>::type { };}
23.6.6.3 Constructors [stack.cons]
constexpr explicit stack(const Container& cont);
Effects: Initializes c with cont.
constexpr explicit stack(Container&& cont);
Effects: Initializes c with std::move(cont).
template<class InputIterator> constexpr stack(InputIterator first, InputIterator last);
Effects: Initializes c withfirst as the first argument and last as the second argument.
Effects: Initializes c with ranges::to<Container>(std::forward<R>(rg)).
23.6.6.4 Constructors with allocators [stack.cons.alloc]
If uses_allocator_v<container_type, Alloc> is falsethe constructors in this subclause shall not participate in overload resolution.
template<class Alloc> constexpr explicit stack(const Alloc& a);
Effects: Initializes c with a.
template<class Alloc> constexpr stack(const container_type& cont, const Alloc& a);
Effects: Initializes c with cont as the first argument and a as the second argument.
template<class Alloc> constexpr stack(container_type&& cont, const Alloc& a);
Effects: Initializes c with std::move(cont) as the first argument and aas the second argument.
template<class Alloc> constexpr stack(const stack& s, const Alloc& a);
Effects: Initializes c with s.c as the first argument and aas the second argument.
template<class Alloc> constexpr stack(stack&& s, const Alloc& a);
Effects: Initializes c with std::move(s.c) as the first argument and aas the second argument.
template<class InputIterator, class Alloc> constexpr stack(InputIterator first, InputIterator last, const Alloc& alloc);
Effects: Initializes c withfirst as the first argument,last as the second argument, andalloc as the third argument.
Effects: Initializesc with ranges::to<Container>(std::forward<R>(rg), a).
23.6.6.5 Modifiers [stack.mod]
Effects: Equivalent to c.append_range(std::forward<R>(rg))if that is a valid expression, otherwise ranges::copy(rg, back_inserter(c)).
23.6.6.6 Operators [stack.ops]
template<class T, class Container> constexpr bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
template<class T, class Container> constexpr bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
template<class T, class Container> constexpr bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
template<class T, class Container> constexpr bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
template<class T, class Container> constexpr bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
template<class T, class Container> constexpr bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
template<class T, [three_way_comparable](cmp.concept#concept:three%5Fway%5Fcomparable "17.12.4 Concept three_way_comparable [cmp.concept]") Container> constexpr compare_three_way_result_t<Container> operator<=>(const stack<T, Container>& x, const stack<T, Container>& y);
23.6.6.7 Specialized algorithms [stack.special]
template<class T, class Container> constexpr void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
Constraints: is_swappable_v<Container> is true.
Effects: As if by x.swap(y).