ENH: Add to and from object support for std::pair.#72
Open
ssanderson wants to merge 1 commit intomasterfrom
Open
ENH: Add to and from object support for std::pair.#72ssanderson wants to merge 1 commit intomasterfrom
ssanderson wants to merge 1 commit intomasterfrom
Conversation
Delegates to the existing implementation for std::tuple.
llllllllll
reviewed
Jun 14, 2019
|
|
||
| template<typename T, typename U> | ||
| struct from_object<std::pair<T, U>> { | ||
| public: |
Contributor
There was a problem hiding this comment.
we can drop the publics from these structs.
llllllllll
reviewed
Jun 14, 2019
| public: | ||
| static PyObject* f(const std::pair<T, U>& p) { | ||
| // Delegate to std::tuple dispatch. | ||
| return std::move(py::to_object(std::make_tuple(std::get<0>(p), std::get<1>(p)))) |
Contributor
There was a problem hiding this comment.
This will already be an rvalue, so we don't need to move
llllllllll
reviewed
Jun 14, 2019
| public: | ||
| static std::pair<T, U> f(PyObject* tup) { | ||
| std::tuple<T, U> tmp = from_object<std::tuple<T, U>>(tup); | ||
| return std::make_pair(std::get<0>(tmp), std::get<1>(tmp)); |
Contributor
There was a problem hiding this comment.
We should probably move the values from the old tuple in the resulting pair. For things like vector and string this will trigger a copy.
llllllllll
reviewed
Jun 14, 2019
| public: | ||
| static PyObject* f(const std::pair<T, U>& p) { | ||
| // Delegate to std::tuple dispatch. | ||
| return std::move(py::to_object(std::make_tuple(std::get<0>(p), std::get<1>(p)))) |
Contributor
There was a problem hiding this comment.
This is triggering an extra copy. Should we just pull the tuple to_object into a helper base class that accepts tuple-likes and subclass from that? This is how we handle mappings and sequences.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Delegates to the existing implementation for std::tuple.