template<
class T,
class Container = std::deque<T>
> class stack;
定义:
// 默认构造函数
stack() : stack(Container()) { }
// 以 cont 的内容复制构造底层容器 c
explicit stack( const Container& cont );
// 以 std::move(cont) 移动构造底层容器 c
explicit stack( Container&& cont );
// 复制构造函数
stack( const stack& other );
// 复制构造函数
stack( stack&& other );
用法:
std::stack<int> c1;
std::stack<int> c2(c1);
std::deque<int> deq {3, 1, 4, 1, 5};
std::stack<int> c3(deq);
定义:
stack& operator=( const stack& other );
stack& operator=( stack&& other );
用法:
stack<int> s1;
stack<int> s2;
s1 = s2;
s1 = std::move(s2);
定义:
reference top();
const_reference top() const;
用法:
std::stack<int> s;
s.push( 2 );
s.push( 6 );
s.push( 51 );
std::cout << s.top() << std::endl; // 51
bool empty() const;
size_type size() const;
// 等效地调用 c.push_back(value)
void push( const value_type& value );
// 等效地调用 c.push_back(std::move(value))
void push( value_type&& value );
template< class... Args >
void emplace( Args&&... args );
void pop();
void swap( stack& other ) noexcept(/* see below */);
按照字典顺序比较 stack 中的值
template< class T, class Container >
bool operator==( const std::stack<T,Container>& lhs, const std::stack<T,Container>& rhs );
template< class T, class Container >
bool operator!=( const std::stack<T,Container>& lhs, const std::stack<T,Container>& rhs );
template< class T, class Container >
bool operator<( const std::stack<T,Container>& lhs, const std::stack<T,Container>& rhs );
template< class T, class Container >
bool operator<=( const std::stack<T,Container>& lhs, const std::stack<T,Container>& rhs );
template< class T, class Container >
bool operator>( const std::stack<T,Container>& lhs, const std::stack<T,Container>& rhs );
template< class T, class Container >
bool operator>=( const std::stack<T,Container>& lhs, const std::stack<T,Container>& rhs );
template< class T, std::three_way_comparable Container >
std::compare_three_way_result_t<Container>
operator<=>( const std::stack<T,Container>& lhs, const std::stack<T,Container>& rhs );
template< class T, class Container >
void swap( std::stack<T,Container>& lhs,
std::stack<T,Container>& rhs );