Simple example
#include <vector>
#include <functional>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
vector<int> v({1,2,3,4,5,4,3,2,1});
cout << "Original Vector: " << endl;
auto itr = v.begin();
while (itr!=v.end()){
cout << *itr << " ";
itr++;
}
cout << endl;
// replace 3 with 10
cout << "After replacement: " << endl;
replace(v.begin(), v.end(), 3, 10);
itr = v.begin();
while (itr!=v.end()){
cout << *itr << " ";
itr++;
}
cout << endl;
// if the number less than 5, replace it with 0
cout << "After replacement: " << endl;
replace_if(v.begin(), v.end(), [](int i){return i<5;}, 0);
itr = v.begin();
while (itr!=v.end()){
cout << *itr << " ";
itr++;
}
cout << endl;
return 0;
}