Re: [Boost-users] [bind] Member fn has defeated me
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Simon Buchan Sent: Wednesday, October 05, 2005 9:49 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [bind] Member fn has defeated me
BRIDGES Dick wrote: <snip>
<snip> You find it mysterious because it's not even slightly common outside of functional languages. (I hope Boost can change this). Basicly: bind is a function that creates a function (sortof) from a function and arguments. Confused? Don't worry, that's normal. Essentially:
bind(&X::f, &x, _1);
is the same as:
f_result_type bound_f(f_arg1_type arg1) { return x.f(arg1); }
// ...
&bound_f
but with less hassles (ie. x can be local)
If I could start with a "bound" x, I probably wouldn't have so much trouble with the concept. I get confused when trying to deal with the implied 'this' when starting from the bind(&X::f, _1, _2) form. In the current case [i.e., void f(bool)], I think _2 represents the bool parameter and can't figure out how to express the unbound 'this'. Clearly there is an error in my understanding of the underlying concept.
Dick Bridges wrote:
If I could start with a "bound" x, I probably wouldn't have so much trouble with the concept. I get confused when trying to deal with the implied 'this' when starting from the bind(&X::f, _1, _2) form. In the current case [i.e., void f(bool)], I think _2 represents the bool parameter and can't figure out how to express the unbound 'this'. Clearly there is an error in my understanding of the underlying concept.
_1, _2, ..., _9 represent the 1st, 2nd, ..., 9th parameters to the function object that bind() produces. Their numbering has nothing to do with the order of arguments to the function, member function or function object that's being bound, which will be the same as the order of the arguments given to bind(). Ben.
participants (2)
-
Ben Hutchings
-
BRIDGES Dick