111986Sandreas.sandberg@arm.comType conversions
211986Sandreas.sandberg@arm.com################
311986Sandreas.sandberg@arm.com
411986Sandreas.sandberg@arm.comApart from enabling cross-language function calls, a fundamental problem
511986Sandreas.sandberg@arm.comthat a binding tool like pybind11 must address is to provide access to
611986Sandreas.sandberg@arm.comnative Python types in C++ and vice versa. There are three fundamentally
711986Sandreas.sandberg@arm.comdifferent ways to do this—which approach is preferable for a particular type
811986Sandreas.sandberg@arm.comdepends on the situation at hand.
911986Sandreas.sandberg@arm.com
1011986Sandreas.sandberg@arm.com1. Use a native C++ type everywhere. In this case, the type must be wrapped
1111986Sandreas.sandberg@arm.com   using pybind11-generated bindings so that Python can interact with it.
1211986Sandreas.sandberg@arm.com
1311986Sandreas.sandberg@arm.com2. Use a native Python type everywhere. It will need to be wrapped so that
1411986Sandreas.sandberg@arm.com   C++ functions can interact with it.
1511986Sandreas.sandberg@arm.com
1611986Sandreas.sandberg@arm.com3. Use a native C++ type on the C++ side and a native Python type on the
1711986Sandreas.sandberg@arm.com   Python side. pybind11 refers to this as a *type conversion*.
1811986Sandreas.sandberg@arm.com
1911986Sandreas.sandberg@arm.com   Type conversions are the most "natural" option in the sense that native
2011986Sandreas.sandberg@arm.com   (non-wrapped) types are used everywhere. The main downside is that a copy
2111986Sandreas.sandberg@arm.com   of the data must be made on every Python ↔ C++ transition: this is
2211986Sandreas.sandberg@arm.com   needed since the C++ and Python versions of the same type generally won't
2311986Sandreas.sandberg@arm.com   have the same memory layout.
2411986Sandreas.sandberg@arm.com
2511986Sandreas.sandberg@arm.com   pybind11 can perform many kinds of conversions automatically. An overview
2611986Sandreas.sandberg@arm.com   is provided in the table ":ref:`conversion_table`".
2711986Sandreas.sandberg@arm.com
2811986Sandreas.sandberg@arm.comThe following subsections discuss the differences between these options in more
2911986Sandreas.sandberg@arm.comdetail. The main focus in this section is on type conversions, which represent
3011986Sandreas.sandberg@arm.comthe last case of the above list.
3111986Sandreas.sandberg@arm.com
3211986Sandreas.sandberg@arm.com.. toctree::
3311986Sandreas.sandberg@arm.com   :maxdepth: 1
3411986Sandreas.sandberg@arm.com
3511986Sandreas.sandberg@arm.com   overview
3612037Sandreas.sandberg@arm.com   strings
3711986Sandreas.sandberg@arm.com   stl
3811986Sandreas.sandberg@arm.com   functional
3911986Sandreas.sandberg@arm.com   chrono
4011986Sandreas.sandberg@arm.com   eigen
4111986Sandreas.sandberg@arm.com   custom
4211986Sandreas.sandberg@arm.com
43