stack
注:
-
构造函数默认为c++11
-
函数原型省略了一些细节,只展示实际需要填写的情况(分配器已经隐藏了,需要可以去c++reference查看)
-
参数栏表示传入的两个参数的意义而不是类型
-
返回值栏表示类型而不是意义
-
粉红色表示为c++11新特性
构造函数
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
构造函数 | explicit stack (const container_type& ctnr); | 容器类型的参数 | default | 创建一个stack,并初始化,赋ctnr的值 |
构造函数 | template <class Alloc> stack (container_type&& ctnr, const Alloc& alloc); | 容器类型的参数/无(常用) | default | 一般用来创建空的stack |
构造函数 | template <class Alloc> explicit stack (const Alloc& alloc); | 一个构造器 | default | 创建一个stack,并把初始化为alloc的内容 |
构造函数 | template <class Alloc> stack (const container_type& ctnr, const Alloc& alloc); | 容器类型的参数,一个构造器 | default | 创建一个stack,其内部容器是以cntr和alloc作为参数构造的 |
构造函数 | template <class Alloc> stack (container_type&& ctnr, const Alloc& alloc); | 容器类型的参数,一个构造器 | default | 创建一个stack,其内部容器由std::move(cntr)和alloc作为参数构造。 |
构造函数 | template <class Alloc> stack (const stack& x, const Alloc& alloc); | stack x,一个构造器 | default | 创建一个stack,并初始化为x内容,并由构造器作为参数 |
构造函数 | template <class Alloc> stack (container_type&& ctnr, const Alloc& alloc); | stack x,一个构造器 | default | 创建一个stack,并初始化为x内容,并由构造器作为参数 |
N/A(无析构函数) | N/A | N/A | N/A | N/A |
stack的构造函数好怪啊!大家看c++98的就好,忽略11版本的吧
成员方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
empty | bool empty() const; | 无 | bool | 返回是否为空 |
size | size_type size() const; | 无 | 非负整数 | 返回容器中的元素数量 |
top | reference top(); | 无 | 引用 | 返回栈顶元素 |
top | const_reference top() const; | 无 | 引用 | 返回栈顶元素 |
push | void push (const value_type& val); | 添加的值val | 无 | 将一个值压入栈中 |
push | void push (const value_type& val); | 添加的值val | 无 | 将一个值压入栈中 |
emplace | template <class... Args> void emplace (Args&&... args); | 添加的n个参数 | 无 | 将(n个)值(构造性的)压入栈中 |
pop | void pop(); | 无 | 无 | 弹出栈顶元素 |
swap | void swap (stack& x) noexcept(/*see below**/); | stack x | 无 | 将两个栈中的内容交换 |
- 该文章为翻译c++ Reference结合其他资料整理得出