Files
2025-10-25 03:02:53 +03:00

3.5 KiB

[stack.defn]

23 Containers library [containers]

23.6 Container adaptors [container.adaptors]

23.6.6 Class template stack [stack]

23.6.6.2 Definition [stack.defn]

namespace std {template<class T, class Container = deque>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 constexpr stack(InputIterator first, InputIterator last); template<container-compatible-range R>constexpr stack(from_range_t, R&& rg); template constexpr explicit stack(const Alloc&); template constexpr stack(const Container&, const Alloc&); template constexpr stack(Container&&, const Alloc&); template constexpr stack(const stack&, const Alloc&); template constexpr stack(stack&&, const Alloc&); template<class InputIterator, class Alloc>constexpr stack(InputIterator first, InputIterator last, const Alloc&); template<container-compatible-range 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 R>constexpr void push_range(R&& rg); template<class... Args>constexpr decltype(auto) emplace(Args&&... args){ return c.emplace_back(std::forward(args)...); }constexpr void pop() { c.pop_back(); }constexpr void swap(stack& s) noexcept(is_nothrow_swappable_v){ using std::swap; swap(c, s.c); }}; template stack(Container) -> stack<typename Container::value_type, Container>; template stack(InputIterator, InputIterator) -> stack<iter-value-type>; template<ranges::input_range R> stack(from_range_t, R&&) -> stack<ranges::range_value_t>; 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, deque<iter-value-type, Allocator>>; template<ranges::input_range R, class Allocator> stack(from_range_t, R&&, Allocator)-> stack<ranges::range_value_t, deque<ranges::range_value_t, Allocator>>; template<class T, class Container, class Alloc>struct uses_allocator<stack<T, Container>, Alloc>: uses_allocator<Container, Alloc>::type { };}