std::front_insert_iterator
STD:正面[医]插入[医]迭代器
Defined in header | | |
---|---|---|
template< class Container > class front_insert_iterator : public std::iterator< std::output_iterator_tag, void,void,void,void > | | (until C++17) |
template< class Container > class front_insert_iterator; | | (since C++17) |
std::front_insert_iterator
是OutputIterator
它将元素添加到为其构造的容器中。容器%27spush_front()
每当迭代器%28被分配给取消引用或未分配%29时,都会调用成员函数。递增std::front_insert_iterator
是个禁止行动。
成员类型
Member type | Definition |
---|---|
container_type | Container |
成员函数
(constructor) | constructs a new front_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 <vector>
#include <deque>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
std::vector<int> v{1,2,3,4,5};
std::deque<int> d;
std::copy(v.begin(), v.end(),
std::front_insert_iterator<std::deque<int>>(d) // or std::front_inserter(d)
for(int n : d)
std::cout << n << ' ';
std::cout << '\n';
}
二次
产出:
二次
5 4 3 2 1
二次
另见
front_inserter | creates a std::front_insert_iterator of type inferred from the argument (function template) |
---|---|
back_insert_iterator | iterator adaptor for insertion at the end of a container (class template) |
insert_iterator | iterator adaptor for insertion into a container (class template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。