std::back_insert_iterator<Container>::operator=

来自cppreference.com

 
 
迭代器库
迭代器概念
迭代器原语
迭代器适配器
流迭代器
迭代器定制点
迭代器操作
(C++11)
(C++11)
范围访问
(C++11)(C++14)
(C++11)(C++14)
(C++17)(C++20)
(C++14)(C++14)
(C++14)(C++14)
(C++17)
(C++17)
 
 
(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 <iostream>
#include <iterator>
#include <deque>
 
int main()
{
    std::deque<int> q;
    std::back_insert_iterator< std::deque<int> > it(q);
 
    for (int i=0; i<10; ++i)
        it = i; // 调用 q.push_back(i)
 
    for (auto& elem : q) std::cout << elem << ' ';
}

输出:

0 1 2 3 4 5 6 7 8 9