github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/pybind11/docs/advanced/cast/index.rst (about)

     1  .. _type-conversions:
     2  
     3  Type conversions
     4  ################
     5  
     6  Apart from enabling cross-language function calls, a fundamental problem
     7  that a binding tool like pybind11 must address is to provide access to
     8  native Python types in C++ and vice versa. There are three fundamentally
     9  different ways to do this—which approach is preferable for a particular type
    10  depends on the situation at hand.
    11  
    12  1. Use a native C++ type everywhere. In this case, the type must be wrapped
    13     using pybind11-generated bindings so that Python can interact with it.
    14  
    15  2. Use a native Python type everywhere. It will need to be wrapped so that
    16     C++ functions can interact with it.
    17  
    18  3. Use a native C++ type on the C++ side and a native Python type on the
    19     Python side. pybind11 refers to this as a *type conversion*.
    20  
    21     Type conversions are the most "natural" option in the sense that native
    22     (non-wrapped) types are used everywhere. The main downside is that a copy
    23     of the data must be made on every Python ↔ C++ transition: this is
    24     needed since the C++ and Python versions of the same type generally won't
    25     have the same memory layout.
    26  
    27     pybind11 can perform many kinds of conversions automatically. An overview
    28     is provided in the table ":ref:`conversion_table`".
    29  
    30  The following subsections discuss the differences between these options in more
    31  detail. The main focus in this section is on type conversions, which represent
    32  the last case of the above list.
    33  
    34  .. toctree::
    35     :maxdepth: 1
    36  
    37     overview
    38     strings
    39     stl
    40     functional
    41     chrono
    42     eigen
    43     custom