Opened 15 years ago

Closed 9 years ago

#1076 closed Bugs (wontfix)

compile error: disconnecting struct with operator()() doesn't work in VS2005 SP1

Reported by: boris@… Owned by: Douglas Gregor
Milestone: To Be Determined Component: signals
Version: Boost 1.34.0 Severity: Showstopper
Keywords: error Cc: MartinNvPyle@…

Description

According to http://www.boost.org/doc/html/signals/tutorial.html#id1626102 it should be possible to connect a signal to operator()() in a struct. While connecting works indeed disconnecting doesn't (in VS2005 SP1). The compile error VS2005 reports is:

C2678: binary '==' : no operator found which takes a left-hand operand of type 'const event_handler' (or there is no acceptable conversion)

There has been a discussion on the mailing list already - see http://thread.gmane.org/gmane.comp.lib.boost.user/27997/focus=28629

Attachments (1)

testcase.cpp (376 bytes ) - added by boris@… 15 years ago.

Download all attachments as: .zip

Change History (10)

by boris@…, 15 years ago

Attachment: testcase.cpp added

comment:1 by Eric Niebler, 15 years ago

Owner: set to doug_gregor

comment:2 by boris@…, 14 years ago

The problem can also be reproduced with VC++ 9.0. Upgrading the compiler won't help unfortunately.

comment:3 by Douglas Gregor, 14 years ago

Owner: changed from doug_gregor to Douglas Gregor

comment:4 by anonymous, 13 years ago

Resolution: invalid
Status: newclosed

I think you need an equality comparison here - otherwise, how will the compiler know which slot to disconnect?

struct event_handler
{
       void operator()() {}
       bool operator == ( const event_handler &rhs ) { return true; }
};

I'll see about getting the documentation updated, too.

comment:5 by Marshall Clow, 13 years ago

I was the one who closed the bug.

comment:6 by Martin Pyle <MartinNvPyle@…>, 13 years ago

Cc: MartinNvPyle@… added
Resolution: invalid
Status: closedreopened

In:

http://lists.boost.org/boost-users/2007/07/29153.php

Boris showed some error output. That seems to show his original problem with signal::disconnect was while using boost::function, not a hand crafted struct/functor as is shown here. I think he may have over simplified his example.

I have the same problem Boris had. Using VS2005, and a boost::function object I get operator==() cant be found errors when calling signal::disconnect. Of course, boost::function does have an operator==().

Here's an example:

#include <boost/signal.hpp>
#include <boost/function.hpp>

void foo()
{
}

void TrySignalDisconnect()
{
	typedef boost::function<void()> MyFunctorType;

	MyFunctorType myFunctorFoo(&foo);

	assert( &foo == myFunctorFoo ); //compiles!
	//assert( myFunctorFoo == myFunctorFoo) ); //will NOT compile

	boost::signal<void()> sig;
	sig.connect(myFunctorFoo);
	//sig.disconnect(myFunctorFoo);	//will NOT compile -- same reason

}

To me it looks like boost::function will compare with a raw function pointer, but not another boost::function ?

I hope this isn't bending the meaning of this bug too far. I'm using boost 1.35.

comment:7 by bschaeling, 13 years ago

It's such a long time ago that I reported the bug that I don't remember all the details anymore. However I think your code fails because comparing boost::function objects with == and != isn't supported - see http://www.boost.org/doc/libs/1_42_0/doc/html/function/faq.html#id877361.

comment:8 by Martin Pyle <MartinNvPyle@…>, 13 years ago

Thanks for the info Boris. Yes that seems to be highly relevant. I now see that lack of myFunctorFoo == myFunctorFoo support (in the above example) follows from type-erasure, plus no compile time type-trait for has operator==(T,T).

On the off chance; I don't suppose you can make sense of the (to me) cryptic statement at the end of that FAQ item: "The Signals library has a way around this" ?

comment:9 by Marshall Clow, 9 years ago

Resolution: wontfix
Status: reopenedclosed

Boost.Signals is being deprecated. Please transition to Boost.Signals2

Note: See TracTickets for help on using tickets.