0

Let I have a function

void f1(type_a a, type_b b, type_c c)

I want to convert it to

void f2(type_a a, type_b b)

where instead of c will be passed my object.

How can I do this usind boost:bind?

w00drow
  • 468
  • 2
  • 11

2 Answers2

1

Something like this I think

boost::bind(&f1, _1, _2, c_default_value);
ForEveR
  • 55,233
  • 2
  • 119
  • 133
0

C++ is not a functional language, so you can't make a true partial application of a function. What you can do is the following:

#include <boost/bind.hpp>
void f1(int a, double b, char c)
{}
int main()
{
  auto binder = boost::bind(&f1, _1, _2, 'c');
  binder(1, 2.0);
}

Note however, that while you can pass binder to any context where a callable is expected, it is not convertible to a pointer-to-function.

Igor R.
  • 14,716
  • 2
  • 49
  • 83