函数原型：

```
template < class ForwardIterator, class UnaryPredicate, class T >
  void replace_if (ForwardIterator first, ForwardIterator last,
                   UnaryPredicate pred, const T& new_value)
{
  while (first!=last) {
    if (pred(*first)) *first=new_value;
    ++first;
  }
}
```
功能： 将区间[fist,last)之内每一个元素传入一元判断式：当pred(elem) 返回true时的元素替换成new_value；

示例代码：

```
  #include <iostream>  
  #include <algorithm>
  #include <vector>  
  using namespace std;  
  //把小于5的替换为8 
  bool fun(int i)
  {
  	return i < 5;
  }
  int main()  
  { 
  	 int a[] = {1,2,3,4,5,6,7}; 
  	 vector<int> vec(a,a+7);
     replace_if(vec.begin(),vec.end(),fun,8); //vec = [8 8 8 8 5 6 7]
     return 0;
  }
```