std::back_insert_iterator<Container>::operator=
来自 cppreference.com
< cpp | iterator | back insert iterator
(1) | ||
back_insert_iterator<Container>& operator=( typename Container::const_reference value ); |
(直到 C++11) | |
back_insert_iterator<Container>& operator=( const typename Container::value_type& value ); |
(自 C++11 起) (直到 C++20) |
|
constexpr back_insert_iterator<Container>& operator=( const typename Container::value_type& value ); |
(自 C++20 起) | |
(2) | ||
back_insert_iterator<Container>& operator=( typename Container::value_type&& value ); |
(自 C++11 起) (直到 C++20) |
|
constexpr back_insert_iterator<Container>& operator=( typename Container::value_type&& value ); |
(自 C++20 起) | |
将给定值 value 插入容器中。
1) 结果为 container->push_back(value).
2) 结果为 container->push_back(std::move(value)).
[编辑] 参数
value | - | 要插入的值 |
[编辑] 返回值
*this
[编辑] 示例
运行此代码
#include <deque> #include <iostream> #include <iterator> int main() { std::deque<int> q; std::back_insert_iterator<std::deque<int>> it(q); for (int i = 0; i < 10; ++i) it = i; // calls q.push_back(i) for (auto& elem : q) std::cout << elem << ' '; std::cout << '\n'; }
输出
0 1 2 3 4 5 6 7 8 9