std::stack::stack
来自cppreference.com
![]() |
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
explicit stack( const Container& cont = Container() ); explicit stack( const Container& cont ); |
(1) | (C++11 前) (C++11 起) |
explicit stack( Container&& cont = Container() ); |
(2) | (C++11 起) |
stack( const stack& other ); |
(3) | |
stack( stack&& other ); |
(4) | (C++11 起) |
template< class Alloc > explicit stack( const Alloc& alloc ); |
(5) | (C++11 起) |
template< class Alloc > stack( const Container& cont, const Alloc& alloc ); |
(6) | (C++11 起) |
template< class Alloc > stack( Container&& cont, const Alloc& alloc ); |
(7) | (C++11 起) |
template< class Alloc > stack( const stack& other, const Alloc& alloc ); |
(8) | (C++11 起) |
template< class Alloc > stack( stack&& other, const Alloc& alloc ); |
(9) | (C++11 起) |
构建新的基础容器,容器适配器从各种数据源.
1)
2)
3)
4)
5-9)
下面的构造std::uses_allocator<container_type, Alloc>::value == true,也就是说,如果的基础容器是一个分配器感知的容器(适用于所有标准库容器),如果只定义.
原文:
The following constructors are only defined if std::uses_allocator<container_type, Alloc>::value == true, that is, if the underlying container is an allocator-aware container (true for all standard library containers).
5)
6)
7)
8)
9)
目录 |
[编辑] 参数
alloc | - | |
other | - | |
cont | - | |
first, last | - | |
类型要求 | ||
-Alloc 必须满足 Allocator 的要求。
| ||
-Container 必须满足 Container 的要求。The constructors (5-10) are only defined if Container meets the requirements of AllocatorAwareContainer
| ||
-InputIt 必须满足 InputIterator 的要求。
|
[编辑] 复杂性
本节未完成 |
[编辑] 为例
运行此代码
#include <stack> #include <deque> #include <iostream> int main() { std::stack<int> c1; c1.push(5); std::cout << c1.size() << '\n'; std::stack<int> c2(c1); std::cout << c2.size() << '\n'; std::deque<int> deq {3, 1, 4, 1, 5}; std::stack<int> c3(deq); std::cout << c3.size() << '\n'; }
输出:
1 1 5
[编辑] 另请参阅
将值赋给容器适配器 (公开成员函数) |