pybind11/docs
oremanj fd9bc8f54d Add basic support for tag-based static polymorphism (#1326)
* Add basic support for tag-based static polymorphism

Sometimes it is possible to look at a C++ object and know what its dynamic type is,
even if it doesn't use C++ polymorphism, because instances of the object and its
subclasses conform to some other mechanism for being self-describing; for example,
perhaps there's an enumerated "tag" or "kind" member in the base class that's always
set to an indication of the correct type. This might be done for performance reasons,
or to permit most-derived types to be trivially copyable. One of the most widely-known
examples is in LLVM: https://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html

This PR permits pybind11 to be informed of such conventions via a new specializable
detail::polymorphic_type_hook<> template, which generalizes the previous logic for
determining the runtime type of an object based on C++ RTTI. Implementors provide
a way to map from a base class object to a const std::type_info* for the dynamic
type; pybind11 then uses this to ensure that casting a Base* to Python creates a
Python object that knows it's wrapping the appropriate sort of Derived.

There are a number of restrictions with this tag-based static polymorphism support
compared to pybind11's existing support for built-in C++ polymorphism:

- there is no support for this-pointer adjustment, so only single inheritance is permitted
- there is no way to make C++ code call new Python-provided subclasses
- when binding C++ classes that redefine a method in a subclass, the .def() must be
  repeated in the binding for Python to know about the update

But these are not much of an issue in practice in many cases, the impact on the
complexity of pybind11's innards is minimal and localized, and the support for
automatic downcasting improves usability a great deal.
2018-04-14 02:13:10 +02:00
..
_static documentation improvements 2016-04-26 23:48:55 +02:00
advanced Add basic support for tag-based static polymorphism (#1326) 2018-04-14 02:13:10 +02:00
basics.rst Update build commands for Linux / OS X in the docs (#907) 2017-08-30 21:58:43 +02:00
benchmark.py Replace PYBIND11_PLUGIN with PYBIND11_MODULE 2017-05-29 03:21:19 +02:00
benchmark.rst Replace PYBIND11_PLUGIN with PYBIND11_MODULE 2017-05-29 03:21:19 +02:00
changelog.rst added v2.2.2 changelog 2018-02-07 11:05:41 +01:00
classes.rst Add basic support for tag-based static polymorphism (#1326) 2018-04-14 02:13:10 +02:00
compiling.rst Update build commands for Linux / OS X in the docs (#907) 2017-08-30 21:58:43 +02:00
conf.py updated version flags for next version 2017-08-31 14:01:08 +02:00
Doxyfile Fix documentation build 2017-08-17 15:10:51 +02:00
faq.rst Correct VS version in FAQ 2018-03-10 14:19:31 -04:00
index.rst Add upgrade guide to the documentation 2017-08-21 01:12:45 +02:00
intro.rst Use semi-constexpr signatures on MSVC 2017-09-16 12:02:49 +02:00
limitations.rst Multiple inheritance support 2016-09-19 13:45:31 +02:00
Makefile took a stab at some documentation 2015-10-13 03:16:44 +02:00
pybind11_vs_boost_python1.png documentation improvements 2016-04-28 15:32:07 +02:00
pybind11_vs_boost_python1.svg Much more efficient generation of function signatures, updated docs 2016-01-17 22:31:15 +01:00
pybind11_vs_boost_python2.png documentation improvements 2016-04-28 15:32:07 +02:00
pybind11_vs_boost_python2.svg Much more efficient generation of function signatures, updated docs 2016-01-17 22:31:15 +01:00
pybind11-logo.png Very minor documentation fixes, updated logo 2016-01-17 22:31:15 +01:00
reference.rst Utility for redirecting C++ streams to Python (#1009) 2017-08-25 02:12:43 +02:00
release.rst fix release.rst instructions for conda-forge SHA checksum 2017-08-31 23:05:47 +02:00
requirements.txt Fix readthedocs build (#721) 2017-03-12 22:36:48 +01:00
upgrade.rst Add upgrade guide entry about stricter compile-time checks 2017-09-04 23:01:34 +02:00