You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I claim that it would be worthwhile to allow Python io objects to be wrapped into std::ostreams. Currently, one has to use scoped_ostream_redirect like so:
m.def("foo", [](pybind11::object io) {
std::ostringstream out;
pybind11::scoped_ostream_redirect redirect{out, file};
// rest of code, using `out` as the std::ostream&
});
However, std::ostreamcan be constructed by a std::streambuf. scoped_ostream_redirect uses a streambuf implementation. Thus, it's possible to directly create a std::ostream from the object:
Could be possible. It would be interesting to see how easy it would be to add to pybind11.
If you (or anyone else) feel(s) like submitting a PR, please do!
I claim that it would be worthwhile to allow Python io objects to be wrapped into
std::ostream
s. Currently, one has to usescoped_ostream_redirect
like so:However,
std::ostream
can be constructed by astd::streambuf
.scoped_ostream_redirect
uses astreambuf
implementation. Thus, it's possible to directly create astd::ostream
from the object:What I'm leading up to is this (currently doesn't work):
Which could be used in Python as if it were a regular Python io object:
The text was updated successfully, but these errors were encountered: