Look at the code first:
#include <iostream>#include<vector>#include<algorithm>#include<iterator>using namespacestd;intmain () {vector<int>Coll; //Create back_inserter for Coll//-Inconvenientback_insert_iterator<vector<int> >ITER (coll); //insert elements with the usual iterator interface*iter =1; ITER++; *iter =2; ITER++; *iter =3; Copy (Coll.begin (), Coll.end (), Ostream_iterator<int> (cout,", ")); cout<<Endl; //Create back Inserter and insert elements; //-ConvenientBack_inserter (coll) = -; Back_inserter (Coll)= -; Copy (Coll.begin (), Coll.end (), Ostream_iterator<int> (cout,", ")); cout<<Endl; //Use the back Inserter to append all elements again//Reserve enough memory to avoid reallocationColl.reserve (2*coll.size ()); Copy (Coll.begin (), Coll.end (),//SourceBack_inserter (coll));//DestinationCopy (Coll.begin (), Coll.end (),ostream_iterator<int> (cout,", ")); cout<<Endl;}
This line in the code above:
back_insert_iterator<vector<int> > iter (coll);
Defines an adapter. Personal feel also belongs to iterator, usage should be similar, so according to gourd painting Scoop, wrote the following code, define a iterator:
iterator<vector<int> > Iter1 (coll);
Result Error: Error C2976: "Std::iterator": Too few template parameters.
See iterator source code, the level is limited, only know is less parameter, concrete should how to remedy do not know. Later thought, the general definition of a iterater generally used the following form:
vector<int>= Coll.begin ();
Unlike Back_insert_iterator's definition, I think it should be back_insert_iterator is not part of a container, it should be a separate from the container. This may be the reason they are defined in different ways.
Back_insert_iterator and iterator are different.