Commit 733f8de2 by jonathan-conder-sm Committed by GitHub

Avoid string copy if possible when passing a Python object to std::ostream (#3042)

parent cad79c11
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment