
Suppose I have something that expects a general function object that takes three parameters. I have a function that takes one parameter, and I don't care about the other two. How do I get an instance func that when called as func(a,b,c) will end up calling my function foo as foo(a) and throw away the other two? If I use bind, I wind up with a functor that takes fewer arguments than the original. But here I have more.

Suppose I have something that expects a general function object that takes three parameters. I have a function that takes one parameter, and I don't care about the other two. How do I get an instance func that when called as func(a,b,c) will end up calling my function foo as foo(a) and throw away the other two?
If I use bind, I wind up with a functor that takes fewer arguments than the original. But here I have more.
You don't need to do anything special; function objects produced by bind can already be called with extra arguments and they ignore the extra ones. i.e. just do "func = bind(foo, _1)", and "func(a, b, c)" will be valid and equivalent to "foo(a)" Regards, Nate
participants (2)
-
John M. Dlugosz
-
Nathan Ridge