在线文档教程
C++
迭代器 | Iterator

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_iteratorOutputIterator它将元素添加到为其构造的容器中。容器%27spush_front()每当迭代器%28被分配给取消引用或未分配%29时,都会调用成员函数。递增std::front_insert_iterator是个禁止行动。

成员类型

Member typeDefinition
container_typeContainer

成员函数

(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 nameDefinition
container (protected)a pointer of type Container*

成员类型

Member typeDefinition
value_typevoid
difference_typevoid
pointervoid
referencevoid
iterator_categorystd::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_insertercreates a std::front_insert_iterator of type inferred from the argument (function template)
back_insert_iteratoriterator adaptor for insertion at the end of a container (class template)
insert_iteratoriterator adaptor for insertion into a container (class template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/iterator/前沿[医]插入[医]迭代器