Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2004-01-23 11:04:35


Peter Dimov wrote:
> Edward Diener wrote:
>> Sorry for the delay in answering this, as I was busy with other work.
>>
>> struct X { void AMemberFunction(int} };
>> struct Y { void AnotherMemberFunction(int) { } };
>>
>> // Within some code
>>
>> X x;
>> Y y;
>> boost::function< void (int) > ACallback;
>> ACallback = boost::bind(&X::AMemberFunction,&x) // or
>> ACallback = boost::bind(&Y::AnotherMemberFunction,&y);
>
> Yes, that's what I thought (you need to add a trailing _1 to forward
> the 'int' parameter as well).

Yes, that is my error.

> The plan is to support this. I asked
> for code because your statement:
>
>
>>>> The idea is this. I use boost::bind to assign a member function to
>>>> boost::function. Later I want to check boost::function to see if my
>>>> particular member function is the one it encapsulates as the
>>>> callback.
>
> in C++ reads:
>
> function< void(X*, int) > callback( &X::AMemberFunction );
>
> and you didn't really have that in mind, although equality
> comprasions for the above case will be supported, too.

I should have been more precise and said an object's member function.

>
>> Admittedly the check, and the reasons for doing so, are farfetched
>> and I am using boost::bind merely to bind a member function to a
>> boost::function for later callback without any argument substitution,
>
> No, you do use argument substitution; you bind the implicit "this"
> parameter to &x.

Picky, picky <g> . I meant that I wasn't explicitly passing in any values
for arguments. That boost::bind can be used just to pass the address of an
object's member function, in the form of the address of an object and the
address of a member function, is something which I greatly appreciate. The
argument substitution, while immensely useful for composition among other
things, is icing on the cake for me.

I am glad that boost::bind will support such comparisons. This will allow
one to test whether or not a particular function is the callback for boost::
function. I don't know what immediate use that I have for such
functionality, although Russell Hind mentioned that he had found one, but I
imagine that it will be a good thing to have for the future.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk