mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 13:15:12 +00:00
Avoid string copy if possible when passing a Python object to std::ostream (#3042)
This commit is contained in:
parent
cad79c1146
commit
733f8de24f
@ -380,7 +380,11 @@ struct type_caster<std::variant<Ts...>> : variant_caster<std::variant<Ts...>> {
|
|||||||
PYBIND11_NAMESPACE_END(detail)
|
PYBIND11_NAMESPACE_END(detail)
|
||||||
|
|
||||||
inline std::ostream &operator<<(std::ostream &os, const handle &obj) {
|
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);
|
os << (std::string) str(obj);
|
||||||
|
#endif
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user