std::stack::stack
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| 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 起) |
构建新的基础容器,容器适配器从各种数据源.
Original:
Constructs new underlying container of the container adaptor from a variety of data sources.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
1)
复制与内容
c构造基础容器cont。这也是默认的构造函数(至 C++11)Original:
Copy-constructs the underlying container
c with the contents of cont. This is also the default constructor (至 C++11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
移动构建的基本容器
cstd::move(cont)。这也是默认的构造函数(C++11 起)Original:
Move-constructs the underlying container
c with std::move(cont). This is also the default constructor (C++11 起)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
3)
拷贝构造函数。该适配器拷贝构造的other.c的内容。 (隐式声明)
Original:
Copy constructor. The adaptor is copy-constructed with the contents of other.c. (隐式声明)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
4)
移动的构造函数。该适配器的构造与std::move(other.c)。 (隐式声明)
Original:
Move constructor. The adaptor is constructed with std::move(other.c). (隐式声明)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
5-9)
下面的构造std::uses_allocator<container_type, Alloc>::value == true,也就是说,如果的基础容器是一个分配器感知的容器(适用于所有标准库容器),如果只定义.
Original:
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).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
5)
构造底层的容器,使用
alloc作为分配器。有效地调用c(alloc).Original:
Constructs the underlying container using
alloc as allocator. Effectively calls c(alloc).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
6)
构造的基础容器
cont的内容和使用alloc作为分配器。有效地调用c(cont, alloc).Original:
Constructs the underlying container with the contents of
cont and using alloc as allocator. Effectively calls c(cont, alloc).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
7)
构造基础容器的内容
cont使用移动语义,同时利用alloc分配器。有效地调用c(std::move(cont), alloc).Original:
Constructs the underlying container with the contents of
cont using move semantics while utilising alloc as allocator. Effectively calls c(std::move(cont), alloc).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
8)
构建适配器的
other.c的内容,作为分配器和使用alloc。有效地调用c(athor.c, alloc).Original:
Constructs the adaptor with the contents of
other.c and using alloc as allocator. Effectively calls c(athor.c, alloc).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
9)
构建适配器
other使用移动语义,同时利用alloc分配器的内容。有效地调用c(std::move(other.c), alloc).Original:
Constructs the adaptor with the contents of
other using move semantics while utilising alloc as allocator. Effectively calls c(std::move(other.c), alloc).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| alloc | - | 分配器使用的所有内存分配的基础容器
Original: allocator to use for all memory allocations of the underlying container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| other | - | 另一个容器适配器要用作源初始化基础容器
Original: another container adaptor to be used as source to initialize the underlying container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| cont | - | 容器被用作源初始化基础容器
Original: container to be used as source to initialize the underlying container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| first, last | - | 初始化的元素范围
Original: range of elements to initialize with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| Type requirements | ||
-Alloc must meet the requirements of Allocator.
| ||
-Container must meet the requirements of Container. The constructors (5-10) are only defined if Container meets the requirements of AllocatorAwareContainer
| ||
-InputIt must meet the requirements of InputIterator.
| ||
[编辑] 复杂性
1,3,5,6,8:线性
cont或otherOriginal:
1, 3, 5, 6, 8: linear in
cont or otherThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2,4,7,9:不变
Original:
2, 4, 7, 9: constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
| 本节是不完整的 |
[编辑] 为例
#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'; }
Output:
1 1 5
[编辑] 另请参阅
| 将值指派给容器适配器 Original: assigns values to the container adaptor The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |