Go to the documentation of this file.
31 static constexpr
auto name = const_name<value_and_holder>();
41 throw type_error(
"pybind11::init(): factory function returned nullptr");
46 template <
typename Class>
48 template <
typename Class>
49 using Alias =
typename Class::type_alias;
50 template <
typename Class>
51 using Holder =
typename Class::holder_type;
53 template <
typename Class>
57 template <
typename Class, enable_if_t<Class::has_alias,
int> = 0>
72 template <
typename Class,
76 return new Class(std::forward<Args>(
args)...);
78 template <
typename Class,
82 return new Class{std::forward<Args>(
args)...};
90 template <
typename Class>
96 template <
typename Class>
100 throw type_error(
"pybind11::init(): unable to convert returned instance to required "
101 "alias class: no `Alias<Class>(Class &&)` constructor available");
106 template <
typename Class>
109 "pybind11::init(): init function must return a compatible pointer, "
117 template <
typename Class>
121 if (Class::has_alias && need_alias && !is_alias<Class>(ptr)) {
132 v_h.
type->init_instance(v_h.
inst,
nullptr);
134 v_h.
type->dealloc(v_h);
146 template <
typename Class, enable_if_t<Class::has_alias,
int> = 0>
156 template <
typename Class>
162 if (Class::has_alias && need_alias && !is_alias<Class>(ptr)) {
163 throw type_error(
"pybind11::init(): construction failed: returned holder-wrapped instance "
164 "is not an alias instance");
168 v_h.
type->init_instance(v_h.
inst, &holder);
175 template <
typename Class>
179 "pybind11::init() return-by-value factory function requires a movable class");
180 if (Class::has_alias && need_alias) {
190 template <
typename Class>
194 "pybind11::init() return-by-alias-value factory function requires a movable alias class");
199 template <
typename... Args>
206 v_h.value_ptr() = construct_or_initialize<Cpp<Class>>(std::forward<Args>(args)...);
221 if (Py_TYPE(v_h.inst) == v_h.type->type) {
223 = construct_or_initialize<Cpp<Class>>(std::forward<Args>(args)...);
226 = construct_or_initialize<Alias<Class>>(std::forward<Args>(args)...);
243 = construct_or_initialize<Alias<Class>>(std::forward<Args>(args)...);
251 template <
typename... Args>
263 = construct_or_initialize<Alias<Class>>(std::forward<Args>(args)...);
271 template <
typename CFunc,
278 template <
typename Func,
typename Return,
typename... Args>
290 template <
typename Class,
typename... Extra>
292 #if defined(PYBIND11_CPP14)
295 [
func = std::move(class_factory)]
297 auto &
func = class_factory;
304 v_h, func(std::forward<Args>(args)...), Py_TYPE(v_h.inst) != v_h.type->type);
312 template <
typename CFunc,
318 struct factory<CFunc, AFunc, CReturn(CArgs...), AReturn(AArgs...)> {
319 static_assert(
sizeof...(CArgs) ==
sizeof...(AArgs),
320 "pybind11::init(class_factory, alias_factory): class and alias factories "
321 "must have identical argument signatures");
322 static_assert(
all_of<std::is_same<CArgs, AArgs>...>::
value,
323 "pybind11::init(class_factory, alias_factory): class and alias factories "
324 "must have identical argument signatures");
334 template <
typename Class,
typename... Extra>
336 static_assert(Class::has_alias,
337 "The two-argument version of `py::init()` can "
338 "only be used if the class has an alias");
339 #if defined(PYBIND11_CPP14)
342 [class_func = std::move(class_factory), alias_func = std::move(alias_factory)]
344 auto &class_func = class_factory;
345 auto &alias_func = alias_factory;
348 [class_func, alias_func]
351 if (Py_TYPE(v_h.inst) == v_h.type->type) {
354 construct<Class>(v_h, class_func(std::forward<CArgs>(args)...), false);
356 construct<Class>(v_h, alias_func(std::forward<CArgs>(args)...), true);
365 template <
typename Class,
typename T>
367 construct<Class>(v_h, std::forward<T>(
result), need_alias);
371 template <
typename Class,
376 construct<Class>(v_h, std::move(
result.first), need_alias);
378 if (PyDict_Check(
d.ptr()) && PyDict_Size(
d.ptr()) == 0) {
387 template <
typename Get,
393 template <
typename Get,
397 typename NewInstance,
401 "The type returned by `__getstate__` must be the same "
402 "as the argument accepted by `__setstate__`");
409 template <
typename Class,
typename... Extra>
411 cl.def(
"__getstate__", std::move(
get));
413 #if defined(PYBIND11_CPP14)
static void execute(Class &cl, const Extra &...extra)
remove_reference_t< Func > class_factory
std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... > > all_of
typename Class::type_alias Alias
Annotation for function names.
void setattr(handle obj, handle name, handle value)
Annotation indicating that a class derives from another given type.
factory(CFunc &&c, AFunc &&a)
static const double d[K][N]
void setstate(value_and_holder &v_h, T &&result, bool need_alias)
Set just the C++ state. Same as __init__.
void execute(Class &cl, const Extra &...extra) &&
#define PYBIND11_NAMESPACE_END(name)
void execute(Class &cl, const Extra &...extra) &&
Eigen::Triplet< double > T
#define PYBIND11_NAMESPACE_BEGIN(name)
Implementation for py::pickle(GetState, SetState)
void construct_alias_from_cpp(std::true_type, value_and_holder &v_h, Cpp< Class > &&base)
void set_instance_registered(bool v=true)
typename intrinsic_type< T >::type intrinsic_t
pickle_factory(Get get, Set set)
Tag for a new-style __init__ defined in detail/init.h
remove_reference_t< Get > get
void execute(Class &cl, const Extra &...extra) &&
std::is_constructible< Alias< Class >, Cpp< Class > && > is_alias_constructible
bool is_alias(Cpp< Class > *ptr)
static void execute(Class &cl, const Extra &...extra)
A small structure to hold a non zero as a triplet (i,j,value).
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
remove_reference_t< AFunc > alias_factory
#define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
conditional_t< std::is_function< F >::value, F, typename conditional_t< std::is_pointer< F >::value||std::is_member_pointer< F >::value, std::remove_pointer< F >, strip_function_object< F > >::type > function_signature_t
typename Class::holder_type Holder
PYBIND11_WARNING_PUSH PYBIND11_WARNING_DISABLE_MSVC(5054) PYBIND11_WARNING_POP static_assert(EIGEN_VERSION_AT_LEAST(3
Helper type to replace 'void' in some expressions.
void no_nullptr(void *ptr)
Class * construct_or_initialize(Args &&...args)
Container::iterator get(Container &c, Position position)
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
remove_reference_t< CFunc > class_factory
const detail::type_info * type
bool load(handle h, bool)
typename std::remove_reference< T >::type remove_reference_t
remove_reference_t< Set > set
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:28