13#include "detail/common.h" 
   14#include "detail/descr.h" 
   15#include "detail/type_caster_base.h" 
   16#include "detail/typeid.h" 
   34template <
typename type, 
typename SFINAE = 
void>
 
   36template <
typename type>
 
   51template <
typename type>
 
   61            || std::is_same<reference_t, subcaster_cast_op_type>::value,
 
   62        "std::reference_wrapper<T> caster requires T to have a caster with an " 
   63        "`operator T &()` or `operator const T &()`");
 
   67    static constexpr auto name = caster_t::name;
 
   71        if (policy == return_value_policy::take_ownership
 
   72            || policy == return_value_policy::automatic) {
 
   73            policy = return_value_policy::automatic_reference;
 
   75        return caster_t::cast(&src.get(), policy, parent);
 
   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_> 
  109template <
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>   
 
  124                                     typename std::make_unsigned<_py_type_0>::type>;
 
  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__"); };
 
  143        if (std::is_floating_point<T>::value) {
 
  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;
 
  168            if (std::is_unsigned<py_type>::value) {
 
  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();
 
  183            || (std::is_integral<T>::value && 
sizeof(
py_type) != 
sizeof(T)
 
  184                && py_value != (
py_type) (T) py_value)) {
 
  186            if (py_err && convert && (PyNumber_Check(src.
ptr()) != 0)) {
 
  187                auto tmp = reinterpret_steal<object>(std::is_floating_point<T>::value
 
  188                                                         ? PyNumber_Float(src.
ptr())
 
  189                                                         : PyNumber_Long(src.
ptr()));
 
  191                return load(tmp, 
false);
 
  196        value = (T) py_value;
 
  200    template <
typename U = T>
 
  201    static typename std::enable_if<std::is_floating_point<U>::value, 
handle>
::type 
  203        return PyFloat_FromDouble((
double) src);
 
  206    template <
typename U = T>
 
  207    static typename std::enable_if<!std::is_floating_point<U>::value && std::is_signed<U>::value
 
  208                                       && (
sizeof(U) <= 
sizeof(
long)),
 
  214    template <
typename U = T>
 
  215    static typename std::enable_if<!std::is_floating_point<U>::value && std::is_unsigned<U>::value
 
  216                                       && (
sizeof(U) <= 
sizeof(
unsigned long)),
 
  222    template <
typename U = T>
 
  223    static typename std::enable_if<!std::is_floating_point<U>::value && std::is_signed<U>::value
 
  224                                       && (
sizeof(U) > 
sizeof(
long)),
 
  227        return PyLong_FromLongLong((
long long) src);
 
  230    template <
typename U = T>
 
  231    static typename std::enable_if<!std::is_floating_point<U>::value && std::is_unsigned<U>::value
 
  232                                       && (
sizeof(U) > 
sizeof(
unsigned long)),
 
  235        return PyLong_FromUnsignedLongLong((
unsigned long long) src);
 
  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) {
 
  360template <
typename StringType, 
bool IsView = false>
 
  362    using CharT = 
typename StringType::value_type;
 
  366    static_assert(!std::is_same<CharT, char>::value || 
sizeof(
CharT) == 1,
 
  367                  "Unsupported char size != 1");
 
  368#if defined(PYBIND11_HAS_U8STRING) 
  369    static_assert(!std::is_same<CharT, char8_t>::value || 
sizeof(
CharT) == 1,
 
  370                  "Unsupported char8_t size != 1");
 
  372    static_assert(!std::is_same<CharT, char16_t>::value || 
sizeof(
CharT) == 2,
 
  373                  "Unsupported char16_t size != 2");
 
  374    static_assert(!std::is_same<CharT, char32_t>::value || 
sizeof(
CharT) == 4,
 
  375                  "Unsupported char32_t size != 4");
 
  377    static_assert(!std::is_same<CharT, wchar_t>::value || 
sizeof(
CharT) == 2 || 
sizeof(
CharT) == 4,
 
  378                  "Unsupported wchar_t size != 2/4");
 
  382#if PY_MAJOR_VERSION < 3 
  389        if (!PyUnicode_Check(load_src.
ptr())) {
 
  390#if PY_MAJOR_VERSION >= 3 
  393            if (std::is_same<CharT, char>::value) {
 
  401            temp = reinterpret_steal<object>(PyUnicode_FromObject(load_src.
ptr()));
 
  410#if PY_VERSION_HEX >= 0x03030000 
  414            Py_ssize_t size = -1;
 
  416                = 
reinterpret_cast<const CharT *
>(PyUnicode_AsUTF8AndSize(load_src.
ptr(), &size));
 
  421            value = StringType(
buffer, 
static_cast<size_t>(size));
 
  427            = reinterpret_steal<object>(PyUnicode_AsEncodedString(load_src.
ptr(),
 
  429                                                                  : 
UTF_N == 16 ? 
"utf-16" 
  445        value = StringType(
buffer, length);
 
  457        const char *
buffer = 
reinterpret_cast<const char *
>(src.data());
 
  470#if !defined(PYPY_VERSION) 
  471        return UTF_N == 8    ? PyUnicode_DecodeUTF8(
buffer, nbytes, 
nullptr)
 
  472               : 
UTF_N == 16 ? PyUnicode_DecodeUTF16(
buffer, nbytes, 
nullptr, 
nullptr)
 
  473                             : PyUnicode_DecodeUTF32(
buffer, nbytes, 
nullptr, 
nullptr);
 
  478        return PyUnicode_Decode(
buffer,
 
  481                                : 
UTF_N == 16 ? 
"utf-16" 
  490    template <
typename C = CharT>
 
  505    template <
typename C = CharT>
 
  511template <
typename CharT, 
class Traits, 
class Allocator>
 
  514    : 
string_caster<std::basic_string<CharT, Traits, Allocator>> {};
 
  516#ifdef PYBIND11_HAS_STRING_VIEW 
  517template <
typename CharT, 
class Traits>
 
  520    : 
string_caster<std::basic_string_view<CharT, Traits>, true> {};
 
  525template <
typename CharT>
 
  546        return str_caster.
load(src, convert);
 
  550        if (src == 
nullptr) {
 
  551            return pybind11::none().
inc_ref();
 
  553        return StringCaster::cast(
StringType(src), policy, parent);
 
  557        if (std::is_same<char, CharT>::value) {
 
  558            handle s = PyUnicode_DecodeLatin1((
const char *) &src, 1, 
nullptr);
 
  564        return StringCaster::cast(
StringType(1, src), policy, parent);
 
  567    explicit operator CharT *() {
 
  568        return none ? nullptr : 
const_cast<CharT *
>(
static_cast<StringType &
>(str_caster).
c_str());
 
  570    explicit operator CharT &() {
 
  572            throw value_error(
"Cannot convert None to a character");
 
  576        size_t str_len = 
value.size();
 
  578            throw value_error(
"Cannot convert empty string to a character");
 
  587            auto v0 = 
static_cast<unsigned char>(
value[0]);
 
  592            size_t char0_bytes = (v0 & 0x80) == 0      ? 1
 
  593                                 : (v0 & 0xE0) == 0xC0 ? 2
 
  594                                 : (v0 & 0xF0) == 0xE0 ? 3
 
  597            if (char0_bytes == str_len) {
 
  599                if (char0_bytes == 2 && (v0 & 0xFC) == 0xC0) { 
 
  600                    one_char = 
static_cast<CharT
>(((v0 & 3) << 6)
 
  601                                                  + (
static_cast<unsigned char>(
value[1]) & 0x3F));
 
  605                throw value_error(
"Character code point not in range(0x100)");
 
  613            one_char = 
static_cast<CharT
>(
value[0]);
 
  614            if (one_char >= 0xD800 && one_char < 0xE000) {
 
  615                throw value_error(
"Character code point not in range(0x10000)");
 
  620            throw value_error(
"Expected a character, but multi-character string found");
 
  628    template <
typename _T>
 
  633template <
template <
typename...> 
class Tuple, 
typename... Ts>
 
  636    static constexpr auto size = 
sizeof...(Ts);
 
  641        if (!isinstance<sequence>(src)) {
 
  644        const auto seq = reinterpret_borrow<sequence>(src);
 
  645        if (seq.size() != 
size) {
 
  651    template <
typename T>
 
  657    template <
typename T>
 
  662        if (policy == return_value_policy::take_ownership) {
 
  663            auto h = 
cast(std::move(*src), policy, parent);
 
  667        return cast(*src, policy, parent);
 
  673    template <
typename T>
 
  677    explicit operator type() && { 
return std::move(*this).implicit_cast(
indices{}); }
 
  680    template <
size_t... Is>
 
  684    template <
size_t... Is>
 
  691    template <
size_t... Is>
 
  693#ifdef __cpp_fold_expressions 
  698        for (
bool r : {std::get<Is>(
subcasters).load(seq[Is], convert)...}) {
 
  708    template <
typename T, 
size_t... Is>
 
  713        std::array<object, size> entries{{reinterpret_steal<object>(
 
  715        for (
const auto &entry : entries) {
 
  722        for (
auto &entry : entries) {
 
  723            PyTuple_SET_ITEM(result.ptr(), counter++, entry.release().ptr());
 
  725        return result.release();
 
  731template <
typename T1, 
typename T2>
 
  734template <
typename... Ts>
 
  741    static auto get(
const T &p) -> 
decltype(p.get()) { 
return p.get(); }
 
  749template <
typename type, 
typename holder_type, 
typename SFINAE = 
void>
 
  753    static_assert(std::is_base_of<base, type_caster<type>>
::value,
 
  754                  "Holder classes are only supported for custom types");
 
  761        return base::template load_impl<copyable_holder_caster<type, holder_type>>(src, convert);
 
  768    explicit operator holder_type *() { 
return std::addressof(
holder); }
 
  769    explicit operator holder_type &() { 
return holder; }
 
  780            throw cast_error(
"Unable to load a custom holder type from a default-holder instance");
 
  785        if (v_h.holder_constructed()) {
 
  786            value = v_h.value_ptr();
 
  787            holder = v_h.template holder<holder_type>();
 
  790        throw cast_error(
"Unable to cast from non-held to held instance (T& to Holder<T>) " 
  792                         "(compile in debug mode for type information)");
 
  795                         + type_id<holder_type>() + 
"''");
 
  799    template <
typename T = holder_type,
 
  800              detail::enable_if_t<!std::is_constructible<T, const T &, type *>::value, 
int> = 0>
 
  805    template <
typename T = holder_type,
 
  806              detail::enable_if_t<std::is_constructible<T, const T &, type *>::value, 
int> = 0>
 
  810            if (sub_caster.
load(src, convert)) {
 
  831template <
typename type, 
typename holder_type, 
typename SFINAE = 
void>
 
  834                  "Holder classes are only supported for custom types");
 
  843template <
typename type, 
typename deleter>
 
  847template <
typename type, 
typename holder_type>
 
  852template <
typename T, 
bool Value = false>
 
  854    static constexpr bool value = Value;
 
  858#define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type, ...)                                      \ 
  859    namespace pybind11 {                                                                          \ 
  861    template <typename type>                                                                      \ 
  862    struct always_construct_holder<holder_type> : always_construct_holder<void, ##__VA_ARGS__> {  \ 
  864    template <typename type>                                                                      \ 
  865    class type_caster<holder_type, enable_if_t<!is_shared_ptr<holder_type>::value>>               \ 
  866        : public type_caster_holder<type, holder_type> {};                                        \ 
  871template <
typename base, 
typename holder>
 
  873    : std::is_base_of<detail::type_caster_holder<base, holder>, detail::type_caster<holder>> {};
 
  875template <
typename base, 
typename deleter>
 
  880    static constexpr auto name = const_name<T>();
 
  919template <
typename type>
 
  921    template <typename T = type, enable_if_t<std::is_same<T, handle>::value, 
int> = 0>
 
  924        return static_cast<bool>(value);
 
  927    template <typename T = type, enable_if_t<std::is_base_of<object, T>::value, 
int> = 0>
 
  929#if PY_MAJOR_VERSION < 3 && !defined(PYBIND11_STR_LEGACY_PERMISSIVE) 
  934            PyObject *str_from_bytes = PyUnicode_FromEncodedObject(src.
ptr(), 
"utf-8", 
nullptr);
 
  937            value = reinterpret_steal<type>(str_from_bytes);
 
  941        if (!isinstance<type>(src)) {
 
  944        value = reinterpret_borrow<type>(src);
 
  969template <
typename T, 
typename SFINAE = 
void>
 
  977               std::is_move_constructible<T>,
 
  978               std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>::value>>
 
  980template <
typename T, 
typename SFINAE = 
void>
 
  988               std::is_move_constructible<T>,
 
  989               std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>::value>>
 
  998template <
typename type>
 
 1000    = 
bool_constant<(std::is_reference<type>::value || std::is_pointer<type>::value)
 
 1007template <
typename Return, 
typename SFINAE = 
void>
 
 1012template <
typename Return>
 
 1015    detail::
enable_if_t<std::is_base_of<type_caster_generic, make_caster<Return>>::value, void>> {
 
 1017        return !std::is_lvalue_reference<Return>::value && !std::is_pointer<Return>::value
 
 1018                   ? return_value_policy::move
 
 1024template <
typename T, 
typename SFINAE>
 
 1026    if (!conv.load(
handle, 
true)) {
 
 1029            "Unable to cast Python instance to C++ type (compile in debug mode for details)");
 
 1031        throw cast_error(
"Unable to cast Python instance of type " 
 1033                         + type_id<T>() + 
"'");
 
 1039template <
typename T>
 
 1049template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, 
int> = 0>
 
 1051    using namespace detail;
 
 1053                  "Unable to cast type to reference: value is local to type caster");
 
 1054    return cast_op<T>(load_type<T>(
handle));
 
 1058template <typename T, detail::enable_if_t<detail::is_pyobject<T>::value, 
int> = 0>
 
 1060    return T(reinterpret_borrow<object>(
handle));
 
 1064template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, 
int> = 0>
 
 1068    using no_ref_T = 
typename std::remove_reference<T>::type;
 
 1078    return reinterpret_steal<object>(
 
 1082template <
typename T>
 
 1084    return pybind11::cast<T>(*
this);
 
 1091template <
typename T>
 
 1092detail::enable_if_t<!detail::move_never<T>::value, T> 
move(
object &&obj) {
 
 1093    if (obj.ref_count() > 1) {
 
 1096            "Unable to cast Python instance to C++ rvalue: instance has multiple references" 
 1097            " (compile in debug mode for details)");
 
 1099        throw cast_error(
"Unable to move from Python " + (std::string) 
str(
type::handle_of(obj))
 
 1100                         + 
" instance to C++ " + type_id<T>()
 
 1101                         + 
" instance: instance has multiple references");
 
 1106    T ret = std::move(detail::load_type<T>(obj).
operator T &());
 
 1115template <
typename T>
 
 1116detail::enable_if_t<detail::move_always<T>::value, T> 
cast(
object &&
object) {
 
 1117    return move<T>(std::move(
object));
 
 1119template <
typename T>
 
 1120detail::enable_if_t<detail::move_if_unreferenced<T>::value, T> 
cast(
object &&
object) {
 
 1121    if (
object.ref_count() > 1) {
 
 1122        return cast<T>(
object);
 
 1124    return move<T>(std::move(
object));
 
 1126template <
typename T>
 
 1127detail::enable_if_t<detail::move_never<T>::value, T> 
cast(
object &&
object) {
 
 1128    return cast<T>(
object);
 
 1131template <
typename T>
 
 1133    return pybind11::cast<T>(*
this);
 
 1135template <
typename T>
 
 1137    return pybind11::cast<T>(std::move(*
this));
 
 1151template <typename T, enable_if_t<!is_pyobject<T>::value, 
int>>
 
 1153    return pybind11::cast(std::forward<T>(o));
 
 1159template <
typename ret_type>
 
 1166template <
typename T>
 
 1169    return cast_op<T>(
load_type(caster, o));
 
 1171template <
typename T>
 
 1180template <
typename T>
 
 1182    return pybind11::cast<T>(std::move(o));
 
 1184template <
typename T>
 
 1186    pybind11_fail(
"Internal error: cast_safe fallback invoked");
 
 1198        "Unable to convert call argument to Python object (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");
 
 1208template <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>(
 
 1218    for (
size_t i = 0; i < 
args.
size(); i++) {
 
 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)
 
 1244    template <
typename T>
 
 1267    template <
typename T>
 
 1280        if (PyErr_Occurred()) {
 
 1287    template <
typename T>
 
 1292    template <
typename T>
 
 1328template <
typename T>
 
 1330    return {*
this, std::forward<T>(value)};
 
 1346template <
typename T>
 
 1348template <
typename T>
 
 1379template <
typename... Args>
 
 1383    template <
typename Arg>
 
 1385    template <
typename Arg>
 
 1391                  "py::kwargs is only permitted as the last argument of a function");
 
 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 
 1430        for (
bool r : {std::get<Is>(
argcasters).load(
call.args[Is], 
call.args_convert[Is])...}) {
 
 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)))...);
 
 1449template <return_value_policy policy>
 
 1452    template <
typename... Ts>
 
 1463        PyObject *result = PyObject_CallObject(ptr, 
m_args.
ptr());
 
 1467        return reinterpret_steal<object>(result);
 
 1475template <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);
 
 1501        return reinterpret_steal<object>(result);
 
 1505    template <
typename T>
 
 1507        auto o = reinterpret_steal<object>(
 
 1555        for (
auto k : reinterpret_borrow<dict>(kp)) {
 
 1568        throw type_error(
"Got kwargs without a name; only named arguments " 
 1569                         "may be passed via py::arg() to a python function call. " 
 1570                         "(compile in debug mode for details)");
 
 1573        throw type_error(
"Got kwargs without a name of type '" + 
type 
 1575                           "arguments may be passed via py::arg() to a python function call. ");
 
 1578        throw type_error(
"Got multiple values for keyword argument " 
 1579                         "(compile in debug mode for details)");
 
 1583        throw type_error(
"Got multiple values for keyword argument '" + 
name + 
"'");
 
 1595template <
typename... Args>
 
 1615                          < constexpr_first<is_keyword_or_ds, Args...>()
 
 1617                             < constexpr_first<is_ds_unpacking, Args...>(),
 
 1618                  "Invalid function call: positional args must precede keywords and ** unpacking; " 
 1619                  "* unpacking must precede ** unpacking");
 
 1623template <
typename Derived>
 
 1626#if !defined(NDEBUG) && PY_VERSION_HEX >= 0x03060000 
 1627    if (!PyGILState_Check()) {
 
 1628        pybind11_fail(
"pybind11::object_api<>::operator() PyGILState_Check() failure.");
 
 1631    return detail::collect_arguments<policy>(std::forward<Args>(
args)...).call(derived().ptr());
 
 1634template <
typename Derived>
 
 1637    return operator()<policy>(std::forward<Args>(
args)...);
 
 1642template <
typename T>
 
 1644    static_assert(std::is_base_of<detail::type_caster_generic, detail::make_caster<T>>::value,
 
 1645                  "py::type::of<T> only supports the case where T is a registered C++ types.");
 
 1647    return detail::get_type_handle(
typeid(T), 
true);
 
 1650#define PYBIND11_MAKE_OPAQUE(...)                                                                 \ 
 1651    namespace pybind11 {                                                                          \ 
 1652    namespace detail {                                                                            \ 
 1654    class type_caster<__VA_ARGS__> : public type_caster_base<__VA_ARGS__> {};                     \ 
 1661#define PYBIND11_TYPE(...) __VA_ARGS__ 
Helper class which loads arguments for C++ functions called from Python.
 
bool load_impl_sequence(function_call &call, index_sequence< Is... >)
 
Return call_impl(Func &&f, index_sequence< Is... >, Guard &&) &&
 
enable_if_t< std::is_void< Return >::value, void_type > call(Func &&f) &&
 
std::is_same< intrinsic_t< Arg >, args > argument_is_args
 
static bool load_impl_sequence(function_call &, index_sequence<>)
 
make_index_sequence< sizeof...(Args)> indices
 
static constexpr auto arg_names
 
std::tuple< make_caster< Args >... > argcasters
 
static constexpr int args_pos
 
std::is_same< intrinsic_t< Arg >, kwargs > argument_is_kwargs
 
bool load_args(function_call &call)
 
enable_if_t<!std::is_void< Return >::value, Return > call(Func &&f) &&
 
static constexpr auto kwargs_pos
 
static constexpr bool has_kwargs
 
bool contains(T &&key) const
 
Fetch and hold an error which was already set in Python.
 
\rst Holds a reference to a Python object (no reference counting)
 
const handle & inc_ref() const &
\rst Manually increase the reference count of the Python object.
 
T cast() const
\rst Attempt to cast the Python object into the given C++ type.
 
PyObject * ptr() const
Return the underlying PyObject * pointer.
 
\rst Wraps a Python iterator so that it can also be used as a C++ input iterator
 
static PYBIND11_NOINLINE void add_patient(handle h)
This can only be used inside a pybind11-bound function, either by argument_loader at argument prepara...
 
\rst A mixin class which adds common functions to handle, object and various accessors.
 
object operator()(Args &&...args) const
\rst Assuming the Python object is a function or implements the __call__ protocol,...
 
\rst Holds a reference to a Python object (with reference counting)
 
handle release()
\rst Resets the internal pointer to nullptr without decreasing the object's reference count.
 
Helper class which collects only positional arguments for a Python function call.
 
simple_collector(Ts &&...values)
 
object call(PyObject *ptr) const
Call a Python function and pass the collected arguments.
 
const tuple & args() const &
 
static handle cast(T *src, return_value_policy policy, handle parent)
 
static constexpr auto size
 
type implicit_cast(index_sequence< Is... >) &&
 
bool load(handle src, bool convert)
 
static constexpr bool load_impl(const sequence &, bool, index_sequence<>)
 
static handle cast_impl(T &&src, return_value_policy policy, handle parent, index_sequence< Is... >)
 
bool load_impl(const sequence &seq, bool convert, index_sequence< Is... >)
 
type implicit_cast(index_sequence< Is... >) &
 
Tuple< make_caster< Ts >... > subcasters
 
static handle cast(T &&src, return_value_policy policy, handle parent)
 
make_index_sequence< size > indices
 
PYBIND11_TYPE_CASTER(bool, const_name("bool"))
 
bool load(handle src, bool convert)
 
static handle cast(bool src, return_value_policy, handle)
 
static handle cast(const std::reference_wrapper< type > &src, return_value_policy policy, handle parent)
 
std::reference_wrapper< type > cast_op_type
 
typename caster_t::template cast_op_type< reference_t > subcaster_cast_op_type
 
bool load(handle src, bool convert)
 
bool load(handle h, bool)
 
static handle cast(const void *ptr, return_value_policy, handle)
 
Generic type caster for objects stored on the heap.
 
static handle cast_holder(const itype *src, const void *holder)
 
static handle cast(const itype &src, return_value_policy policy, handle parent)
 
const type_info * typeinfo
 
static PYBIND11_NOINLINE handle cast(const void *_src, return_value_policy policy, handle parent, const detail::type_info *tinfo, void *(*copy_constructor)(const void *), void *(*move_constructor)(const void *), const void *existing_holder=nullptr)
 
bool load(handle src, bool convert)
 
static handle handle_of()
Convert C++ type to handle if previously registered.
 
Helper class which collects positional, keyword, * and ** arguments for a Python function call.
 
static void multiple_values_error()
 
static void nameless_argument_error()
 
static void multiple_values_error(const std::string &name)
 
void process(list &, detail::kwargs_proxy kp)
 
object call(PyObject *ptr) const
Call a Python function and pass the collected arguments.
 
const tuple & args() const &
 
unpacking_collector(Ts &&...values)
 
const dict & kwargs() const &
 
void process(list &args_list, detail::args_proxy ap)
 
static void nameless_argument_error(const std::string &type)
 
void process(list &args_list, T &&x)
 
void process(list &, arg_v a)
 
bool hasattr(handle obj, handle name)
 
conditional_t< is_copy_constructible< holder_type >::value, copyable_holder_caster< type, holder_type >, move_only_holder_caster< type, holder_type > > type_caster_holder
 
std::is_same< intrinsic_t< T >, pos_only > is_pos_only
 
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
 
constexpr bool args_are_all_positional()
 
T cast(const handle &handle)
 
cast_error cast_error_unable_to_convert_call_arg(const std::string &name, const std::string &type)
 
object object_or_cast(T &&o)
 
conditional_t< cast_is_temporary_value_reference< ret_type >::value, make_caster< ret_type >, override_unused > override_caster_t
 
enable_if_t< cast_is_temporary_value_reference< T >::value, T > cast_ref(object &&o, make_caster< T > &caster)
 
enable_if_t<!cast_is_temporary_value_reference< T >::value, T > cast_safe(object &&o)
 
void cast_safe< void >(object &&)
 
make_caster< T >::template cast_op_type< T > cast_op(make_caster< T > &caster)
 
simple_collector< policy > collect_arguments(Args &&...args)
Collect only positional arguments for a Python function call.
 
std::is_same< intrinsic_t< T >, kw_only > is_kw_only
 
type_caster< T, SFINAE > & load_type(type_caster< T, SFINAE > &conv, const handle &handle)
 
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
 
std::integral_constant< bool, B > bool_constant
Backports of std::bool_constant and std::negation to accommodate older compilers.
 
#define PYBIND11_LONG_AS_LONGLONG(o)
 
PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Thrown when pybind11::cast or.
 
constexpr int constexpr_first()
Return the index of the first type in Ts which satisfies Predicate<T>.
 
typename intrinsic_type< T >::type intrinsic_t
 
#define PYBIND11_STRING_NAME
 
#define PYBIND11_BYTES_SIZE
 
#define PYBIND11_BYTES_CHECK
 
#define PYBIND11_LONG_CHECK(o)
 
typename std::remove_cv< T >::type remove_cv_t
 
#define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
 
#define PYBIND11_NAMESPACE_END(name)
 
#define PYBIND11_BYTES_NAME
 
#define PYBIND11_NAMESPACE_BEGIN(name)
 
#define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
 
#define PYBIND11_BYTES_AS_STRING
 
typename make_index_sequence_impl< N >::type make_index_sequence
 
std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... > > all_of
 
typename std::conditional< B, T, F >::type conditional_t
 
#define PYBIND11_BOOL_ATTR
 
constexpr int constexpr_last()
Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.
 
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
 
@ copy
Create a new copy of the returned object, which will be owned by Python.
 
@ automatic_reference
As above, but use policy return_value_policy::reference when the return value is a pointer.
 
@ automatic
This is the default return value policy, which falls back to the policy return_value_policy::take_own...
 
@ move
Use std::move to move the return value contents into a new instance that will be owned by Python.
 
@ take_ownership
Reference an existing object (i.e.
 
@ reference
Reference an existing object, but do not take ownership.
 
#define PYBIND11_LONG_FROM_UNSIGNED(o)
 
#define PYBIND11_SILENCE_MSVC_C4127(...)
 
#define PYBIND11_NB_BOOL(ptr)
 
#define PYBIND11_LONG_FROM_SIGNED(o)
 
constexpr descr< N - 1 > const_name(char const (&text)[N])
 
constexpr descr< N+2, Ts... > type_descr(const descr< N, Ts... > &descr)
 
constexpr descr< 0 > concat()
 
const char * c_str(Args &&...args)
Constructs a std::string with the given arguments, stores it in internals, and returns its c_str().
 
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
Determine suitable casting operator for pointer-or-lvalue-casting type casters.
 
const std::vector< detail::type_info * > & all_type_info(PyTypeObject *type)
Extracts vector of type_info pointers of pybind-registered roots of the given Python type.
 
std::is_base_of< pyobject_tag, remove_reference_t< T > > is_pyobject
 
T reinterpret_steal(handle h)
\rst Like reinterpret_borrow, but steals the reference.
 
std::is_same< args_proxy, T > is_s_unpacking
 
satisfies_none_of< T, is_keyword, is_s_unpacking, is_ds_unpacking > is_positional
 
T cast(const handle &handle)
 
cast_error cast_error_unable_to_convert_call_arg(const std::string &name, const std::string &type)
 
static constexpr bool value
 
Annotation for arguments with values.
 
arg_v(const arg &base, T &&x, const char *descr=nullptr)
Called internally when invoking py::arg("a") = value
 
arg_v & none(bool flag=true)
Same as arg::nonone(), but returns *this as arg_v&, not arg&.
 
arg_v & noconvert(bool flag=true)
Same as arg::noconvert(), but returns *this as arg_v&, not arg&.
 
object value
The default value.
 
std::string type
The C++ type name of the default value (only available when compiled in debug mode)
 
arg_v(const char *name, T &&x, const char *descr=nullptr)
Direct construction with name, default, and description.
 
arg_v(arg &&base, T &&x, const char *descr=nullptr)
 
const char * descr
The (optional) description of the default value.
 
Annotation for arguments.
 
arg & noconvert(bool flag=true)
Indicate that the type should not be converted in the type caster.
 
const char * name
If non-null, this is a named kwargs argument.
 
arg & none(bool flag=true)
Indicates that the argument should/shouldn't allow None (e.g. for nullable pointer args)
 
bool flag_none
If set (the default), allow None to be passed to this argument.
 
constexpr arg(const char *name=nullptr)
Constructs an argument with the name of the argument; if null or omitted, this is a positional argume...
 
arg_v operator=(T &&value) const
Assign a value to this argument.
 
bool flag_noconvert
If set, do not allow conversion (requires a supporting type caster!)
 
Annotation indicating that a class derives from another given type.
 
Type caster for holder types like std::shared_ptr, etc.
 
bool load_value(value_and_holder &&v_h)
 
bool load(handle src, bool convert)
 
void check_holder_compat()
 
static bool try_direct_conversions(handle)
 
bool try_implicit_casts(handle src, bool convert)
 
bool try_implicit_casts(handle, bool)
 
static handle cast(const holder_type &src, return_value_policy, handle)
 
Internal data associated with a single function call.
 
object args_ref
Extra references for the optional py::args and/or py::kwargs arguments (which, if present,...
 
handle parent
The parent, if any.
 
std::vector< bool > args_convert
The convert value the arguments should be loaded with.
 
handle init_self
If this is a call to an initializer, this argument contains self
 
const function_record & func
The function data:
 
std::vector< handle > args
Arguments passed to the function:
 
Internal data structure which holds metadata about a bound function (signature, overloads,...
 
Helper class which abstracts away certain actions.
 
static auto get(const T &p) -> decltype(p.get())
 
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
 
Annotation indicating that all following arguments are keyword-only; the is the equivalent of an unna...
 
Type caster for holder types like std::unique_ptr.
 
static handle cast(holder_type &&src, return_value_policy, handle)
 
Annotation for function names.
 
Annotation indicating that all previous arguments are positional-only; the is the equivalent of an un...
 
PYBIND11_TYPE_CASTER(type, handle_type_name< type >::name)
 
bool load(handle src, bool)
 
static handle cast(const handle &src, return_value_policy, handle)
 
static return_value_policy policy(return_value_policy p)
 
static return_value_policy policy(return_value_policy p)
 
typename StringType::value_type CharT
 
static handle decode_utfN(const char *buffer, ssize_t nbytes)
 
static constexpr size_t UTF_N
 
bool load(handle src, bool)
 
static handle cast(const StringType &src, return_value_policy, handle)
 
bool load_bytes(enable_if_t< std::is_same< C, char >::value, handle > src)
 
bool load_bytes(enable_if_t<!std::is_same< C, char >::value, handle >)
 
PYBIND11_TYPE_CASTER(StringType, const_name(PYBIND11_STRING_NAME))
 
bool load(handle src, bool convert)
 
pybind11::detail::cast_op_type< _T > cast_op_type
 
static handle cast(const CharT *src, return_value_policy policy, handle parent)
 
std::basic_string< CharT > StringType
 
static handle cast(CharT src, return_value_policy policy, handle parent)
 
conditional_t< sizeof(T)<=sizeof(long), long, long long > _py_type_0
 
static std::enable_if<!std::is_floating_point< U >::value &&std::is_unsigned< U >::value &&(sizeof(U)>sizeof(unsignedlong)), handle >::type cast(U src, return_value_policy, handle)
 
conditional_t< std::is_floating_point< T >::value, double, _py_type_1 > py_type
 
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)
 
PYBIND11_TYPE_CASTER(T, const_name< std::is_integral< T >::value >("int", "float"))
 
static std::enable_if<!std::is_floating_point< U >::value &&std::is_unsigned< U >::value &&(sizeof(U)<=sizeof(unsignedlong)), handle >::type cast(U src, return_value_policy, handle)
 
bool load(handle src, bool convert)
 
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)
 
static std::enable_if< std::is_floating_point< U >::value, handle >::type cast(U src, return_value_policy, handle)
 
conditional_t< std::is_signed< T >::value, _py_type_0, typename std::make_unsigned< _py_type_0 >::type > _py_type_1
 
std::vector< std::pair< const std::type_info *, void *(*)(void *)> > implicit_casts
 
PYBIND11_TYPE_CASTER(T, const_name("None"))
 
static handle cast(T, return_value_policy, handle)
 
bool load(handle src, bool)
 
Helper type to replace 'void' in some expressions.