Namespaces
Variants
Actions

std::stack

From cppreference.com
< cpp‎ | container
 
 
 
 
Defined in header <stack>
template<

    class T,
    class Container = std::deque<T>

> class stack;

The std::stack class is a container adaptor that gives the programmer the functionality of a stack - specifically, a LIFO (last-in, first-out) data structure.

The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The stack pushes and pops the element from the back of the underlying container, known as the top of the stack.

All member functions of std::stack are constexpr: it is possible to create and use std::stack objects in the evaluation of a constant expression.

However, std::stack objects generally cannot be constexpr, because any dynamically allocated storage must be released in the same evaluation of constant expression.

(since C++26)

Contents

[edit] Template parameters

T - The type of the stored elements. The program is ill-formed if T is not the same type as Container::value_type.
Container - The type of the underlying container to use to store the elements. The container must satisfy the requirements of SequenceContainer. Additionally, it must provide the following functions with the usual semantics:

The standard containers