boost bind question, can it create a functor with more arguments than needed

Dear all,
Probably this is something one does not encounter often, but I have here an
interface which expects more arguments than needed, e.g.:
void SomeInterface(boost::function

gast 128 wrote:
Dear all,
Probably this is something one does not encounter often, but I have here an interface which expects more arguments than needed, e.g.:
void SomeInterface(boost::function
fcCallback) {} now I have another functor like: boost::function
fc; I want fc apply to SomeInterface, and it only needs to fill in argument1.
So I need something like boost::bind(fc, _1, _2) to get it compilable for SomeInterface, only bind now thinks that fc has a prototype of two arguments. Is there a way to tell bind to ignore argument2 (without explicit write a functor)?
I believe the result of bind(fc, _1) would happily accept two arguments, discarding the second. As an extreme example: void do_nothing() {} int r; bind(do_nothing)(r, r, r, r, r, r); works fine. - Volodya

gast 128 wrote:
Dear all,
Probably this is something one does not encounter often, but I have here an interface which expects more arguments than needed, e.g.:
void SomeInterface(boost::function
fcCallback) {} now I have another functor like: boost::function
fc; I want fc apply to SomeInterface, and it only needs to fill in argument1. So I need something like boost::bind(fc, _1, _2) to get it compilable for SomeInterface, only bind now thinks that fc has a prototype of two arguments. Is there a way to tell bind to ignore argument2 (without explicit write a functor)?
Yes there is, just tell it so: bind(fc, _1) is as close to "I want fc apply to SomeInterface, and it only needs to fill in argument1" as it can get. ;-) You can also use bind(fc, _2) if you want to pass Arg2 to fc and ignore Arg1.
participants (3)
-
gast 128
-
Peter Dimov
-
Vladimir Prus