MCPcopy Create free account
hub / github.com/pybind/pybind11 / execute

Function execute

include/pybind11/detail/init.h:434–460  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432 // class (i.e. not inherited), the alias factory when `self` is a Python-side subtype.
433 template <typename Class, typename... Extra>
434 void execute(Class &cl, const Extra &...extra) && {
435 static_assert(Class::has_alias,
436 "The two-argument version of `py::init()` can "
437 "only be used if the class has an alias");
438#if defined(PYBIND11_CPP14)
439 cl.def(
440 "__init__",
441 [class_func = std::move(class_factory), alias_func = std::move(alias_factory)]
442#else
443 auto &class_func = class_factory;
444 auto &alias_func = alias_factory;
445 cl.def(
446 "__init__",
447 [class_func, alias_func]
448#endif
449 (value_and_holder &v_h, CArgs... args) {
450 if (Py_TYPE(v_h.inst) == v_h.type->type) {
451 // If the instance type equals the registered type we don't have inheritance,
452 // so don't need the alias and can construct using the class function:
453 construct<Class>(v_h, class_func(std::forward<CArgs>(args)...), false);
454 } else {
455 construct<Class>(v_h, alias_func(std::forward<CArgs>(args)...), true);
456 }
457 },
458 is_new_style_constructor(),
459 extra...);
460 }
461};
462
463/// Set just the C++ state. Same as `__init__`.

Callers

nothing calls this directly

Calls 2

moveFunction · 0.85

Tested by

no test coverage detected