-
Notifications
You must be signed in to change notification settings - Fork 42
Added comparison operator to FunctionPointerBase. #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
+1 |
@@ -29,6 +29,11 @@ class FunctionPointerBase { | |||
return (_membercaller != NULL) && (_object != NULL); | |||
} | |||
|
|||
bool operator==(const FunctionPointerBase& other) | |||
{ | |||
return (_membercaller == other._membercaller) && (_object == other._object); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really work properly? membercaller
ends up taking the address of a static function, which is the same for all instances of FunctionPointerX<T>
for a given T. So, for a given instance inst
of type T
, wouldn't this return true for 2 function pointers that reffer to different methods of T
? Sorry if I'm missing something.
I don't think it does. There's also the issue of bound arguments (since FunctionPointerBind derives from this): should they be tested for equality? If so, by POD-value, or by recursively calling |
@bogdanm I see your point. It "works" in my app because testing for object is sufficient in my case. I'm not sure how to make it work properly though. |
As @autopulated pointed out, making it work properly is not trivial, especially the FunctionPointerBind part. I guess we could refactor the code a bit and make FunctionPointerBind include a FunctionPointerBase as opposed to deriving from it, which would simplify the implementation of operator == a bit easier (see also #28) |
It's possible to declare a non-member |
Regarding FunctionPointerBind, testing the arguments for equality and then the derived FunctionPointerBase should be sufficient? |
Yes, assuming the base implementation distinguishes different member functions. |
I tried to compare the content of |
actually... not sure why that wouldn't work. Should be different for different member functions, is it the same? |
It's different for members that should be the same. |
as in this didn't work:
|
Ah – it might include uninitialised memory if the size of the member function pointer is different? member function pointers can even be different sizes depending on the sort of function they point to. See http://www.codeproject.com/Articles/7150/Member-Function-Pointers-and-the-Fastest-Possible |
although apparently not in gcc, hmm :/ |
The only way to handle this safely is to provide a comparison operator static function in FunctionPointer. |
@marcuschangarm, maybe that's an initialization problem? I don't think |
I added that, but it didn't help. I'll do some more debugging when I have the cycles, at the moment just checking the object works in my app. But it sounds like comparing |
@bremoran @bogdanm