Skip to content

Commit

Permalink
Avoid string copy if possible when passing a Python object to std::os…
Browse files Browse the repository at this point in the history
…tream (#3042)
  • Loading branch information
jonathan-conder-sm authored Jul 1, 2021
1 parent cad79c1 commit 733f8de
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/pybind11/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ struct type_caster<std::variant<Ts...>> : variant_caster<std::variant<Ts...>> {
PYBIND11_NAMESPACE_END(detail)

inline std::ostream &operator<<(std::ostream &os, const handle &obj) {
#ifdef PYBIND11_HAS_STRING_VIEW
os << str(obj).cast<std::string_view>();
#else
os << (std::string) str(obj);
#endif
return os;
}

Expand Down

0 comments on commit 733f8de

Please sign in to comment.