Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2004-01-21 18:21:25

Peter Dimov wrote:
> Douglas Paul Gregor wrote:
>> boost::bind would need to be EqualityComparable for this to work, and
>> at the moment it is not. It's technically trivially to do, we need
>> only convince Peter :)
> There are some interesting corner cases.
> int a = 1, b = 1;
> int f(int x) { return x; }
> bind(f, a) == bind<int>(f, a); // true, false, or ill-formed?
> bind(f, 1) == bind(f, 1L); // true, false, or ill-formed?
> bind(f, ref(a)) == bind(f, ref(b)); // true or false?
> and the related question whether reference_wrapper needs operator==
> and if so, what are its semantics. However, ...
>> On Wed, 21 Jan 2004, Edward Diener wrote:
>>> The million dollar question is: if one uses boost::bind as the
>>> mechanism of passing a member function as an underlying function
>>> object to boost::function, will this new functionality somehow let
>>> me check if a particular member function is indeed the one that
>>> boost::function holds as its function object ? Or maybe it needs to
>>> be rephrased as: does an instance of boost::bind allow me to pass
>>> its underlying function object to the new equality operator of
>>> boost::function and is this underlying function object
>>> EqualityComparable ?
> ... I am not entirely sure that I understand the question.

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. Mr.
Gregor's original post suggested that something like this could be done on
his end, but I suspect that boost::bind can't equate my member function to a
form which would allow boost::function to compare against it to see if it
actually encapsulates it as the callback.

I would be very surprised if something like this can be made to work, but it
would be a plus to be able to check whether a particular function, member
function, or function object were the underlying callback mechanism for
boost::function. It could be argued that such functionality has little use,
which may be theoretically true, but since boost::function encapsulates the
idea of a universal callback in C++, it would seem that such a mechanism for
checking if a particular callback were encapsulated could be beneficial in
some situations. I could imagine, although just theoretically, for some
run-time code using boost::function to have logic that says that if class
X's AMemberFunction were the callback do A, while if class Y's
AnotherMemberFunction were the callback do B. While I don't advocate such
logic, which ties a knowledge of possible callbacks to a particular
boost::function, I can imagine that it might actually be used in some form
of computer programming situation.

Again this is all theoretical. It is you bright fellows who can consider
whether such theoretical functionality is actually ever worthwhile working

In the non-standard C++ programming world of MC++ __delegates and BCB
__closures, one can indeed check that a particular member function is a
callback. I don't bring that up in order to criticize, in any way,
boost::function, boost::signals, or boost::bind, but just to point out that
my query has a basis in some existing, although non-standard, C++
functionality. I have never found an immediate practical use of such
knowledge myself.

Boost list run by bdawes at, gregod at, cpdaniel at, john at