std::list<T,Allocator>::push_back
来自 zh.cppreference.net
void push_back( const T& value );
|
(1) | |
void push_back( T&& value );
|
(2) | (自 C++11 起) |
将给定元素 value 追加到容器的末尾。
1) 新元素被初始化为
value 的副本。2)
value 通过移动构造新元素。不会使任何迭代器或引用失效。
参数
| value | - | 要追加的元素值 |
|
(自 C++11 起) | ||||||
返回值
(无)
复杂度
常量。
异常
如果抛出异常(可能由于
Allocator::allocate()
或元素复制/移动构造函数/赋值操作导致),此函数不产生任何效果(
强异常安全保证
)。
示例
运行此代码
#include <iomanip> #include <iostream> #include <string> #include <list> int main() { std::list<std::string> letters; letters.push_back("abc"); std::string s{"def"}; letters.push_back(std::move(s)); std::cout << "std::list letters holds: "; for (auto&& e : letters) std::cout << std::quoted(e) << ' '; std::cout << "\nMoved-from string s holds: " << std::quoted(s) << '\n'; }
可能的输出:
std::list letters holds: "abc" "def" Moved-from string s holds: ""
参见
|
(C++11)
|
在容器末尾原位构造元素
(公开成员函数) |
|
在容器开头插入元素
(公开成员函数) |
|
|
移除末尾元素
(公开成员函数) |
|
|
创建根据实参类型推导的
std::back_insert_iterator
(函数模板) |