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: | 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)
Change History (10)
by , 15 years ago
Attachment: | testcase.cpp added |
---|
comment:1 by , 15 years ago
Owner: | set to |
---|
comment:2 by , 14 years ago
comment:3 by , 14 years ago
Owner: | changed from | to
---|
comment:4 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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:6 by , 13 years ago
Cc: | added |
---|---|
Resolution: | invalid |
Status: | closed → reopened |
In:
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 , 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 , 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 , 9 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
Boost.Signals is being deprecated. Please transition to Boost.Signals2
The problem can also be reproduced with VC++ 9.0. Upgrading the compiler won't help unfortunately.