replace_if 用法
来源:互联网 发布:小米移植网络助手 编辑:程序博客网 时间:2024/05/16 12:58
replace_iffunction template
template < class ForwardIterator, class Predicate, class T > void replace_if ( ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value );
<algorithm>
Replace values in range
Sets all those elements in the range [first,last) for which pred returns true when applied to its value, to a value of new_value.
The behavior of this function template is equivalent to:
template < class ForwardIterator, class Predicate, class T > void replace_if ( ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value ){ for (; first != last; ++first) if (pred(*first)) *first=new_value;}
Parameters
- first, last
- Forward iterators to the initial and final positions in a sequence. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
- pred
- Unary predicate taking an element in the range as argument, and returning a value indicating the falsehood (with false, or a zero value) or truth (true, or non-zero) of some condition applied to it. This can either be a pointer to a function or an object whose class overloads operator().
- new_value
- Value to be set to the affected elements.
Return value
none
#include<iostream>#include<algorithm>#include<vector>using namespace std;class student{public:int key;int value;int n;student(int n):n(n){}student(){}bool operator()(student s){return s.value<n;}};int main(){vector<student>vec(5);vector<student>vec_sub;vec[0].key=1;vec[0].value=1;vec[1].key=1;vec[1].value=2;vec[2].key=5;vec[2].value=5;vec[3].key=7;vec[3].value=7;vec[4].key=4;vec[4].value=4;vec_sub.resize(vec.size());vector<student>::iterator it,p;replace_if(vec.begin(),vec.end(),student(4),vec[4]);for(it=vec.begin();it!=vec.end();it++)cout<<(*it).value<<endl;}
- replace_if 用法
- boost replace_if replace_all_regex_copy用法
- replace_if
- replace/replace_if详解
- replace,replace_if,replace_copy,repace_copy_if
- STl-replace_if() trim,split,replace
- C++ replace,replace_if,replace_copy,replace_copy_if
- STL中replace/replace_if例子
- STL_Algorithm4: Replace, replace_if, replace copy, replace_copy_if
- STl-replace_if()替换函数的妙用
- STL 之replace,replace_if,replace_copy,replace_copy_if
- C++标准库---替换元素replace()&replace_if()
- STL 之replace,replace_if,replace_copy,replace_copy_if
- STL算法replace,replace_if,replace_copy.replace_copy_if
- STL常用算法: replace.replace_copy.replace_if.replace_copy_if
- STL中remove_if()/find_if()/replace_if()的使用方法(The usages of remove_if()/find_if()/replace_if() )
- 泛型算法系列32:replace()&&replace_copy()&&replace_if()&&replace_copy_if()
- 变异算法之替换(replace, replace_if, replace_copy, replace_copy_if)
- java.lang.ClassCastException: java.lang.Short cannot be [Object]
- 在Eclipse中将Java项目打包为jar .
- 动态规划中Warshall 和 Floyd
- ip数据流走向图解(图)
- 我的android程序员面试经历(一)(北京)
- replace_if 用法
- PB日志-数据窗口控件函数33.GetChild( )
- Intel Hex文件格式
- java 文件及目录操作
- I/O操作,字节流,字符流,字符集编码
- 转 JAVA 字符流与字节流的区别
- FileInputStream(文件输入、输出流) 示例
- 极力推荐一个数据库-sqlite
- 各种烧写文件格式简介-ELF Hex Bin