std::back_insert_iterator
STD:回来[医]插入[医]迭代器
Defined in header | | |
---|---|---|
template< class Container > class back_insert_iterator : public std::iterator< std::output_iterator_tag, void, void, void, void > | | (until C++17) |
template< class Container > class back_insert_iterator; | | (since C++17) |
std::back_insert_iterator
是OutputIterator
它附加到一个容器上,而容器是为其建造的。容器%27spush_back()
每当迭代器%28被分配给取消引用或未分配%29时,都会调用成员函数。递增std::back_insert_iterator
是个禁止行动。
成员类型
Member type | Definition |
---|---|
container_type | Container |
成员函数
(constructor) | constructs a new back_insert_iterator (public member function) |
---|---|
operator= | inserts an object into the associated container (public member function) |
operator* | no-op (public member function) |
operator++operator++(int) | no-op (public member function) |
成员对象
Member name | Definition |
---|---|
container (protected) | a pointer of type Container* |
成员类型
Member type | Definition |
---|---|
value_type | void |
difference_type | void |
pointer | void |
reference | void |
iterator_category | std::output_iterator_tag |
注意:在C++17之前,这些成员类型必须通过从std::iterator<std::output_iterator_tag,void,void,void,void>...
例
二次
#include <iostream>
#include <iterator>
#include <algorithm>
#include <cstdlib>
#include <vector>
int main()
{
std::vector<int> v;
std::generate_n(std::back_insert_iterator<std::vector<int>>(v), // can be simplified
10, [](){ return std::rand() % 10; } // with std::back_inserter
for (int n : v)
std::cout << n << ' ';
std::cout << '\n';
}
二次
产出:
二次
3 6 7 5 3 5 6 2 9 1
二次
另见
back_inserter | creates a std::back_insert_iterator of type inferred from the argument (function template) |
---|---|
front_insert_iterator | iterator adaptor for insertion at the front of a container (class template) |
insert_iterator | iterator adaptor for insertion into a container (class template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。