27 #include <type_traits> 34 template <
typename type,
typename SFINAE =
void>
36 template <
typename type>
51 template <
typename type>
62 "std::reference_wrapper<T> caster requires T to have a caster with an " 63 "`operator T &()` or `operator const T &()`");
79 explicit operator std::reference_wrapper<type>() {
return cast_op<type &>(subcaster); }
82 #define PYBIND11_TYPE_CASTER(type, py_name) \ 87 static constexpr auto name = py_name; \ 88 template <typename T_, \ 89 ::pybind11::detail::enable_if_t< \ 90 std::is_same<type, ::pybind11::detail::remove_cv_t<T_>>::value, \ 92 static ::pybind11::handle cast( \ 93 T_ *src, ::pybind11::return_value_policy policy, ::pybind11::handle parent) { \ 95 return ::pybind11::none().release(); \ 96 if (policy == ::pybind11::return_value_policy::take_ownership) { \ 97 auto h = cast(std::move(*src), policy, parent); \ 101 return cast(*src, policy, parent); \ 103 operator type *() { return &value; } \ 104 operator type &() { return value; } \ 105 operator type &&() && { return std::move(value); } \ 106 template <typename T_> \ 107 using cast_op_type = ::pybind11::detail::movable_cast_op_type<T_> 109 template <
typename CharT>
111 #if defined(PYBIND11_HAS_U8STRING) 112 std::is_same<CharT, char8_t>,
114 std::is_same<CharT, char16_t>,
115 std::is_same<CharT, char32_t>,
116 std::is_same<CharT, wchar_t>
119 template <
typename T>
135 #if !defined(PYPY_VERSION) 136 auto index_check = [](PyObject *o) {
return PyIndex_Check(o); };
140 auto index_check = [](PyObject *o) {
return hasattr(o,
"__index__"); };
144 if (convert || PyFloat_Check(src.
ptr())) {
145 py_value = (
py_type) PyFloat_AsDouble(src.
ptr());
149 }
else if (PyFloat_Check(src.
ptr())
153 handle src_or_index = src;
155 #if PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION) 158 index = reinterpret_steal<object>(PyNumber_Index(src.
ptr()));
164 src_or_index = index;
169 py_value = as_unsigned<py_type>(src_or_index.
ptr());
171 py_value =
sizeof(
T) <=
sizeof(
long)
178 bool py_err = py_value == (
py_type) -1 && PyErr_Occurred();
184 && py_value != (
py_type) (
T) py_value)) {
186 if (py_err && convert && (PyNumber_Check(src.
ptr()) != 0)) {
188 ? PyNumber_Float(src.
ptr())
189 : PyNumber_Long(src.
ptr()));
191 return load(tmp,
false);
200 template <
typename U = T>
203 return PyFloat_FromDouble((
double) src);
206 template <
typename U = T>
208 && (
sizeof(
U) <=
sizeof(
long)),
214 template <
typename U = T>
216 && (
sizeof(
U) <=
sizeof(
unsigned long)),
222 template <
typename U = T>
224 && (
sizeof(
U) >
sizeof(
long)),
227 return PyLong_FromLongLong((
long long) src);
230 template <
typename U = T>
232 && (
sizeof(
U) >
sizeof(
unsigned long)),
235 return PyLong_FromUnsignedLongLong((
unsigned long long) src);
241 template <
typename T>
245 if (src && src.is_none()) {
274 if (isinstance<capsule>(h)) {
275 value = reinterpret_borrow<capsule>(
h);
281 if (bases.size() == 1) {
297 template <
typename T>
299 explicit operator void *&() {
return value; }
316 if (src.
ptr() == Py_True) {
320 if (src.
ptr() == Py_False) {
324 if (convert || (std::strcmp(
"numpy.bool_", Py_TYPE(src.
ptr())->tp_name) == 0)) {
331 #if defined(PYPY_VERSION) 334 res = PyObject_IsTrue(src.
ptr());
339 else if (
auto *tp_as_number = src.
ptr()->ob_type->tp_as_number) {
345 if (res == 0 || res == 1) {
360 template <
typename StringType,
bool IsView = false>
362 using CharT =
typename StringType::value_type;
367 "Unsupported char size != 1");
368 #if defined(PYBIND11_HAS_U8STRING) 370 "Unsupported char8_t size != 1");
373 "Unsupported char16_t size != 2");
375 "Unsupported char32_t size != 4");
378 "Unsupported wchar_t size != 2/4");
379 static constexpr
size_t UTF_N = 8 *
sizeof(
CharT);
386 if (!PyUnicode_Check(load_src.
ptr())) {
387 return load_raw(load_src);
393 Py_ssize_t
size = -1;
395 =
reinterpret_cast<const CharT *
>(PyUnicode_AsUTF8AndSize(load_src.
ptr(), &
size));
400 value = StringType(
buffer, static_cast<size_t>(size));
405 = reinterpret_steal<object>(PyUnicode_AsEncodedString(load_src.
ptr(),
407 : UTF_N == 16 ?
"utf-16" 435 const char *
buffer =
reinterpret_cast<const char *
>(src.data());
437 handle s = decode_utfN(buffer, nbytes);
448 #if !defined(PYPY_VERSION) 449 return UTF_N == 8 ? PyUnicode_DecodeUTF8(buffer, nbytes,
nullptr)
450 : UTF_N == 16 ? PyUnicode_DecodeUTF16(buffer, nbytes,
nullptr,
nullptr)
451 : PyUnicode_DecodeUTF32(buffer, nbytes,
nullptr,
nullptr);
456 return PyUnicode_Decode(buffer,
459 : UTF_N == 16 ?
"utf-16" 468 template <
typename C = CharT>
475 pybind11_fail(
"Unexpected PYBIND11_BYTES_AS_STRING() failure.");
480 if (PyByteArray_Check(src.ptr())) {
483 const char *
bytearray = PyByteArray_AsString(src.ptr());
487 value = StringType(bytearray, (
size_t) PyByteArray_Size(src.ptr()));
494 template <
typename C = CharT>
500 template <
typename CharT,
class Traits,
class Allocator>
503 :
string_caster<std::basic_string<CharT, Traits, Allocator>> {};
505 #ifdef PYBIND11_HAS_STRING_VIEW 506 template <
typename CharT,
class Traits>
507 struct type_caster<std::basic_string_view<CharT, Traits>,
509 :
string_caster<std::basic_string_view<CharT, Traits>, true> {};
514 template <
typename CharT>
535 return str_caster.
load(src, convert);
539 if (src ==
nullptr) {
540 return pybind11::none().
inc_ref();
547 handle s = PyUnicode_DecodeLatin1((
const char *) &src, 1,
nullptr);
556 explicit operator CharT *() {
557 return none ? nullptr :
const_cast<CharT *
>(
static_cast<StringType &
>(str_caster).
c_str());
559 explicit operator CharT &() {
561 throw value_error(
"Cannot convert None to a character");
565 size_t str_len =
value.size();
567 throw value_error(
"Cannot convert empty string to a character");
576 auto v0 =
static_cast<unsigned char>(
value[0]);
581 size_t char0_bytes = (
v0 & 0x80) == 0 ? 1
582 : (
v0 & 0xE0) == 0xC0 ? 2
583 : (
v0 & 0xF0) == 0xE0 ? 3
586 if (char0_bytes == str_len) {
588 if (char0_bytes == 2 && (
v0 & 0xFC) == 0xC0) {
589 one_char =
static_cast<CharT
>(((
v0 & 3) << 6)
590 + (
static_cast<unsigned char>(
value[1]) & 0x3F));
594 throw value_error(
"Character code point not in range(0x100)");
602 one_char =
static_cast<CharT
>(
value[0]);
603 if (one_char >= 0xD800 && one_char < 0xE000) {
604 throw value_error(
"Character code point not in range(0x10000)");
609 throw value_error(
"Expected a character, but multi-character string found");
617 template <
typename _T>
622 template <
template <
typename...>
class Tuple,
typename... Ts>
625 static constexpr
auto size =
sizeof...(Ts);
630 if (!isinstance<sequence>(src)) {
633 const auto seq = reinterpret_borrow<sequence>(src);
640 template <
typename T>
642 return cast_impl(std::forward<T>(src), policy, parent,
indices{});
646 template <
typename T>
652 auto h =
cast(std::move(*src), policy, parent);
656 return cast(*src, policy, parent);
659 static constexpr
auto name 662 template <
typename T>
666 explicit operator type() && {
return std::move(*this).implicit_cast(
indices{}); }
669 template <
size_t... Is>
671 return type(cast_op<Ts>(std::get<Is>(subcasters))...);
673 template <
size_t... Is>
675 return type(cast_op<Ts>(std::move(std::get<Is>(subcasters)))...);
680 template <
size_t... Is>
682 #ifdef __cpp_fold_expressions 683 if ((... || !std::get<Is>(subcasters).
load(seq[Is], convert))) {
687 for (
bool r : {std::get<Is>(subcasters).
load(seq[Is], convert)...}) {
697 template <
typename T,
size_t... Is>
702 std::array<object, size> entries{{reinterpret_steal<object>(
704 for (
const auto &entry : entries) {
711 for (
auto &entry : entries) {
712 PyTuple_SET_ITEM(result.
ptr(), counter++, entry.release().ptr());
720 template <
typename T1,
typename T2>
723 template <
typename... Ts>
728 template <
typename T>
730 static auto get(
const T &
p) -> decltype(
p.get()) {
return p.get(); }
738 template <
typename type,
typename holder_type,
typename SFINAE =
void>
743 "Holder classes are only supported for custom types");
746 using base::typeinfo;
750 return base::template load_impl<copyable_holder_caster<type, holder_type>>(src,
convert);
757 explicit operator holder_type *() {
return std::addressof(holder); }
758 explicit operator holder_type &() {
return holder; }
769 throw cast_error(
"Unable to load a custom holder type from a default-holder instance");
774 if (v_h.holder_constructed()) {
775 value = v_h.value_ptr();
776 holder = v_h.template holder<holder_type>();
779 throw cast_error(
"Unable to cast from non-held to held instance (T& to Holder<T>) " 781 "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for " 782 "type information)");
785 + type_id<holder_type>() +
"''");
789 template <
typename T = holder_type,
795 template <
typename T = holder_type,
800 if (sub_caster.
load(src, convert)) {
815 template <
typename T>
821 template <
typename type,
typename holder_type,
typename SFINAE =
void>
824 "Holder classes are only supported for custom types");
833 template <
typename type,
typename deleter>
837 template <
typename type,
typename holder_type>
842 template <
typename T,
bool Value = false>
844 static constexpr
bool value = Value;
848 #define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type, ...) \ 849 PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) \ 851 template <typename type> \ 852 struct always_construct_holder<holder_type> : always_construct_holder<void, ##__VA_ARGS__> { \ 854 template <typename type> \ 855 class type_caster<holder_type, enable_if_t<!is_shared_ptr<holder_type>::value>> \ 856 : public type_caster_holder<type, holder_type> {}; \ 858 PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 861 template <
typename base,
typename holder>
863 : std::is_base_of<detail::type_caster_holder<base, holder>, detail::type_caster<holder>> {};
865 template <
typename base,
typename deleter>
868 template <
typename T>
870 static constexpr
auto name = const_name<T>();
909 template <
typename type>
922 return static_cast<bool>(
value);
927 if (!isinstance<type>(src)) {
930 value = reinterpret_borrow<type>(src);
940 template <
typename T>
952 template <
typename T>
955 template <
typename T,
typename SFINAE =
void>
957 template <
typename T>
963 std::is_move_constructible<T>,
964 std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>
::value>>
966 template <
typename T,
typename SFINAE =
void>
968 template <
typename T>
974 std::is_move_constructible<T>,
975 std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>
::value>>
977 template <
typename T>
984 template <
typename type>
993 template <
typename Return,
typename SFINAE =
void>
998 template <
typename Return>
1001 detail::
enable_if_t<std::is_base_of<type_caster_generic, make_caster<Return>>::value, void>> {
1010 template <
typename T,
typename SFINAE>
1013 "Internal error: type_caster should only be used for C++ types");
1014 if (!conv.
load(handle,
true)) {
1015 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1016 throw cast_error(
"Unable to cast Python instance to C++ type (#define " 1017 "PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1019 throw cast_error(
"Unable to cast Python instance of type " 1021 + type_id<T>() +
"'");
1027 template <
typename T>
1041 "Unable to cast type to reference: value is local to type caster");
1042 return cast_op<T>(load_type<T>(handle));
1048 return T(reinterpret_borrow<object>(handle));
1055 handle parent = handle()) {
1066 return reinterpret_steal<object>(
1070 template <
typename T>
1072 return pybind11::cast<T>(*this);
1079 template <
typename T>
1081 if (obj.ref_count() > 1) {
1082 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1084 "Unable to cast Python instance to C++ rvalue: instance has multiple references" 1085 " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1087 throw cast_error(
"Unable to move from Python " + (std::string)
str(
type::handle_of(obj))
1088 +
" instance to C++ " + type_id<T>()
1089 +
" instance: instance has multiple references");
1094 T
ret = std::move(detail::load_type<T>(obj).
operator T &());
1103 template <
typename T>
1106 return move<T>(std::move(
object));
1108 template <
typename T>
1111 if (
object.ref_count() > 1) {
1112 return cast<T>(object);
1114 return move<T>(std::move(
object));
1116 template <
typename T>
1119 return cast<T>(object);
1123 template <
typename T>
1125 return T(std::move(
object));
1128 template <
typename T>
1130 return pybind11::cast<T>(*this);
1132 template <
typename T>
1134 return pybind11::cast<T>(std::move(*
this));
1156 template <
typename ret_type>
1163 template <
typename T>
1166 return cast_op<T>(
load_type(caster, o));
1168 template <
typename T>
1177 template <
typename T>
1179 pybind11_fail(
"Internal error: cast_safe fallback invoked");
1181 template <
typename T>
1183 template <
typename T>
1185 std::is_same<void, intrinsic_t<T>>>
::value,
1188 return pybind11::cast<T>(std::move(o));
1195 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1197 return cast_error(
"Unable to convert call argument to Python object (#define " 1198 "PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1202 const std::string &
type) {
1203 return cast_error(
"Unable to convert call argument '" + name +
"' of type '" + type
1204 +
"' to Python object");
1208 template <return_value_policy policy = return_value_policy::automatic_reference>
1215 constexpr
size_t size =
sizeof...(Args);
1216 std::array<object, size>
args{{reinterpret_steal<object>(
1220 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1223 std::array<std::string, size> argtypes{{type_id<Args>()...}};
1230 for (
auto &arg_value :
args) {
1231 PyTuple_SET_ITEM(result.
ptr(), counter++, arg_value.release().ptr());
1241 constexpr
explicit arg(
const char *
name =
nullptr)
1242 :
name(
name), flag_noconvert(false), flag_none(true) {}
1244 template <
typename T>
1248 flag_noconvert = flag;
1267 template <
typename T>
1272 #if defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1280 if (PyErr_Occurred()) {
1287 template <
typename T>
1292 template <
typename T>
1312 #if defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1328 template <
typename T>
1330 return {*
this, std::forward<T>(
value)};
1334 template <
typename >
1341 constexpr
arg operator"" _a(
const char *
name,
size_t) {
return arg(name); }
1346 template <
typename T>
1348 template <
typename T>
1379 template <
typename... Args>
1383 template <
typename Arg>
1385 template <
typename Arg>
1390 static_assert(kwargs_pos == -1 || kwargs_pos == (
int)
sizeof...(Args) - 1,
1391 "py::kwargs is only permitted as the last argument of a function");
1394 static constexpr
bool has_kwargs = kwargs_pos != -1;
1399 static_assert(args_pos == -1 || args_pos == constexpr_first<argument_is_args, Args...>(),
1400 "py::args cannot be specified more than once");
1406 template <
typename Return,
typename Guard,
typename Func>
1410 std::forward<Func>(
f),
indices{}, Guard{});
1413 template <
typename Return,
typename Guard,
typename Func>
1416 std::forward<Func>(
f),
indices{}, Guard{});
1423 template <
size_t... Is>
1425 #ifdef __cpp_fold_expressions 1439 template <
typename Return,
typename Func,
size_t... Is,
typename Guard>
1441 return std::forward<Func>(
f)(cast_op<Args>(std::move(std::get<Is>(argcasters)))...);
1449 template <return_value_policy policy>
1452 template <
typename... Ts>
1463 PyObject *
result = PyObject_CallObject(ptr, m_args.ptr());
1467 return reinterpret_steal<object>(
result);
1475 template <return_value_policy policy>
1478 template <
typename... Ts>
1482 auto args_list = list();
1483 using expander =
int[];
1484 (void) expander{0, (process(args_list, std::forward<Ts>(
values)), 0)...};
1486 m_args = std::move(args_list);
1497 PyObject *
result = PyObject_Call(ptr, m_args.ptr(), m_kwargs.ptr());
1501 return reinterpret_steal<object>(
result);
1505 template <
typename T>
1507 auto o = reinterpret_steal<object>(
1510 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1517 args_list.append(std::move(o));
1520 void process(list &args_list, detail::args_proxy ap) {
1522 args_list.append(
a);
1528 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1529 nameless_argument_error();
1531 nameless_argument_error(a.
type);
1534 if (m_kwargs.contains(a.
name)) {
1535 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1536 multiple_values_error();
1538 multiple_values_error(a.
name);
1542 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1555 for (
auto k : reinterpret_borrow<dict>(kp)) {
1556 if (m_kwargs.contains(k.first)) {
1557 #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) 1558 multiple_values_error();
1560 multiple_values_error(
str(k.first));
1563 m_kwargs[k.first] = k.second;
1569 "Got kwargs without a name; only named arguments " 1570 "may be passed via py::arg() to a python function call. " 1571 "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1574 throw type_error(
"Got kwargs without a name of type '" + type
1576 "arguments may be passed via py::arg() to a python function call. ");
1580 "Got multiple values for keyword argument " 1581 "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1585 throw type_error(
"Got multiple values for keyword argument '" + name +
"'");
1597 template <
typename... Args>
1616 static_assert(constexpr_last<is_positional, Args...>()
1617 < constexpr_first<is_keyword_or_ds, Args...>()
1618 && constexpr_last<is_s_unpacking, Args...>()
1619 < constexpr_first<is_ds_unpacking, Args...>(),
1620 "Invalid function call: positional args must precede keywords and ** unpacking; " 1621 "* unpacking must precede ** unpacking");
1625 template <
typename Derived>
1629 if (!PyGILState_Check()) {
1630 pybind11_fail(
"pybind11::object_api<>::operator() PyGILState_Check() failure.");
1633 return detail::collect_arguments<policy>(std::forward<Args>(
args)...).call(derived().ptr());
1636 template <
typename Derived>
1638 object object_api<Derived>::call(Args &&...args)
const {
1639 return operator()<policy>(std::forward<Args>(
args)...);
1644 template <
typename T>
1646 static_assert(std::is_base_of<detail::type_caster_generic, detail::make_caster<T>>::
value,
1647 "py::type::of<T> only supports the case where T is a registered C++ types.");
1652 #define PYBIND11_MAKE_OPAQUE(...) \ 1653 PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) \ 1654 namespace detail { \ 1656 class type_caster<__VA_ARGS__> : public type_caster_base<__VA_ARGS__> {}; \ 1658 PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 1663 #define PYBIND11_TYPE(...) __VA_ARGS__ typename std::conditional< B, T, F >::type conditional_t
object call(PyObject *ptr) const
Call a Python function and pass the collected arguments.
static handle cast(T &&src, return_value_policy policy, handle parent)
std::reference_wrapper< type > cast_op_type
#define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
object object_or_cast(T &&o)
static void multiple_values_error(const std::string &name)
bool load_args(function_call &call)
static constexpr bool load_impl(const sequence &, bool, index_sequence<>)
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
static handle handle_of()
bool hasattr(handle obj, handle name)
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)
object operator()(Args &&...args) const
static auto get(const T &p) -> decltype(p.get())
void process(list &, arg_v a)
bool load_impl(const sequence &seq, bool convert, index_sequence< Is... >)
bool load_impl_sequence(function_call &call, index_sequence< Is... >)
bool try_implicit_casts(handle src, bool convert)
arg & none(bool flag=true)
Indicates that the argument should/shouldn't allow None (e.g. for nullable pointer args) ...
std::vector< handle > args
Arguments passed to the function:
typename std::remove_cv< T >::type remove_cv_t
#define PYBIND11_DETAILED_ERROR_MESSAGES
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)
PyObject * conv(PyObject *o)
bool load(handle src, bool convert)
enable_if_t<!std::is_void< Return >::value, Return > call(Func &&f) &&
static handle cast_holder(const itype *src, const void *holder)
#define PYBIND11_LONG_CHECK(o)
#define PYBIND11_NB_BOOL(ptr)
const type_info * typeinfo
#define PYBIND11_SILENCE_MSVC_C4127(...)
static handle cast(bool src, return_value_policy, handle)
bool load(handle src, bool convert)
static handle cast(CharT src, return_value_policy policy, handle parent)
static std::enable_if< std::is_floating_point< U >::value, handle >::type cast(U src, return_value_policy, handle)
object value
The default value.
static handle cast(T, return_value_policy, handle)
conditional_t< is_copy_constructible< holder_type >::value, copyable_holder_caster< type, holder_type >, move_only_holder_caster< type, holder_type > > type_caster_holder
enable_if_t< std::is_void< Return >::value, void_type > call(Func &&f) &&
Helper class which loads arguments for C++ functions called from Python.
std::vector< std::pair< const std::type_info *, void *(*)(void *)> > implicit_casts
bool load(handle h, bool)
Internal data associated with a single function call.
PYBIND11_NOINLINE handle get_type_handle(const std::type_info &tp, bool throw_if_missing)
#define PYBIND11_NAMESPACE
std::is_same< intrinsic_t< Arg >, args > argument_is_args
std::tuple< make_caster< Args >... > argcasters
static handle cast(T *src, return_value_policy policy, handle parent)
simple_collector< policy > collect_arguments(Args &&...args)
Collect only positional arguments for a Python function call.
enable_if_t< cast_is_temporary_value_reference< T >::value, T > cast_safe(object &&)
object call(PyObject *ptr) const
Call a Python function and pass the collected arguments.
#define PYBIND11_STRING_NAME
#define PYBIND11_LONG_FROM_UNSIGNED(o)
arg & noconvert(bool flag=true)
Indicate that the type should not be converted in the type caster.
const char * c_str(Args &&...args)
#define PYBIND11_BOOL_ATTR
bool load(handle src, bool)
PyExc_RuntimeError [[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
type_caster< T, SFINAE > & load_type(type_caster< T, SFINAE > &conv, const handle &handle)
conditional_t< std::is_signed< T >::value, _py_type_0, typename std::make_unsigned< _py_type_0 >::type > _py_type_1
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
const handle & inc_ref() const &
static handle cast(const std::reference_wrapper< type > &src, return_value_policy policy, handle parent)
cast_error cast_error_unable_to_convert_call_arg(const std::string &name, const std::string &type)
void check_holder_compat()
conditional_t< sizeof(T)<=sizeof(long), long, long long > _py_type_0
static handle cast(const itype &src, return_value_policy policy, handle parent)
bool load_value(value_and_holder &&v_h)
#define PYBIND11_BYTES_CHECK
bool load(handle src, bool convert)
type implicit_cast(index_sequence< Is... >) &&
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)
const tuple & args() const &
const function_record & func
The function data:
std::vector< bool > args_convert
The convert value the arguments should be loaded with.
type implicit_cast(index_sequence< Is... >) &
const dict & kwargs() const &
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
simple_collector(Ts &&...values)
bool load(handle src, bool convert)
std::integral_constant< bool, B > bool_constant
Backports of std::bool_constant and std::negation to accommodate older compilers. ...
Eigen::Triplet< double > T
constexpr arg(const char *name=nullptr)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
static return_value_policy policy(return_value_policy p)
static handle cast(const holder_type &src, return_value_policy, handle)
static bool try_direct_conversions(handle)
#define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
constexpr descr< 0 > concat()
constexpr bool args_are_all_positional()
static void nameless_argument_error(const std::string &type)
unpacking_collector(Ts &&...values)
Helper type to replace 'void' in some expressions.
typename caster_t::template cast_op_type< reference_t > subcaster_cast_op_type
arg_v(arg &&base, T &&x, const char *descr=nullptr)
conditional_t< std::is_floating_point< T >::value, double, _py_type_1 > py_type
#define PYBIND11_BYTES_NAME
constexpr descr< N+2, Ts... > type_descr(const descr< N, Ts... > &descr)
void process(list &args_list, T &&x)
enable_if_t< cast_is_temporary_value_reference< T >::value, T > cast_ref(object &&o, make_caster< T > &caster)
bool load(handle src, bool convert)
bool load(handle src, bool)
arg_v & none(bool flag=true)
Same as arg::nonone(), but returns *this as arg_v&, not arg&.
constexpr int constexpr_last()
Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match...
std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... > > all_of
bool load(handle src, bool convert)
arg_v & noconvert(bool flag=true)
Same as arg::noconvert(), but returns *this as arg_v&, not arg&.
static void multiple_values_error()
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)
Helper class which collects positional, keyword, * and ** arguments for a Python function call...
bool load_raw(enable_if_t<!std::is_same< C, char >::value, handle >)
#define PYBIND11_LONG_AS_LONGLONG(o)
bool try_implicit_casts(handle, bool)
static bool load_impl_sequence(function_call &, index_sequence<>)
Return call_impl(Func &&f, index_sequence< Is... >, Guard &&) &&
typename intrinsic_type< T >::type intrinsic_t
std::basic_string< CharT > StringType
static return_value_policy policy(return_value_policy p)
const std::vector< detail::type_info * > & all_type_info(PyTypeObject *type)
arg_v operator=(T &&value) const
Assign a value to this argument.
static void nameless_argument_error()
std::is_same< intrinsic_t< T >, kw_only > is_kw_only
#define PYBIND11_LONG_FROM_SIGNED(o)
std::is_same< intrinsic_t< Arg >, kwargs > argument_is_kwargs
conditional_t< cast_is_temporary_value_reference< ret_type >::value, make_caster< ret_type >, override_unused > override_caster_t
handle parent
The parent, if any.
Generic type caster for objects stored on the heap.
bool load_raw(enable_if_t< std::is_same< C, char >::value, handle > src)
static handle cast(const StringType &src, return_value_policy, handle)
static handle cast_impl(T &&src, return_value_policy policy, handle parent, index_sequence< Is... >)
static handle cast(const handle &src, return_value_policy, handle)
T cast(const handle &handle)
static handle cast(const CharT *src, return_value_policy policy, handle parent)
arg_v(const arg &base, T &&x, const char *descr=nullptr)
Called internally when invoking py::arg("a") = value
static handle decode_utfN(const char *buffer, ssize_t nbytes)
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
arg_v(const char *name, T &&x, const char *descr=nullptr)
Direct construction with name, default, and description.
typename std::basic_string< CharT, Traits, Allocator > ::value_type CharT
const char * descr
The (optional) description of the default value.
T reinterpret_steal(handle h)
Annotation for function names.
void process(list &, detail::kwargs_proxy kp)
Tuple< make_caster< Ts >... > subcasters
const char * name
If non-null, this is a named kwargs argument.
#define PYBIND11_BYTES_AS_STRING
Annotation indicating that a class derives from another given type.
make_caster< T >::template cast_op_type< T > cast_op(make_caster< T > &caster)
PyObject * ptr() const
Return the underlying PyObject * pointer.
#define PYBIND11_BYTES_SIZE
bool load(handle src, bool convert)
handle init_self
If this is a call to an initializer, this argument contains self
pybind11::detail::cast_op_type< _T > cast_op_type
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 tuple & args() const &
static handle cast(const void *ptr, return_value_policy, handle)
static handle cast(holder_type &&src, return_value_policy, handle)
constexpr descr< N - 1 > const_name(char const (&text)[N])
typename make_index_sequence_impl< N >::type make_index_sequence
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
static PYBIND11_NOINLINE void add_patient(handle h)
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)
PYBIND11_NOINLINE bool load_impl(handle src, bool convert)
#define PYBIND11_TYPE_CASTER(type, py_name)
#define PYBIND11_NAMESPACE_END(name)
static BinaryMeasurement< Rot3 > convert(const BetweenFactor< Pose3 >::shared_ptr &f)
std::string type
The C++ type name of the default value (only available when compiled in debug mode) ...
make_index_sequence< sizeof...(Args)> indices
std::is_base_of< pyobject_tag, remove_reference_t< T > > is_pyobject
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
#define PYBIND11_NAMESPACE_BEGIN(name)
make_index_sequence< size > indices
std::is_same< intrinsic_t< T >, pos_only > is_pos_only
void process(list &args_list, detail::args_proxy ap)
bool load(handle src, bool)