Any sequence container supporting operations back(), push_back() and pop_back() can be used to instantiate stack. In particular, vector, list and deque can be used.
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: explicit stack(const Container&); explicit stack(Container&& = Container()); template <class Alloc> explicit stack(const Alloc&); template <class Alloc> stack(const Container&, const Alloc&); template <class Alloc> stack(Container&&, const Alloc&); template <class Alloc> stack(const stack&, const Alloc&); template <class Alloc> stack(stack&&, const Alloc&); bool empty() const { return c.empty(); } size_type size() const { return c.size(); } reference top() { return c.back(); } const_reference top() const { return c.back(); } void push(const value_type& x) { c.push_back(x); } void push(value_type&& x) { c.push_back(std::move(x)); } template <class... Args> reference emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); } void pop() { c.pop_back(); } 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 Container, class Allocator> stack(Container, Allocator) -> stack<typename Container::value_type, Container>; template <class T, class Container> bool operator==(const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator< (const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator> (const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y))); template <class T, class Container, class Alloc> struct uses_allocator<stack<T, Container>, Alloc> : uses_allocator<Container, Alloc>::type { }; }
explicit stack(const Container& cont);
explicit stack(Container&& cont = Container());
If uses_allocator_v<container_type, Alloc> is false the constructors in this subclause shall not participate in overload resolution.
template <class Alloc> explicit stack(const Alloc& a);
template <class Alloc> stack(const container_type& cont, const Alloc& a);
template <class Alloc> stack(container_type&& cont, const Alloc& a);
template <class Alloc> stack(const stack& s, const Alloc& a);
template <class Alloc> stack(stack&& s, const Alloc& a);
template <class T, class Container>
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
Remarks: This function shall not participate in overload resolution unless is_swappable_v<Container> is true.