Classes | Functions
iostream.h File Reference
#include "pybind11.h"
#include <algorithm>
#include <cstring>
#include <iostream>
#include <iterator>
#include <memory>
#include <ostream>
#include <streambuf>
#include <string>
#include <utility>
Include dependency graph for iostream.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  OstreamRedirect
 
class  pythonbuf
 
class  scoped_estream_redirect
 
class  scoped_ostream_redirect
 

Functions

class_< detail::OstreamRedirect > add_ostream_redirect (module_ m, const std::string &name="ostream_redirect")
 

Function Documentation

◆ add_ostream_redirect()

class_<detail::OstreamRedirect> add_ostream_redirect ( module_  m,
const std::string &  name = "ostream_redirect" 
)
inline

This is a helper function to add a C++ redirect context manager to Python instead of using a C++ guard. To use it, add the following to your binding code:

.. code-block:: cpp

#include <pybind11/iostream.h>

...

py::add_ostream_redirect(m, "ostream_redirect");

You now have a Python context manager that redirects your output:

.. code-block:: python

with m.ostream_redirect():
    m.print_to_cout_function()

This manager can optionally be told which streams to operate on:

.. code-block:: python

with m.ostream_redirect(stdout=true, stderr=true):
    m.noisy_function_with_error_printing()

Definition at line 258 of file iostream.h.



gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:40:49