练习10.41 仅根据算法和参数的名字,描述下面每个标准库算法执行什么操作。
replace(beg,end,old_val, new_val):将容器中的元素old_val替换为new_val。
replace_if(beg,end,pred,new_val):当元素在pred条件下满足非零值,将其替换为new_val。
replace_copy(beg,end,dest,old_val,new_val):将容器中的元素old_val替换为new_val,并将其拷贝到dest。
replace_copy_if(beg,end,dest,pred,new_val):当元素在pred条件下满足非零值,将其拷贝到dest。
练习10.42 使用list代替vector重新实现10.2.3节(343页)中的去除重复单词的程序。
#include <iostream>
#include <list>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
list<string> text{ "I","can","can","a","can","in","your","can" };
text.sort();
text.unique();
for_each(text.begin(), text.end(), [](const string &s) {cout << s << " "; });
cout << endl;
//ostream_iterator<string> out_iter(cout, " ");
//copy(text.begin(), text.end(), out_iter);
return 0;
}