我有一个函数A
,它接受一个谓词函数作为它的参数。
我有另一个功能B
,它需要一个char
并返回一个int
和功能C
接受int
并返回一个bool
。如何将一个函数绑定到其他
我的问题是如何绑定B
和C
将它传递到功能A
。
喜欢的东西:
A(bindfunc(B,C))
我知道boost::bind
的作品,但我期待的STL的解决方案。
例如,
int count(vector<int> a, pred func); // A
//this functions counts all elements which satisfy a condition
int lastdigit(int x); // B
//this function outputs last digit(in decimal notation) of number x
bool isodd(int x); // C
//this function tells if number x is odd
// i want to find the count of all such numbers in a vector whose last digit is odd
// so i want something like
count(vector<int> a, bind(lastdigit, isodd))
一个糟糕的方式是使冗余功能D
其中明确进行绑定操作。
也许更具体的例子会帮助... – Cogwheel 2010-07-22 15:24:43
为什么社区wiki? (顺便说一下,要清楚,请显示A,B和C的函数声明) – kennytm 2010-07-22 15:44:16
int count(vector a,pred func); //此函数计算满足条件的所有元素 int lastdigit(int x ); //这个函数输出编号为x的最后一位数字(十进制表示法) bool isodd(int x); //这个函数告诉x是否为奇数 我想查找所有这样的数字在矢量最后的数字是奇数 所以我要像数(矢量一个,绑定(lastdigit,ISODD)) 请让我知道,如果我不明白 –
mukul
2010-07-22 15:49:34