[stack.defn] # 23 Containers library [[containers]](./#containers) ## 23.6 Container adaptors [[container.adaptors]](container.adaptors#stack.defn) ### 23.6.6 Class template stack [[stack]](stack#defn) #### 23.6.6.2 Definition [stack.defn] namespace std {template>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*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") 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&); templateconstexpr stack(InputIterator first, InputIterator last, const Alloc&); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") 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*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R>constexpr void push_range(R&& rg); templateconstexpr 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; template stack(InputIterator, InputIterator) -> stack<*iter-value-type*>; template stack(from_range_t, R&&) -> stack>; template stack(Container, Allocator) -> stack; template stack(InputIterator, InputIterator, Allocator)-> stack<*iter-value-type*, deque<*iter-value-type*, Allocator>>; template stack(from_range_t, R&&, Allocator)-> stack, deque, Allocator>>; templatestruct uses_allocator, Alloc>: uses_allocator::type { };}