www.luxoft.com
Kyrylo Cherneha
C++ developer
C++ & Python
interaction in
automotive industry
www.luxoft.com
Agenda
QA vs Developers
Testing
Why Python?
Frameworks/Tools/Libraries
Pybind11/Boost.Python
Conclusion
www.luxoft.com
QA vs Developers
www.luxoft.com
Unit testing
• Gtest
• CPPtest
• Catch
• Boost.Test
• etc
www.luxoft.com
Integration testing
www.luxoft.com
How we do IT
First
component
test
Second
component
test
Integration
test
www.luxoft.com
Small prinC++
www.luxoft.com
Why Python?
www.luxoft.com
Frameworks/Tools/Libraries
https://github.com/cython/cython/wiki/WrappingCorCpp
www.luxoft.com
Boost.Python
Python programmer walks into a bar and asks for something imported.
The bindings are fast, but the C++ files compile very slowly and it's very difficult to debug
(several pages of C++ errors in templates if you make a mistake in your code).
www.luxoft.com
Hello
www.luxoft.com
Pybind11 – Feature Mapping
• Functions accepting and returning custom data structures per value, reference, or pointer
• Instance methods and static methods, Overloaded functions
• Instance attributes and static attributes
• Arbitrary exception types
• Enumerations, Callbacks
• Iterators and ranges, Custom operators
• Single and multiple inheritance
• STL data structures
• Smart pointers with reference counting like std::shared_ptr
• Internal references with correct reference counting
• C++ classes with virtual (and pure virtual) methods can be extended in Python
www.luxoft.com
Pybind11
www.luxoft.com
Pybind11 (Continue)
PYBIND11_OVERLOAD_PURE(/*params*/)
PYBIND11_EMBEDDED_MODULE(bindings, m)
// m – is a py::module which is used to bind functions and classes
pybind11 is a header-only library, hence it is not necessary to link against any special libraries and there are
no intermediate (magic) translation steps.
find_package( PythonInterp REQUIRED )
find_package( PythonLibs REQUIRED )
www.luxoft.com
All you need is … Python
www.luxoft.com
Comparison of usage
description Boost pybind11
C++, python type convert boost::python::extract
py::cast(cls)
obj.cast<MyClass *>()
Python type in C++
boost::python::list
boost::python::tuple
py::list
py::tuple
Python type in C++ boost::python::make_tuple py::make_tuple
Classe declaration boost::python::class_ py::class_
Classe declaration boost::python::class_("name","descr",init<>)
py::class_(m, "name","descr")
.def(init<>())
Split classe declaration
some file
void bind_matrix() void bind_matrix(py::module& m)
property setter getter .add_property .def_readwrite
www.luxoft.com
P.S.
• Fast code writing for parsing files (xml, json)
• Some useful features for user (like calling bash/shell, working with directories, OS, processes,
etc)
• Just a joke about PHP (why not?):
• A piece of PHP code walks into a bar. The bartender informs it that they don't serve spaghetti
there, so it turns around and leaves.
• Spoiler for C++23: pointers will be removed.
www.luxoft.com
Thank you

Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"