std::list<T,Allocator>:: push_back
From cppreference.net
|
void
push_back
(
const
T
&
value
)
;
|
(1) | (自 C++26 起为 constexpr) |
|
void
push_back
(
T
&&
value
)
;
|
(2) |
(自 C++11 起)
(自 C++26 起为 constexpr) |
将 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
(函数模板) |