I have a function that requires a function pointer as argument:
int func(int a, int (*b)(int, int))
{
return b(a,1);
}
Now I want to use a certain function that has three arguments in this function:
int c(int, int, int)
{
// ...
}
How can I bind the first argument of c so that I’m able to do:
int i = func(10, c_bound);
I’ve been looking at std::bind1st but I cannot seem to figure it out. It doesn’t return a function pointer right? I have full freedom to adapt func so any changes of approach are possible. Althoug I would like for the user of my code to be able to define their own c…
note that the above is a ferocious simplification of the actual functions I’m using.
The project sadly requires C++98.
You can’t do that. You would have to modify
functo take a function-object first. Something like:In fact, there is no need for
bto be anstd::function, it could be templated instead:but I would stick with the
std::functionversion for clarity and somewhat less convoluted compiler output on errors.Then you would be able to do something like:
Note all this is C++11, but you can do it in C++03 using Boost.