Go to the documentation of this file.
27 #include <type_traits>
37 template <typename
type, typename SFINAE =
void>
39 template <
typename type>
46 return caster.operator result_t();
53 return std::move(caster).operator result_t();
56 template <
typename type>
67 "std::reference_wrapper<T> caster requires T to have a caster with an "
68 "`operator T &()` or `operator const T &()`");
84 explicit operator std::reference_wrapper<type>() {
return cast_op<type &>(subcaster); }
87 #define PYBIND11_TYPE_CASTER(type, py_name) \
92 static constexpr auto name = py_name; \
93 template <typename T_, \
94 ::pybind11::detail::enable_if_t< \
95 std::is_same<type, ::pybind11::detail::remove_cv_t<T_>>::value, \
98 static ::pybind11::handle cast( \
99 T_ *src, ::pybind11::return_value_policy policy, ::pybind11::handle parent) { \
101 return ::pybind11::none().release(); \
102 if (policy == ::pybind11::return_value_policy::take_ownership) { \
103 auto h = cast(std::move(*src), policy, parent); \
107 return cast(*src, policy, parent); \
109 operator type *() { return &value; } \
110 operator type &() { return value; } \
111 operator type &&() && { return std::move(value); } \
112 template <typename T_> \
113 using cast_op_type = ::pybind11::detail::movable_cast_op_type<T_>
115 template <
typename CharT>
117 #if defined(PYBIND11_HAS_U8STRING)
118 std::is_same<CharT, char8_t>,
120 std::is_same<CharT, char16_t>,
121 std::is_same<CharT, char32_t>,
122 std::is_same<CharT, wchar_t>
125 template <
typename T>
141 #if !defined(PYPY_VERSION)
142 auto index_check = [](PyObject *o) {
return PyIndex_Check(o); };
146 auto index_check = [](PyObject *o) {
return hasattr(o,
"__index__"); };
151 py_value = (
py_type) PyFloat_AsDouble(src.
ptr());
155 }
else if (PyFloat_Check(src.
ptr())
159 handle src_or_index = src;
161 #if PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION)
164 index = reinterpret_steal<object>(PyNumber_Index(src.
ptr()));
170 src_or_index = index;
175 py_value = as_unsigned<py_type>(src_or_index.
ptr());
177 py_value =
sizeof(
T) <=
sizeof(
long)
184 bool py_err = py_value == (
py_type) -1 && PyErr_Occurred();
190 && py_value != (
py_type) (
T) py_value)) {
192 if (py_err &&
convert && (PyNumber_Check(src.
ptr()) != 0)) {
194 ? PyNumber_Float(src.
ptr())
195 : PyNumber_Long(src.
ptr()));
197 return load(tmp,
false);
206 template <
typename U = T>
209 return PyFloat_FromDouble((
double) src);
212 template <
typename U = T>
214 && (
sizeof(
U) <=
sizeof(
long)),
220 template <
typename U = T>
222 && (
sizeof(
U) <=
sizeof(
unsigned long)),
228 template <
typename U = T>
230 && (
sizeof(
U) >
sizeof(
long)),
233 return PyLong_FromLongLong((
long long) src);
236 template <
typename U = T>
238 && (
sizeof(
U) >
sizeof(
unsigned long)),
241 return PyLong_FromUnsignedLongLong((
unsigned long long) src);
247 template <
typename T>
251 if (src && src.is_none()) {
280 if (isinstance<capsule>(
h)) {
281 value = reinterpret_borrow<capsule>(
h);
287 if (bases.size() == 1) {
303 template <
typename T>
305 explicit operator void *&() {
return value; }
322 if (src.
ptr() == Py_True) {
326 if (src.
ptr() == Py_False) {
330 if (
convert || is_numpy_bool(src)) {
338 #if defined(PYPY_VERSION)
341 res = PyObject_IsTrue(src.
ptr());
346 else if (
auto *tp_as_number = src.
ptr()->ob_type->tp_as_number) {
352 if (
res == 0 ||
res == 1) {
368 const char *
type_name = Py_TYPE(
object.ptr())->tp_name;
370 return std::strcmp(
"numpy.bool",
type_name) == 0
371 || std::strcmp(
"numpy.bool_",
type_name) == 0;
376 template <
typename StringType,
bool IsView = false>
378 using CharT =
typename StringType::value_type;
383 "Unsupported char size != 1");
384 #if defined(PYBIND11_HAS_U8STRING)
386 "Unsupported char8_t size != 1");
389 "Unsupported char16_t size != 2");
391 "Unsupported char32_t size != 4");
394 "Unsupported wchar_t size != 2/4");
402 if (!PyUnicode_Check(load_src.
ptr())) {
409 Py_ssize_t
size = -1;
411 =
reinterpret_cast<const CharT *
>(PyUnicode_AsUTF8AndSize(load_src.
ptr(), &
size));
421 = reinterpret_steal<object>(PyUnicode_AsEncodedString(load_src.
ptr(),
423 :
UTF_N == 16 ?
"utf-16"
451 const char *
buffer =
reinterpret_cast<const char *
>(src.data());
464 #if !defined(PYPY_VERSION)
465 return UTF_N == 8 ? PyUnicode_DecodeUTF8(
buffer, nbytes,
nullptr)
466 :
UTF_N == 16 ? PyUnicode_DecodeUTF16(
buffer, nbytes,
nullptr,
nullptr)
467 : PyUnicode_DecodeUTF32(
buffer, nbytes,
nullptr,
nullptr);
472 return PyUnicode_Decode(
buffer,
475 :
UTF_N == 16 ?
"utf-16"
484 template <
typename C = CharT>
491 pybind11_fail(
"Unexpected PYBIND11_BYTES_AS_STRING() failure.");
496 if (PyByteArray_Check(src.ptr())) {
499 const char *
bytearray = PyByteArray_AsString(src.ptr());
503 value = StringType(
bytearray, (
size_t) PyByteArray_Size(src.ptr()));
510 template <
typename C = CharT>
516 template <
typename CharT,
class Traits,
class Allocator>
519 :
string_caster<std::basic_string<CharT, Traits, Allocator>> {};
521 #ifdef PYBIND11_HAS_STRING_VIEW
522 template <
typename CharT,
class Traits>
525 :
string_caster<std::basic_string_view<CharT, Traits>, true> {};
530 template <
typename CharT>
555 if (src ==
nullptr) {
556 return pybind11::none().release();
563 handle s = PyUnicode_DecodeLatin1((
const char *) &src, 1,
nullptr);
572 explicit operator CharT *() {
573 return none ? nullptr :
const_cast<CharT *
>(
static_cast<StringType &
>(str_caster).
c_str());
575 explicit operator CharT &() {
577 throw value_error(
"Cannot convert None to a character");
581 size_t str_len =
value.size();
583 throw value_error(
"Cannot convert empty string to a character");
591 if (StringCaster::UTF_N == 8 && str_len > 1 && str_len <= 4) {
592 auto v0 =
static_cast<unsigned char>(
value[0]);
597 size_t char0_bytes = (
v0 & 0x80) == 0 ? 1
598 : (
v0 & 0xE0) == 0xC0 ? 2
599 : (
v0 & 0xF0) == 0xE0 ? 3
602 if (char0_bytes == str_len) {
604 if (char0_bytes == 2 && (
v0 & 0xFC) == 0xC0) {
605 one_char =
static_cast<CharT
>(((
v0 & 3) << 6)
606 + (
static_cast<unsigned char>(
value[1]) & 0x3F));
610 throw value_error(
"Character code point not in range(0x100)");
617 else if (StringCaster::UTF_N == 16 && str_len == 2) {
618 one_char =
static_cast<CharT
>(
value[0]);
619 if (one_char >= 0xD800 && one_char < 0xE000) {
620 throw value_error(
"Character code point not in range(0x10000)");
625 throw value_error(
"Expected a character, but multi-character string found");
633 template <
typename _T>
638 template <
template <
typename...>
class Tuple,
typename... Ts>
641 static constexpr
auto size =
sizeof...(Ts);
646 if (!isinstance<sequence>(src)) {
649 const auto seq = reinterpret_borrow<sequence>(src);
656 template <
typename T>
662 template <
typename T>
668 auto h =
cast(std::move(*src), policy, parent);
672 return cast(*src, policy, parent);
679 template <
typename T>
683 explicit operator type() && {
return std::move(*this).implicit_cast(
indices{}); }
686 template <
size_t... Is>
690 template <
size_t... Is>
697 template <
size_t... Is>
699 #ifdef __cpp_fold_expressions
714 template <
typename T,
size_t... Is>
719 std::array<object, size> entries{{reinterpret_steal<object>(
721 for (
const auto &entry : entries) {
728 for (
auto &entry : entries) {
729 PyTuple_SET_ITEM(
result.ptr(), counter++, entry.release().ptr());
737 template <
typename T1,
typename T2>
740 template <
typename... Ts>
745 template <
typename T>
747 static auto get(
const T &
p) -> decltype(
p.get()) {
return p.get(); }
755 template <
typename type,
typename holder_type,
typename SFINAE =
void>
760 "Holder classes are only supported for custom types");
767 return base::template load_impl<copyable_holder_caster<type, holder_type>>(src,
convert);
774 explicit operator holder_type *() {
return std::addressof(
holder); }
775 explicit operator holder_type &() {
return holder; }
786 throw cast_error(
"Unable to load a custom holder type from a default-holder instance");
791 if (v_h.holder_constructed()) {
792 value = v_h.value_ptr();
793 holder = v_h.template holder<holder_type>();
796 throw cast_error(
"Unable to cast from non-held to held instance (T& to Holder<T>) "
798 "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for "
799 "type information)");
802 + type_id<holder_type>() +
"''");
806 template <
typename T = holder_type,
812 template <
typename T = holder_type,
832 template <
typename T>
838 template <
typename type,
typename holder_type,
typename SFINAE =
void>
841 "Holder classes are only supported for custom types");
850 template <
typename type,
typename deleter>
854 template <
typename type,
typename holder_type>
859 template <
typename T,
bool Value = false>
861 static constexpr
bool value = Value;
865 #define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type, ...) \
866 PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) \
868 template <typename type> \
869 struct always_construct_holder<holder_type> : always_construct_holder<void, ##__VA_ARGS__> { \
871 template <typename type> \
872 class type_caster<holder_type, enable_if_t<!is_shared_ptr<holder_type>::value>> \
873 : public type_caster_holder<type, holder_type> {}; \
875 PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
878 template <
typename base,
typename holder>
880 : std::is_base_of<detail::type_caster_holder<base, holder>, detail::type_caster<holder>> {};
882 template <
typename base,
typename deleter>
885 #ifdef PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION // See PR #4888
888 template <
typename T>
893 template <
typename T>
895 static constexpr
auto name = const_name<T>();
1014 static constexpr
auto name = const_name<obj_attr_accessor>();
1018 static constexpr
auto name = const_name<str_attr_accessor>();
1022 static constexpr
auto name = const_name<item_accessor>();
1026 static constexpr
auto name = const_name<sequence_accessor>();
1030 static constexpr
auto name = const_name<list_accessor>();
1034 static constexpr
auto name = const_name<tuple_accessor>();
1037 template <
typename type>
1050 return static_cast<bool>(
value);
1055 if (!isinstance<type>(src)) {
1058 value = reinterpret_borrow<type>(src);
1068 template <
typename T>
1080 template <
typename T>
1083 template <
typename T,
typename SFINAE =
void>
1085 template <
typename T>
1092 std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>
::value>>
1093 : std::true_type {};
1094 template <
typename T,
typename SFINAE =
void>
1096 template <
typename T>
1103 std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>
::value>>
1104 : std::true_type {};
1105 template <
typename T>
1112 template <
typename type>
1121 template <
typename Return,
typename SFINAE =
void>
1126 template <
typename Return>
1129 detail::
enable_if_t<std::is_base_of<type_caster_generic, make_caster<Return>>::value, void>> {
1138 template <
typename T,
typename SFINAE>
1141 "Internal error: type_caster should only be used for C++ types");
1143 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1145 "Unable to cast Python instance of type "
1147 +
" to C++ type '?' (#define "
1148 "PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1150 throw cast_error(
"Unable to cast Python instance of type "
1152 + type_id<T>() +
"'");
1158 template <
typename T>
1168 template <
typename T,
1176 "Unable to cast type to reference: value is local to type caster");
1177 return cast_op<T>(load_type<T>(
handle));
1183 return T(reinterpret_borrow<object>(
handle));
1194 template <
typename T,
1204 template <
typename T,
1211 return obj.release().ptr();
1229 return reinterpret_steal<object>(
1233 template <
typename T>
1235 return pybind11::cast<T>(*
this);
1242 template <
typename T>
1244 if (obj.ref_count() > 1) {
1245 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1248 +
" instance to C++ rvalue: instance has multiple references"
1249 " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1251 throw cast_error(
"Unable to move from Python "
1253 + type_id<T>() +
" instance: instance has multiple references");
1258 T ret = std::move(detail::load_type<T>(obj).
operator T &());
1267 template <
typename T>
1270 return move<T>(std::move(
object));
1272 template <
typename T>
1275 if (
object.ref_count() > 1) {
1276 return cast<T>(
object);
1278 return move<T>(std::move(
object));
1280 template <
typename T>
1283 return cast<T>(
object);
1287 template <
typename T>
1289 return T(std::move(
object));
1292 template <
typename T>
1294 return pybind11::cast<T>(*
this);
1296 template <
typename T>
1298 return pybind11::cast<T>(std::move(*
this));
1320 template <
typename ret_type>
1327 template <
typename T>
1330 return cast_op<T>(
load_type(caster, o));
1332 template <
typename T>
1341 template <
typename T>
1346 pybind11_fail(
"Internal error: cast_safe fallback invoked");
1348 template <
typename T>
1350 template <
typename T>
1353 return o.release().ptr();
1355 template <
typename T>
1357 detail::is_same_ignoring_cvref<T, PyObject *>,
1361 return pybind11::cast<T>(std::move(o));
1368 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1370 return cast_error(
"Unable to convert call argument '" +
name
1371 +
"' to Python object (#define "
1372 "PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1376 const std::string &
type) {
1377 return cast_error(
"Unable to convert call argument '" +
name +
"' of type '" +
type
1378 +
"' to Python object");
1382 template <return_value_policy policy = return_value_policy::automatic_reference>
1389 constexpr
size_t size =
sizeof...(Args);
1390 std::array<object, size>
args{{reinterpret_steal<object>(
1394 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1397 std::array<std::string, size> argtypes{{type_id<Args>()...}};
1404 for (
auto &arg_value :
args) {
1405 PyTuple_SET_ITEM(
result.ptr(), counter++, arg_value.release().ptr());
1415 constexpr
explicit arg(
const char *
name =
nullptr)
1418 template <
typename T>
1441 template <
typename T>
1446 #if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1454 if (PyErr_Occurred()) {
1461 template <
typename T>
1466 template <
typename T>
1486 #if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1502 template <
typename T>
1504 return {*
this, std::forward<T>(
value)};
1508 template <
typename >
1516 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5
1528 template <
typename T>
1530 template <
typename T>
1561 template <
typename... Args>
1565 template <
typename Arg>
1567 template <
typename Arg>
1573 "py::kwargs is only permitted as the last argument of a function");
1581 static_assert(
args_pos == -1 ||
args_pos == constexpr_first<argument_is_args, Args...>(),
1582 "py::args cannot be specified more than once");
1589 template <
typename Return,
typename Guard,
typename Func>
1593 std::forward<Func>(
f),
indices{}, Guard{});
1596 template <
typename Return,
typename Guard,
typename Func>
1599 std::forward<Func>(
f),
indices{}, Guard{});
1606 template <
size_t... Is>
1608 #ifdef __cpp_fold_expressions
1613 for (
bool r : {std::get<Is>(
argcasters).load(
call.args[Is],
call.args_convert[Is])...}) {
1622 template <
typename Return,
typename Func,
size_t... Is,
typename Guard>
1624 return std::forward<Func>(
f)(cast_op<Args>(std::move(std::get<Is>(
argcasters)))...);
1632 template <return_value_policy policy>
1635 template <
typename... Ts>
1650 return reinterpret_steal<object>(
result);
1658 template <return_value_policy policy>
1661 template <
typename... Ts>
1665 auto args_list = list();
1666 using expander =
int[];
1667 (void) expander{0, (
process(args_list, std::forward<Ts>(
values)), 0)...};
1669 m_args = std::move(args_list);
1684 return reinterpret_steal<object>(
result);
1688 template <
typename T>
1690 auto o = reinterpret_steal<object>(
1693 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1700 args_list.append(std::move(o));
1703 void process(list &args_list, detail::args_proxy ap) {
1705 args_list.append(
a);
1711 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1718 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1725 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1738 for (
auto k : reinterpret_borrow<dict>(kp)) {
1740 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1752 "Got kwargs without a name; only named arguments "
1753 "may be passed via py::arg() to a python function call. "
1754 "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1757 throw type_error(
"Got kwargs without a name of type '" +
type
1759 "arguments may be passed via py::arg() to a python function call. ");
1763 "Got multiple values for keyword argument "
1764 "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1768 throw type_error(
"Got multiple values for keyword argument '" +
name +
"'");
1780 template <
typename... Args>
1799 static_assert(constexpr_last<is_positional, Args...>()
1800 < constexpr_first<is_keyword_or_ds, Args...>()
1801 && constexpr_last<is_s_unpacking, Args...>()
1802 < constexpr_first<is_ds_unpacking, Args...>(),
1803 "Invalid function call: positional args must precede keywords and ** unpacking; "
1804 "* unpacking must precede ** unpacking");
1808 template <
typename Derived>
1812 if (!PyGILState_Check()) {
1813 pybind11_fail(
"pybind11::object_api<>::operator() PyGILState_Check() failure.");
1816 return detail::collect_arguments<policy>(std::forward<Args>(
args)...).call(derived().ptr());
1819 template <
typename Derived>
1821 object object_api<Derived>::call(Args &&...
args)
const {
1822 return operator()<policy>(std::forward<Args>(
args)...);
1827 template <
typename T>
1829 static_assert(std::is_base_of<detail::type_caster_generic, detail::make_caster<T>>::
value,
1830 "py::type::of<T> only supports the case where T is a registered C++ types.");
1835 #define PYBIND11_MAKE_OPAQUE(...) \
1836 PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) \
1837 namespace detail { \
1839 class type_caster<__VA_ARGS__> : public type_caster_base<__VA_ARGS__> {}; \
1841 PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
1846 #define PYBIND11_TYPE(...) __VA_ARGS__
static handle cast(T *src, return_value_policy policy, handle parent)
type_caster< T, SFINAE > & load_type(type_caster< T, SFINAE > &conv, const handle &handle)
#define PYBIND11_BYTES_SIZE
std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... > > all_of
PyObject * conv(PyObject *o)
static std::enable_if<!std::is_floating_point< U >::value &&std::is_unsigned< U >::value &&(sizeof(U)<=sizeof(unsigned long)), handle >::type cast(U src, return_value_policy, handle)
void process(list &args_list, T &&x)
Annotation for function names.
T cast(const handle &handle)
static constexpr size_t UTF_N
Annotation indicating that a class derives from another given type.
static handle cast(const void *ptr, return_value_policy, handle)
bool load_args(function_call &call)
constexpr arg(const char *name=nullptr)
static handle cast(bool src, return_value_policy, handle)
constexpr descr< N - 1 > const_name(char const (&text)[N])
static handle cast(CharT src, return_value_policy policy, handle parent)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
bool load(handle src, bool)
std::vector< std::pair< const std::type_info *, void *(*)(void *)> > implicit_casts
static handle cast(const holder_type &src, return_value_policy, handle)
typename std::remove_cv< T >::type remove_cv_t
enable_if_t<!std::is_void< Return >::value, Return > call(Func &&f) &&
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
const handle & inc_ref() const &
const function_record & func
The function data:
static return_value_policy policy(return_value_policy p)
std::is_same< intrinsic_t< Arg >, args > argument_is_args
std::basic_string< CharT > StringType
#define PYBIND11_NAMESPACE_END(name)
static void multiple_values_error(const std::string &name)
bool hasattr(handle obj, handle name)
static handle cast(holder_type &&src, return_value_policy, handle)
arg_v(arg &&base, T &&x, const char *descr=nullptr)
conditional_t< std::is_signed< T >::value, _py_type_0, typename std::make_unsigned< _py_type_0 >::type > _py_type_1
Eigen::Triplet< double > T
object operator()(Args &&...args) const
bool load_impl_sequence(function_call &call, index_sequence< Is... >)
static constexpr auto arg_names
static handle cast(const CharT *src, return_value_policy policy, handle parent)
enable_if_t< cast_is_temporary_value_reference< T >::value, T > cast_ref(object &&o, make_caster< T > &caster)
function_call(const function_record &f, handle p)
static std::enable_if<!std::is_floating_point< U >::value &&std::is_signed< U >::value &&(sizeof(U)<=sizeof(long)), handle >::type cast(U src, return_value_policy, handle)
#define PYBIND11_NAMESPACE_BEGIN(name)
simple_collector< policy > collect_arguments(Args &&...args)
Collect only positional arguments for a Python function call.
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
arg_v operator=(T &&value) const
Assign a value to this argument.
const std::vector< detail::type_info * > & all_type_info(PyTypeObject *type)
static handle cast_impl(T &&src, return_value_policy policy, handle parent, index_sequence< Is... >)
std::reference_wrapper< type > cast_op_type
static handle cast(const StringType &src, return_value_policy, handle)
enable_if_t< std::is_void< Return >::value, void_type > call(Func &&f) &&
static bool try_direct_conversions(handle)
bool load(handle src, bool convert)
#define PYBIND11_LONG_AS_LONGLONG(o)
type implicit_cast(index_sequence< Is... >) &&
handle parent
The parent, if any.
typename std::conditional< B, T, F >::type conditional_t
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
Internal data associated with a single function call.
bool load(handle src, bool convert)
simple_collector(Ts &&...values)
std::is_same< intrinsic_t< T >, pos_only > is_pos_only
void process(list &, detail::kwargs_proxy kp)
std::string type
The C++ type name of the default value (only available when compiled in debug mode)
static constexpr bool value
static handle cast(const itype &src, return_value_policy policy, handle parent)
void check_holder_compat()
object call(PyObject *ptr) const
Call a Python function and pass the collected arguments.
std::is_same< intrinsic_t< T >, kw_only > is_kw_only
const char * name
If non-null, this is a named kwargs argument.
Reference counted object base class.
const tuple & args() const &
PYBIND11_TYPE_CASTER(type, handle_type_name< type >::name)
#define PYBIND11_LONG_CHECK(o)
arg_v(const char *name, T &&x, const char *descr=nullptr)
Direct construction with name, default, and description.
PYBIND11_TYPE_CASTER(StringType, const_name(PYBIND11_STRING_NAME))
PYBIND11_TYPE_CASTER(T, const_name("None"))
bool load(handle src, bool convert)
typename intrinsic_type< T >::type intrinsic_t
conditional_t< cast_is_temporary_value_reference< ret_type >::value, make_caster< ret_type >, override_unused > override_caster_t
conditional_t< std::is_floating_point< T >::value, double, _py_type_1 > py_type
object value
The default value.
static handle handle_of()
handle init_self
If this is a call to an initializer, this argument contains self
static return_value_policy policy(return_value_policy p)
bool_constant<(std::is_reference< type >::value||std::is_pointer< type >::value) &&!std::is_base_of< type_caster_generic, make_caster< type > >::value &&!std::is_same< intrinsic_t< type >, void >::value > cast_is_temporary_value_reference
static handle cast(T, return_value_policy, handle)
bool load(handle src, bool convert)
static std::enable_if<!std::is_floating_point< U >::value &&std::is_unsigned< U >::value &&(sizeof(U) > sizeof(unsigned long)), handle >::type cast(U src, return_value_policy, handle)
#define PYBIND11_DETAILED_ERROR_MESSAGES
Tuple< make_caster< Ts >... > subcasters
typename caster_t::template cast_op_type< reference_t > subcaster_cast_op_type
bool load(handle src, bool)
void process(list &args_list, detail::args_proxy ap)
bool flag_none
If set (the default), allow None to be passed to this argument.
unpacking_collector(Ts &&...values)
const dict & kwargs() const &
bool load(handle src, bool convert)
Return call_impl(Func &&f, index_sequence< Is... >, Guard &&) &&
cast_error cast_error_unable_to_convert_call_arg(const std::string &name, const std::string &type)
constexpr descr< 0 > concat()
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE ArgReturnType arg() const
PyExc_RuntimeError PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
make_index_sequence< sizeof...(Args)> indices
static constexpr int args_pos
bool load(handle h, bool)
static void nameless_argument_error(const std::string &type)
arg_v & noconvert(bool flag=true)
Same as arg::noconvert(), but returns *this as arg_v&, not arg&.
conditional_t< std::is_pointer< remove_reference_t< T > >::value, typename std::add_pointer< intrinsic_t< T > >::type, typename std::add_lvalue_reference< intrinsic_t< T > >::type > cast_op_type
constexpr descr< N+2, Ts... > type_descr(const descr< N, Ts... > &descr)
static constexpr auto kwargs_pos
#define PYBIND11_BYTES_NAME
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
#define PYBIND11_BOOL_ATTR
make_index_sequence< size > indices
#define PYBIND11_TYPE_CASTER(type, py_name)
std::integral_constant< bool, B > bool_constant
Backports of std::bool_constant and std::negation to accommodate older compilers.
static void multiple_values_error()
bool load_value(value_and_holder &&v_h)
static handle cast(const std::reference_wrapper< type > &src, return_value_policy policy, handle parent)
arg & none(bool flag=true)
Indicates that the argument should/shouldn't allow None (e.g. for nullable pointer args)
Helper class which collects positional, keyword, * and ** arguments for a Python function call.
const char * descr
The (optional) description of the default value.
#define PYBIND11_BYTES_AS_STRING
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
#define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
bool load_raw(enable_if_t< std::is_same< C, char >::value, handle > src)
typename make_index_sequence_impl< N >::type make_index_sequence
bool contains(T &&key) const
PyObject * ptr() const
Return the underlying PyObject * pointer.
constexpr int constexpr_last()
Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.
PYBIND11_WARNING_PUSH PYBIND11_WARNING_DISABLE_MSVC(5054) PYBIND11_WARNING_POP static_assert(EIGEN_VERSION_AT_LEAST(3
std::is_same< intrinsic_t< Arg >, kwargs > argument_is_kwargs
enable_if_t< cast_is_temporary_value_reference< T >::value &&!detail::is_same_ignoring_cvref< T, PyObject * >::value, T > cast_safe(object &&)
static constexpr bool load_impl(const sequence &, bool, index_sequence<>)
conditional_t< is_copy_constructible< holder_type >::value, copyable_holder_caster< type, holder_type >, move_only_holder_caster< type, holder_type > > type_caster_holder
static bool load_impl_sequence(function_call &, index_sequence<>)
Helper class which loads arguments for C++ functions called from Python.
bool try_implicit_casts(handle, bool)
pybind11::detail::cast_op_type< _T > cast_op_type
PYBIND11_NOINLINE handle get_type_handle(const std::type_info &tp, bool throw_if_missing)
static constexpr auto size
Helper type to replace 'void' in some expressions.
object call(PyObject *ptr) const
Call a Python function and pass the collected arguments.
static void nameless_argument_error()
const char * c_str(Args &&...args)
std::tuple< make_caster< Args >... > argcasters
static auto get(const T &p) -> decltype(p.get())
std::is_base_of< pyobject_tag, remove_reference_t< T > > is_pyobject
bool load_impl(const sequence &seq, bool convert, index_sequence< Is... >)
#define PYBIND11_NB_BOOL(ptr)
make_caster< T >::template cast_op_type< T > cast_op(make_caster< T > &caster)
static handle decode_utfN(const char *buffer, ssize_t nbytes)
void process(list &, arg_v a)
bool load(handle src, bool convert)
static std::enable_if< std::is_floating_point< U >::value, handle >::type cast(U src, return_value_policy, handle)
const type_info * typeinfo
#define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
bool load(handle src, bool convert)
std::vector< handle > args
Arguments passed to the function:
object object_or_cast(T &&o)
static handle cast_holder(const itype *src, const void *holder)
static handle cast(const handle &src, return_value_policy, handle)
conditional_t< sizeof(T)<=sizeof(long), long, long long > _py_type_0
static std::enable_if<!std::is_floating_point< U >::value &&std::is_signed< U >::value &&(sizeof(U) > sizeof(long)), handle >::type cast(U src, return_value_policy, handle)
arg & noconvert(bool flag=true)
Indicate that the type should not be converted in the type caster.
#define PYBIND11_LONG_FROM_SIGNED(o)
bool try_implicit_casts(handle src, bool convert)
const tuple & args() const &
type implicit_cast(index_sequence< Is... >) &
T reinterpret_steal(handle h)
static BinaryMeasurement< Rot3 > convert(const BetweenFactor< Pose3 >::shared_ptr &f)
#define PYBIND11_STRING_NAME
static constexpr bool has_kwargs
internal::enable_if<!(symbolic::is_symbolic< FirstType >::value||symbolic::is_symbolic< LastType >::value), ArithmeticSequence< typename internal::cleanup_index_type< FirstType >::type, Index > >::type seq(FirstType f, LastType l)
#define PYBIND11_BYTES_CHECK
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
#define PYBIND11_LONG_FROM_UNSIGNED(o)
arg_v(const arg &base, T &&x, const char *descr=nullptr)
Called internally when invoking py::arg("a") = value
static PYBIND11_NOINLINE void add_patient(handle h)
std::vector< bool > args_convert
The convert value the arguments should be loaded with.
typename std::basic_string< CharT, Traits, Allocator > ::value_type CharT
constexpr bool args_are_all_positional()
static handle cast(T &&src, return_value_policy policy, handle parent)
arg_v & none(bool flag=true)
Same as arg::nonone(), but returns *this as arg_v&, not arg&.
bool load(handle src, bool)
bool load_raw(enable_if_t<!std::is_same< C, char >::value, handle >)
Generic type caster for objects stored on the heap.
static bool is_numpy_bool(handle object)
gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:00:48