I have a function A that accepts a predicate function as its argument.
I have another function B and it takes a char and returns an int, and a function C that accepts int and returns a bool.
My question is how to bind B and C to pass it to function A.
Something like:
A(bindfunc(B,C))
I know boost::bind works but i am looking for STL solution.
For example,
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))
One bad way would be to make a redundant function D which explicitly performs bind operation.
As a simple workaround for the lack of a
composehigher order function instd:Note that it doesn’t work for binary functions (more work is involved), and that your functions must be STL function objects. It means that if you have function pointers, you must wrap them with
std::ptr_fun.