Back to home page

EIC code displayed by LXR

 
 

    


Warning, /jana2/src/python/externals/pybind11-2.10.3/docs/advanced/cast/index.rst is written in an unsupported language. File is not indexed.

0001 .. _type-conversions:
0002 
0003 Type conversions
0004 ################
0005 
0006 Apart from enabling cross-language function calls, a fundamental problem
0007 that a binding tool like pybind11 must address is to provide access to
0008 native Python types in C++ and vice versa. There are three fundamentally
0009 different ways to do this—which approach is preferable for a particular type
0010 depends on the situation at hand.
0011 
0012 1. Use a native C++ type everywhere. In this case, the type must be wrapped
0013    using pybind11-generated bindings so that Python can interact with it.
0014 
0015 2. Use a native Python type everywhere. It will need to be wrapped so that
0016    C++ functions can interact with it.
0017 
0018 3. Use a native C++ type on the C++ side and a native Python type on the
0019    Python side. pybind11 refers to this as a *type conversion*.
0020 
0021    Type conversions are the most "natural" option in the sense that native
0022    (non-wrapped) types are used everywhere. The main downside is that a copy
0023    of the data must be made on every Python ↔ C++ transition: this is
0024    needed since the C++ and Python versions of the same type generally won't
0025    have the same memory layout.
0026 
0027    pybind11 can perform many kinds of conversions automatically. An overview
0028    is provided in the table ":ref:`conversion_table`".
0029 
0030 The following subsections discuss the differences between these options in more
0031 detail. The main focus in this section is on type conversions, which represent
0032 the last case of the above list.
0033 
0034 .. toctree::
0035    :maxdepth: 1
0036 
0037    overview
0038    strings
0039    stl
0040    functional
0041    chrono
0042    eigen
0043    custom