也就是所谓的迭代器配接器(Iterator Adapters).迭代器配接器不仅起到了辅助作用,还能赋予整个迭代器抽象概念更强大的能力。
2.下面简介三种迭代器配接器(iterator Adapters):(1)insert iterators(安插型迭代器)(2)stream iterators (流迭代器)(3)reverse iterators (逆向迭代器)详细信息可参考《c++ 标准程序库》第7.4节。
是在容器的最前还是最后,或是特定的位置,它根据三种不同的安插型迭代器(insert iterators)而定。单步前进(step forward)不会造成任何动静(是一个no-op)
3.c++代码解释:以back_inserter()为例
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main( int argc ,char **argv)
{
list int_list;
//insert elements from 1 to 9 into the first collection : int_list
for(int i = 1; i <= 9 ; ++i)
int_list.push_back(i);
//printf all the elements in the int_list
list::iterator list_pos;
cout<<"elements in the int_list now: ";
for( list_pos = int_list.begin(); list_pos != int_list.end(); ++list_pos)
cout << *list_pos << ' ';
cout << endl;
//copy all the elements of int_list into int_vector by appending them
vector int_vector;
copy(int_list.begin(),int_list.end(),back_inserter(int_vector));
//printf all the elements int the int_vector
vector::iterator pos_vector;
cout<<"elements in the int_vector:";
for( pos_vector = int_vector.begin(); pos_vector != int_vector.end();++pos_vector)
cout<< *pos_vector << ' ';
cout<< endl;
//copy all the elements of int_list into int_set
//only inserter that works for associative containers
set int_set;
copy(int_list.begin(),int_list.end(),inserter(int_set,int_set.begin()));
set:: iterator pos_printf_list;
cout<<"elements of int_set now:";
for(pos_printf_list = int_set.begin(); pos_printf_list != int_set.end(); ++pos_printf_list)
cout<< *pos_printf_list << ' ';
cout<< endl;
return 0;
}