void f(vector<Entry>& ve,list<Entry>& le) { sort(ve.begin(),ve.end()); unique_copy(ve.begin(),ve.end(),le.begin()); } void f(vector<Entry>&ve,list<Entry>&le) { sort(ve.begin(),ve.end()); unique_copy(ve.begin(),ve.end(),back_inserter(le));//append to le } void f(list<Entry>&ve,vector<Entry>&le) { copy(ve.begin(),ve.end(),le);//error: le not aniterator copy(ve.begin(),ve.end(),le.end());//bad: writes beyond the end copy(ve.begin(),ve.end(),le.begin());//overwrite elements }
string::const iterator i = find(s.begin(),s.end(),c); void f() { string m = "Mary had a little lamb"; int a count = count(m,´a´); } void f(list<complex>& lc, vector<string>& vs, string s) { int i1 = count(lc.begin(),lc.end(),complex(1,3)); int i2 = count(vs.begin(),vs.end(),"Diogenes"); int i3 = count(s.begin(),s.end(),´x´); } void g(char cs[], int sz) { int i1 = count(&cs[0],&cs[sz],´z´); // ’z’s in array int i2 = count(&cs[0],&cs[sz/2],´z´); // ’z’s in first half of array }