-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Adding pybind11::cast overload for rvalue references #1260
Conversation
Nice! I did something similar in #1237 (but with a much broader scope - your changes are definitely useful, and could hopefully be merged in well before mine): The tests I modified were here, so perhaps yours can go in this same file? |
@EricCousineau-TRI Thanks for the suggestion! However, the test there seems a bit heavy for this PR and I don't want to get you into merge problems afterwards either. So I found a nice spot in the existing tests in Next to that, I collapsed the two |
You're welcome, and good find on collapsing the overloads! |
7b795fe
to
25b130d
Compare
25b130d
to
623c32a
Compare
…ging const T& and T&& to universal reference)
…der, in test_smart_ptr
…erence for pointers in py::cast with universal reference
623c32a
to
1b0c6d8
Compare
It never occurred to me that this isn't already working. 👍 for the simplicity of the change. Let's merge this to master and see if folks experience problems (potentially we'll need to roll back.) |
I'm getting build breaks from this commit. I tried to pass a call to a method returning a |
I was able to avoid the error messages on my side by changing the call from
to
|
Not that I'm aware of, but it's always possible that I overlooked something, of course. |
Let me see if I can generate a failure case in just a few lines of code... |
Ooooh, wait, yes. I see what's going on! By specifying Is there a reason you are writing @wjakob Is this problematic? I could just revert back to have two overloads (the old one for lvalue references, and a new one only for rvalue references). |
Oh, let me try that. I don't know why I was using ... Yes, that seems fine. That's a totally acceptable solution for me. I don't know why I was explicit with the cast previously. |
No problem. Quite an obscure difference, indeed. If more people run into this problem we could decide to revert the commit that unified the two original overloads (see commit history of this PR). Thanks for reporting! |
In the words of STL "do not help the compiler". The thing @lgritz did is one of the things STL really hammered home as one of those that you do not want to do. |
Alright, thanks @bstaletic! Another vote to keep things as they are, for now, then! :-) |
py::cast(std::move(move_only_holder));
does not seem to work in the current version of pybind11. This PR adds a function template to support this.I have not figured out where to add tests, but the current test suite seems to pass with this addition.