首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::stack::stack

?

(1)

?

explicit stack( const Container& cont = Container() );

(until C++11)

explicit stack( const Container& cont );

(since C++11)

explicit stack( Container&& cont = Container() );

(2)

(since C++11)

stack( const stack& other );

(3)

?

stack( stack&& other );

(4)

(since C++11)

template< class Alloc > explicit stack( const Alloc& alloc );

(5)

(since C++11)

template< class Alloc > stack( const Container& cont, const Alloc& alloc );

(6)

(since C++11)

template< class Alloc > stack( Container&& cont, const Alloc& alloc );

(7)

(since C++11)

template< class Alloc > stack( const stack& other, const Alloc& alloc );

(8)

(since C++11)

template< class Alloc > stack( stack&& other, const Alloc& alloc );

(9)

(since C++11)

从各种数据源构造容器适配器的新底层容器。

1%29复制构造底层容器。c带着...的内容cont这也是默认构造函数%28,直到C++11%29

2%29移动-构造底层容器c带着std::move(cont)这也是默认构造函数%28,因为C++11%29

3%29复制构造函数。的内容复制构造适配器。other.c.%28隐式声明%29

4%29移动构造函数。适配器是用std::move(other.c).%28隐式声明%29

5-9%29以下构造函数仅在std::uses_allocator<container_type, Alloc>::value==true,也就是说,如果底层容器是所有标准库容器%29的分配器感知容器%28true。

5%29使用alloc作为分配器,就像c(alloc)...

6%29构造底层容器,其内容为cont和使用alloc作为分配器,就像c(cont, alloc)...

7%29构造底层容器,其内容为cont在使用时使用移动语义alloc作为分配器,就像c(std::move(cont), alloc)...

8%29构造适配器,其内容为other.c和使用alloc作为分配器,就像c(other.c, alloc)...

9%29构造适配器,其内容为other在使用时使用移动语义alloc作为分配器,就像c(std::move(other.c), alloc)...

参数

alloc

-

allocator to use for all memory allocations of the underlying container

other

-

another container adaptor to be used as source to initialize the underlying container

cont

-

container to be used as source to initialize the underlying container

first, last

-

range of elements to initialize with

类型要求

-分配器必须符合分配器的要求。

-货柜必须符合货柜的规定。构造函数%285-10%29只在容器满足分配程序-仓库容器的要求时才定义。

-输入必须符合输入器的要求。

复杂性

1,3,5,6,8:线性contother...

2,4,7,9:常数。

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
1
1
5

二次

另见

operator=

assigns values to the container adaptor (public member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com