-
Notifications
You must be signed in to change notification settings - Fork 66
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
Documentation Suggestion (or bug?): operator locations matter #220
Comments
This is related but a bit different: It should also note that if your code defines |
On another inspection, the default |
Thank you for bringing this up @zwimer ! The issue here is that on Python level we do not have global comparison operators similar to global operators in C++ (ie global |
@lyskov Do you happen to have a comprehensive list of operators this is true for? For example, the Another key difference here is likely that the Is it perhaps that all operators whose first argument is I could also add a note that users who wish to follow best practice of defining floating operator functions rather than internal operators can just have the former invoke the latter, which would still maintain all the benefits of free floating functions like implicit conversions. |
-- Binder will look only for member-function-operators for basically all operator bindings that Binder currently supports. You can find full list here: https://github.com/RosettaCommons/binder/blob/master/source/function.cpp#L43
-- yes. re binding of Python
-- This sounds like reasonable approach to me! Thanks, |
Documented via #229 |
The confusion:
I've noticed that these two structs of code lead to different bindings, specifically the second struct generates no
__eq__
method.With my
conf
file saying only+namespace Test
; which should include both equals operators above. I ran binder with the settings--config=/in/a.conf -v --root-module foo --prefix /out /in/include.hpp
whereinclude.hpp
had only#include "a.hpp"
in it. The relevant snippets of output are:Why this is extra bad:
This would be bad in and of itself, but libraries generated using binder have
operator==
defined for everything by default as reference equality. That is, if the user does not scrutinize the output code but rather just verifies (in python) that==
exists by checking if twoA
s equal each other, no exception will be raised but rather the program will call a different==
operator than what the user was likely expecting.My guess as to why this happens:
The reasoning for this is sound, as C++ allows, for example, multiple different
operator==(const A&a, const A&b)
definitions at different namespace scopes, where as python does not. However, this behavior was not intuitive not obvious (especially as good C++ code typically moves operators outside of the class). Actually, this reasoning is just the justification I assume was used, since I couldn't find any information about this in the documentation.The solution:
In the readthedocs, a warning should be added that operators must be defined within a class (or whatever the correct behavior is, I'm just guessing it must be within the class).
The text was updated successfully, but these errors were encountered: