inserter
允许您使用 inserter(_Cont,_Where) 而不是 insert_iterator<Container;AMP_gt;(_Cont,_Where)的帮助器模板函数。
template<class Container>
insert_iterator<Container> inserter(
Container& _Cont,
typename Container::iterator _Where
);
参数
_Cont
新元素将添加的容器。_Where
定位问题插入的迭代器。
备注
模板函数返回 insert_iterator::insert_iterator<Container;AMP_gt;(_Cont,_Where)。
示例
// iterator_inserter.cpp
// compile with: /EHsc
#include <iterator>
#include <list>
#include <iostream>
int main( )
{
using namespace std;
int i;
list <int>::iterator L_Iter;
list<int> L;
for (i = 2 ; i < 5 ; ++i )
{
L.push_back ( 10 * i );
}
cout << "The list L is:\n ( ";
for ( L_Iter = L.begin( ) ; L_Iter != L.end( ); L_Iter++ )
cout << *L_Iter << " ";
cout << ")." << endl;
// Using the template version to insert an element
insert_iterator<list <int> > Iter( L, L.begin ( ) );
*Iter = 1;
// Alternatively, using the member function to insert an element
inserter ( L, L.end ( ) ) = 500;
cout << "After the insertions, the list L is:\n ( ";
for ( L_Iter = L.begin( ) ; L_Iter != L.end( ); L_Iter++)
cout << *L_Iter << " ";
cout << ")." << endl;
}
要求
标头: <iterator>
命名空间: std