Skip to content

Conversation

@jonathan-conder-sm
Copy link
Contributor

@jonathan-conder-sm jonathan-conder-sm commented Jun 17, 2021

Description

Changes operator<<(std::ostream &, const handle &) to delegate to operator<<(std::ostream &, std::string_view) if possible. If I understand the type caster for string_view correctly, I think this avoids an unnecessary copy.

The PYBIND11_HAS_STRING_VIEW macro is defined in cast.h, which is indirectly included by stl.h. If that's likely to change in future, it might be desirable to move the macro to internals.h or something.

Suggested changelog entry:

Use ``std::string_view`` if available to avoid a copy when passing an object to a ``std::ostream``.

@rwgk
Copy link
Collaborator

rwgk commented Jul 1, 2021

Thanks!

@rwgk rwgk merged commit 733f8de into pybind:master Jul 1, 2021
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jul 1, 2021
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants