15 #include <type_traits> 20 class
handle; class
object;
48 template <
typename T>
using is_pyobject = std::is_base_of<pyobject_tag, remove_reference_t<T>>;
54 template <
typename Derived>
56 const Derived &
derived()
const {
return static_cast<const Derived &
>(*this); }
96 template <
typename T>
bool contains(
T &&item)
const;
109 object operator()(Args &&...
args)
const;
112 object call(Args&&...
args)
const;
117 bool is_none()
const {
return derived().ptr() == Py_None; }
127 object operator~()
const;
137 object operator|=(
object_api const &other)
const;
139 object operator&=(
object_api const &other)
const;
141 object operator^=(
object_api const &other)
const;
143 object operator<<=(
object_api const &other)
const;
145 object operator>>=(
object_api const &other)
const;
154 int ref_count()
const {
return static_cast<int>(Py_REFCNT(derived().
ptr())); }
156 PYBIND11_DEPRECATED(
"Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
184 PyObject *
ptr()
const {
return m_ptr; }
185 PyObject *&
ptr() {
return m_ptr; }
205 template <
typename T>
T cast()
const;
207 explicit operator bool()
const {
return m_ptr !=
nullptr; }
213 bool operator==(const
handle &
h)
const {
return m_ptr ==
h.m_ptr; }
215 bool operator!=(const
handle &
h)
const {
return m_ptr !=
h.m_ptr; }
217 bool
check()
const {
return m_ptr !=
nullptr; }
219 PyObject *m_ptr =
nullptr;
240 object(
object &&other) noexcept { m_ptr = other.m_ptr; other.m_ptr =
nullptr; }
250 PyObject *tmp = m_ptr;
263 if (
this != &other) {
266 other.m_ptr =
nullptr;
273 template <
typename T>
T cast()
const &;
275 template <
typename T>
T cast() &&;
329 PyErr_Fetch(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr());
340 void restore() { PyErr_Restore(m_type.release().ptr(), m_value.release().ptr(), m_trace.release().ptr()); }
350 PyErr_WriteUnraisable(err_context.
ptr());
363 bool matches(
handle exc)
const {
return PyErr_GivenExceptionMatches(m_type.ptr(), exc.
ptr()); }
365 const object&
type()
const {
return m_type; }
366 const object&
value()
const {
return m_value; }
367 const object&
trace()
const {
return m_trace; }
395 const auto result = PyObject_IsInstance(obj.
ptr(), type.
ptr());
404 return PyObject_HasAttr(obj.
ptr(), name.
ptr()) == 1;
408 return PyObject_HasAttrString(obj.
ptr(),
name) == 1;
420 PyObject *
result = PyObject_GetAttr(obj.
ptr(), name.
ptr());
422 return reinterpret_steal<object>(
result);
428 return reinterpret_steal<object>(
result);
432 if (PyObject *
result = PyObject_GetAttr(obj.
ptr(), name.
ptr())) {
433 return reinterpret_steal<object>(
result);
436 return reinterpret_borrow<object>(default_);
441 if (PyObject *
result = PyObject_GetAttrString(obj.
ptr(),
name)) {
442 return reinterpret_steal<object>(
result);
445 return reinterpret_borrow<object>(default_);
458 auto h = PyObject_Hash(obj.
ptr());
468 #if PY_MAJOR_VERSION >= 3 469 if (PyInstanceMethod_Check(
value.ptr()))
470 value = PyInstanceMethod_GET_FUNCTION(
value.ptr());
473 if (PyMethod_Check(
value.ptr()))
483 auto object_or_cast(
T &&o) -> decltype(std::forward<T>(o)) {
return std::forward<T>(o); }
490 template <
typename Policy>
511 template <
typename T = Policy>
517 template <
typename T = Policy>
520 return obj.contains(
key);
523 operator object()
const {
return get_cache(); }
524 PyObject *
ptr()
const {
return get_cache().ptr(); }
525 template <
typename T>
T cast()
const {
return get_cache().template cast<T>(); }
528 object &get_cache()
const {
556 PyObject *
result = PyObject_GetItem(obj.ptr(),
key.ptr());
558 return reinterpret_steal<object>(
result);
562 if (PyObject_SetItem(obj.ptr(), key.ptr(), val.ptr()) != 0) {
throw error_already_set(); }
569 static object get(
handle obj,
size_t index) {
570 PyObject *
result = PySequence_GetItem(obj.ptr(),
static_cast<ssize_t>(index));
572 return reinterpret_steal<object>(
result);
577 if (PySequence_SetItem(obj.ptr(),
static_cast<ssize_t>(index), val.ptr()) != 0) {
586 static object get(
handle obj,
size_t index) {
587 PyObject *
result = PyList_GetItem(obj.ptr(),
static_cast<ssize_t>(index));
589 return reinterpret_borrow<object>(
result);
594 if (PyList_SetItem(obj.ptr(),
static_cast<ssize_t>(index), val.inc_ref().ptr()) != 0) {
603 static object get(
handle obj,
size_t index) {
604 PyObject *
result = PyTuple_GetItem(obj.ptr(),
static_cast<ssize_t>(index));
606 return reinterpret_borrow<object>(
result);
611 if (PyTuple_SetItem(obj.ptr(),
static_cast<ssize_t>(index), val.inc_ref().ptr()) != 0) {
618 template <
typename Policy>
659 template <
typename T>
732 #if !defined(PYPY_VERSION) 744 PyObject *
iter = PyObject_GetIter(obj);
773 template <
typename T>
using is_keyword = std::is_base_of<arg, T>;
782 template <return_value_policy policy = return_value_policy::automatic_reference>
784 template <return_value_policy policy = return_value_policy::automatic_reference>
793 #define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \ 795 PYBIND11_DEPRECATED("Use reinterpret_borrow<"#Name">() or reinterpret_steal<"#Name">()") \ 796 Name(handle h, bool is_borrowed) : Parent(is_borrowed ? Parent(h, borrowed_t{}) : Parent(h, stolen_t{})) { } \ 797 Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) { } \ 798 Name(handle h, stolen_t) : Parent(h, stolen_t{}) { } \ 799 PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \ 800 bool check() const { return m_ptr != nullptr && (bool) CheckFun(m_ptr); } \ 801 static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } \ 802 template <typename Policy_> \ 803 Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) { } 805 #define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \ 806 PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \ 808 Name(const object &o) \ 809 : Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) \ 810 { if (!m_ptr) throw error_already_set(); } \ 812 : Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) \ 813 { if (!m_ptr) throw error_already_set(); } 815 #define PYBIND11_OBJECT(Name, Parent, CheckFun) \ 816 PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \ 818 Name(const object &o) : Parent(o) { } \ 819 Name(object &&o) : Parent(std::move(o)) { } 821 #define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun) \ 822 PYBIND11_OBJECT(Name, Parent, CheckFun) \ 823 Name() : Parent() { } 858 if (m_ptr && !
value.ptr()) {
859 auto&
self =
const_cast<iterator &
>(*this);
887 value = reinterpret_steal<object>(PyIter_Next(m_ptr));
912 static handle handle_of();
934 if (!m_ptr)
pybind11_fail(
"Could not allocate string object!");
940 if (!m_ptr)
pybind11_fail(
"Could not allocate string object!");
953 operator std::string()
const {
955 if (PyUnicode_Check(m_ptr)) {
956 temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(m_ptr));
958 pybind11_fail(
"Unable to extract string contents! (encoding issue)");
963 pybind11_fail(
"Unable to extract string contents! (invalid type)");
964 return std::string(buffer, (
size_t) length);
967 template <
typename... Args>
969 return attr(
"format")(std::forward<Args>(
args)...);
975 PyObject *str_value = PyObject_Str(op);
976 #if PY_MAJOR_VERSION < 3 978 PyObject *unicode = PyUnicode_FromEncodedObject(str_value,
"utf-8",
nullptr);
979 Py_XDECREF(str_value); str_value = unicode;
990 inline str operator"" _s(
const char *
s,
size_t size) {
return {
s, size}; }
1002 if (!m_ptr)
pybind11_fail(
"Could not allocate bytes object!");
1007 if (!m_ptr)
pybind11_fail(
"Could not allocate bytes object!");
1015 operator std::string()
const {
1020 return std::string(buffer, (
size_t) length);
1029 if (PyUnicode_Check(s.ptr())) {
1030 temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(s.ptr()));
1032 pybind11_fail(
"Unable to extract string contents! (encoding issue)");
1037 pybind11_fail(
"Unable to extract string contents! (invalid type)");
1041 m_ptr = obj.release().
ptr();
1049 auto obj = reinterpret_steal<object>(PyUnicode_FromStringAndSize(buffer, (
ssize_t) length));
1052 m_ptr = obj.release().
ptr();
1075 operator bool()
const {
return m_ptr && PyLong_AsLong(m_ptr) != 0; }
1080 const auto value = PyObject_IsTrue(op);
1081 if (
value == -1)
return nullptr;
1091 template <
typename Un
signed>
1093 if (
sizeof(Unsigned) <=
sizeof(
unsigned long)
1094 #
if PY_VERSION_HEX < 0x03000000
1098 unsigned long v = PyLong_AsUnsignedLong(o);
1099 return v == (
unsigned long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned)
v;
1102 unsigned long long v = PyLong_AsUnsignedLongLong(o);
1103 return v == (
unsigned long long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned)
v;
1113 template <
typename T,
1116 if (
sizeof(
T) <=
sizeof(
long)) {
1118 m_ptr = PyLong_FromLong((
long) value);
1120 m_ptr = PyLong_FromUnsignedLong((
unsigned long) value);
1123 m_ptr = PyLong_FromLongLong((
long long) value);
1125 m_ptr = PyLong_FromUnsignedLongLong((
unsigned long long) value);
1127 if (!m_ptr)
pybind11_fail(
"Could not allocate int object!");
1130 template <
typename T,
1131 detail::enable_if_t<std::is_integral<T>::value,
int> = 0>
1132 operator T()
const {
1134 ? detail::as_unsigned<T>(m_ptr)
1135 :
sizeof(
T) <=
sizeof(long)
1136 ? (
T) PyLong_AsLong(m_ptr)
1146 if (!m_ptr)
pybind11_fail(
"Could not allocate float object!");
1149 if (!m_ptr)
pybind11_fail(
"Could not allocate float object!");
1151 operator float()
const {
return (
float) PyFloat_AsDouble(m_ptr); }
1152 operator double()
const {
return (
double) PyFloat_AsDouble(m_ptr); }
1159 :
object(PyWeakref_NewRef(obj.
ptr(), callback.ptr()),
stolen_t{}) {
1160 if (!m_ptr)
pybind11_fail(
"Could not allocate weak reference!");
1168 int_ start(start_), stop(stop_),
step(step_);
1169 m_ptr = PySlice_New(start.ptr(), stop.ptr(), step.
ptr());
1170 if (!m_ptr)
pybind11_fail(
"Could not allocate slice object!");
1172 bool compute(
size_t length,
size_t *start,
size_t *stop,
size_t *
step,
1173 size_t *slicelength)
const {
1177 (
ssize_t *) slicelength) == 0;
1194 explicit capsule(
const void *
value,
const char *
name =
nullptr,
void (*destructor)(PyObject *) =
nullptr)
1201 capsule(
const void *
value,
void (*destruct)(PyObject *))
1207 capsule(
const void *
value,
void (*destructor)(
void *)) {
1208 m_ptr = PyCapsule_New(const_cast<void *>(
value),
nullptr, [](PyObject *o) {
1209 auto destructor =
reinterpret_cast<void (*)(
void *)
>(PyCapsule_GetContext(o));
1210 void *
ptr = PyCapsule_GetPointer(o,
nullptr);
1217 if (PyCapsule_SetContext(m_ptr, (
void *) destructor) != 0)
1221 capsule(
void (*destructor)()) {
1222 m_ptr = PyCapsule_New(reinterpret_cast<void *>(destructor),
nullptr, [](PyObject *o) {
1223 auto destructor =
reinterpret_cast<void (*)()
>(PyCapsule_GetPointer(o,
nullptr));
1231 template <
typename T>
operator T *()
const {
1233 T *
result =
static_cast<T *
>(PyCapsule_GetPointer(m_ptr,
name));
1234 if (!result)
pybind11_fail(
"Unable to extract capsule contents!");
1238 const char *
name()
const {
return PyCapsule_GetName(m_ptr); }
1245 if (!m_ptr)
pybind11_fail(
"Could not allocate tuple object!");
1247 size_t size()
const {
return (
size_t) PyTuple_Size(m_ptr); }
1259 if (!m_ptr)
pybind11_fail(
"Could not allocate dict object!");
1261 template <
typename... Args,
1262 typename = detail::enable_if_t<detail::all_of<detail::is_keyword_or_ds<Args>...>
::value>,
1264 typename collector = detail::deferred_t<detail::unpacking_collector<>, Args...>>
1267 size_t size()
const {
return (
size_t) PyDict_Size(m_ptr); }
1279 if (PyDict_Check(op))
1281 return PyObject_CallFunctionObjArgs((PyObject *) &PyDict_Type, op,
nullptr);
1305 if (!m_ptr)
pybind11_fail(
"Could not allocate list object!");
1307 size_t size()
const {
return (
size_t) PyList_Size(m_ptr); }
1313 template <
typename T>
void append(
T &&val)
const {
1316 template <
typename T>
void insert(
size_t index,
T &&val)
const {
1317 PyList_Insert(m_ptr, static_cast<ssize_t>(index),
1329 if (!m_ptr)
pybind11_fail(
"Could not allocate set object!");
1331 size_t size()
const {
return (
size_t) PySet_Size(m_ptr); }
1333 template <
typename T>
bool add(
T &&val)
const {
1336 void clear()
const { PySet_Clear(m_ptr); }
1347 if (fun && PyCFunction_Check(fun.
ptr()))
1364 int flags = PyBUF_STRIDES | PyBUF_FORMAT;
1365 if (writable) flags |= PyBUF_WRITABLE;
1366 auto *
view =
new Py_buffer();
1367 if (PyObject_GetBuffer(m_ptr,
view, flags) != 0) {
1390 pybind11_fail(
"Prohibited to create memoryview without Py_buffer");
1392 m_ptr = (info.view()->obj) ?
1393 PyMemoryView_FromObject(info.view()->obj) :
1394 PyMemoryView_FromBuffer(info.view());
1396 pybind11_fail(
"Unable to create memoryview from buffer descriptor");
1423 void *
ptr,
ssize_t itemsize,
const char *format,
1424 detail::any_container<ssize_t> shape,
1425 detail::any_container<ssize_t> strides,
bool readonly =
false);
1428 const void *
ptr,
ssize_t itemsize,
const char *format,
1429 detail::any_container<ssize_t> shape,
1430 detail::any_container<ssize_t> strides) {
1432 const_cast<void*>(ptr), itemsize, format, shape, strides,
true);
1435 template<
typename T>
1437 T *
ptr, detail::any_container<ssize_t> shape,
1438 detail::any_container<ssize_t> strides,
bool readonly =
false) {
1440 reinterpret_cast<void*>(ptr),
sizeof(
T),
1444 template<
typename T>
1446 const T *
ptr, detail::any_container<ssize_t> shape,
1447 detail::any_container<ssize_t> strides) {
1449 const_cast<T*>(ptr), shape, strides,
true);
1452 #if PY_MAJOR_VERSION >= 3 1467 PyObject*
ptr = PyMemoryView_FromMemory(
1468 reinterpret_cast<char*>(mem),
size,
1469 (readonly) ? PyBUF_READ : PyBUF_WRITE);
1476 return memoryview::from_memory(const_cast<void*>(mem), size,
true);
1481 #ifndef DOXYGEN_SHOULD_SKIP_THIS 1483 void *
ptr,
ssize_t itemsize,
const char* format,
1484 detail::any_container<ssize_t> shape,
1485 detail::any_container<ssize_t> strides,
bool readonly) {
1486 size_t ndim = shape->size();
1487 if (ndim != strides->size())
1488 pybind11_fail(
"memoryview: shape length doesn't match strides length");
1490 for (
size_t i = 0;
i < ndim; ++
i)
1491 size *= (*shape)[
i];
1495 view.len = size * itemsize;
1496 view.readonly =
static_cast<int>(readonly);
1497 view.itemsize = itemsize;
1498 view.format =
const_cast<char*
>(format);
1499 view.ndim =
static_cast<int>(ndim);
1500 view.shape = shape->data();
1501 view.strides = strides->data();
1502 view.suboffsets =
nullptr;
1503 view.internal =
nullptr;
1504 PyObject* obj = PyMemoryView_FromBuffer(&view);
1509 #endif // DOXYGEN_SHOULD_SKIP_THIS 1522 #if PY_VERSION_HEX >= 0x03040000 1537 PyObject *str_value = PyObject_Repr(h.
ptr());
1539 #if PY_MAJOR_VERSION < 3 1540 PyObject *unicode = PyUnicode_FromEncodedObject(str_value,
"utf-8",
nullptr);
1541 Py_XDECREF(str_value); str_value = unicode;
1544 return reinterpret_steal<str>(str_value);
1548 PyObject *
result = PyObject_GetIter(obj.
ptr());
1550 return reinterpret_steal<iterator>(
result);
1558 return {derived(), reinterpret_borrow<object>(
key)};
1564 return {derived(), reinterpret_borrow<object>(
key)};
1567 return {derived(), key};
1573 return attr(
"__contains__")(std::forward<T>(item)).template cast<bool>();
1576 template <
typename D>
1579 template <
typename D>
1582 template <
typename D>
1586 template <
typename D>
1588 int rv = PyObject_RichCompareBool(derived().
ptr(), other.
derived().ptr(),
value);
1594 #define PYBIND11_MATH_OPERATOR_UNARY(op, fn) \ 1595 template <typename D> object object_api<D>::op() const { \ 1596 object result = reinterpret_steal<object>(fn(derived().ptr())); \ 1597 if (!result.ptr()) \ 1598 throw error_already_set(); \ 1602 #define PYBIND11_MATH_OPERATOR_BINARY(op, fn) \ 1603 template <typename D> \ 1604 object object_api<D>::op(object_api const &other) const { \ 1605 object result = reinterpret_steal<object>( \ 1606 fn(derived().ptr(), other.derived().ptr())); \ 1607 if (!result.ptr()) \ 1608 throw error_already_set(); \ 1633 #undef PYBIND11_MATH_OPERATOR_UNARY 1634 #undef PYBIND11_MATH_OPERATOR_BINARY
Quick proxy class needed to implement operator-> for iterators which can't return pointers...
Vector3_ operator*(const Double_ &s, const Vector3_ &v)
typename Policy::pointer pointer
def step(data, isam, result, truth, currPoseIndex)
static iterator sentinel()
str format(Args &&...args) const
generic_iterator< iterator_policies::sequence_slow_readwrite > sequence_iterator
reference operator[](difference_type n) const
static handle handle_of()
accessor< accessor_policies::list_item > list_accessor
detail::item_accessor operator[](handle h) const
bool PyNone_Check(PyObject *o)
typename Policy::reference reference
args_proxy operator*() const
bool hasattr(handle obj, handle name)
void discard_as_unraisable(const char *err_context)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator*=(half &a, const half &b)
friend It operator+(const It &a, difference_type n)
friend It operator-(const It &a, difference_type n)
detail::sequence_accessor operator[](size_t index) const
void append(T &&val) const
EIGEN_DEVICE_FUNC const CwiseBinaryOp< internal::scalar_boolean_xor_op, const Derived, const OtherDerived > operator^(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
bytes(const std::string &s)
std::is_same< args_proxy, T > is_s_unpacking
bool operator>(object_api const &other) const
bool operator<(const benchmark_t &b1, const benchmark_t &b2)
detail::tuple_iterator end() const
pointer operator->() const
bool isinstance_generic(handle obj, const std::type_info &tp)
bool isinstance< handle >(handle)=delete
static PyObject * raw_bool(PyObject *op)
Return the truth value of an object – always returns a new reference.
bool operator<=(object_api const &other) const
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator-=(half &a, const half &b)
object(handle h, stolen_t)
bool equal(const dict_readonly &b) const
accessor(handle obj, key_type key)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp< internal::scalar_quotient_op< Scalar, typename OtherDerived::Scalar >, const Derived, const OtherDerived > operator/(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
PyObject * ptr() const
Return the underlying PyObject * pointer.
object(handle h, borrowed_t)
const mpreal operator>>(const mpreal &v, const unsigned long int k)
#define PYBIND11_LONG_CHECK(o)
bool equal(const sequence_slow_readwrite &b) const
reference dereference() const
int ref_count() const
Return the object's current reference count.
object(object &&other) noexcept
Move constructor; steals the object from other and preserves its reference count. ...
std::string error_string()
#define PYBIND11_BYTES_FROM_STRING_AND_SIZE
friend bool operator<=(const It &a, const It &b)
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 y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set view
bool contains(T &&key) const
sequence_slow_readwrite(handle obj, ssize_t index)
friend bool operator>=(const It &a, const It &b)
typename Policy::iterator_category iterator_category
accessor< accessor_policies::sequence_item > sequence_accessor
iterator iter(handle obj)
It & operator+=(difference_type n)
bool rich_compare(object_api const &other, int value) const
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>(const half &a, const half &b)
friend bool operator!=(const iterator &a, const iterator &b)
bytes(const char *c, size_t n)
item_accessor operator[](handle key) const
#define PYBIND11_BYTES_AS_STRING_AND_SIZE
STL iterator template used for tuple, list, sequence and dict.
bool isinstance(handle obj)
void delattr(handle obj, handle name)
bool contains(T &&val) const
str_attr_accessor doc() const
Get or set the object's docstring, i.e. obj.__doc__.
str(const std::string &s)
bool PyStaticMethod_Check(PyObject *o)
friend bool operator==(const iterator &a, const iterator &b)
It & operator-=(difference_type n)
#define PYBIND11_NAMESPACE
const Derived & derived() const
Signature operator|(const DiscreteKey &key, const DiscreteKey &parent)
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun)
static memoryview from_buffer(void *ptr, ssize_t itemsize, const char *format, detail::any_container< ssize_t > shape, detail::any_container< ssize_t > strides, bool readonly=false)
bool equal(object_api const &other) const
Equivalent to obj == other in Python.
generic_iterator(handle seq, ssize_t index)
bool is(object_api const &other) const
Equivalent to obj is other in Python.
bool not_equal(object_api const &other) const
PyExc_RuntimeError[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
obj_attr_accessor attr(handle key) const
bool is_none() const
Equivalent to obj is None in Python.
detail::dict_iterator begin() const
DiscreteKeys operator&(const DiscreteKey &key1, const DiscreteKey &key2)
Create a list from two keys.
dict_readonly(handle obj, ssize_t pos)
const handle & inc_ref() const &
pybind11::str str() const
T reinterpret_borrow(handle h)
auto object_or_cast(T &&o) -> decltype(std::forward< T >(o))
accessor< accessor_policies::tuple_item > tuple_accessor
ssize_t distance_to(const sequence_slow_readwrite &b) const
std::ostream & operator<<(std::ostream &s, const Jet< T, N > &z)
void operator=(T &&value)&&
detail::sequence_iterator end() const
std::is_same< kwargs_proxy, T > is_ds_unpacking
#define PYBIND11_BYTES_CHECK
detail::list_iterator end() const
iterator end() const
Return a sentinel which ends iteration.
bool PyUnicode_Check_Permissive(PyObject *o)
const object & trace() const
object & operator=(const object &other)
detail::item_accessor operator[](handle h) const
friend bool operator==(const It &a, const It &b)
reference operator*() const
std::random_access_iterator_tag iterator_category
static PyObject * raw_str(PyObject *op)
Return string representation – always returns a new reference, even if already a str...
pointer operator->() const
void discard_as_unraisable(object err_context)
EIGEN_DEVICE_FUNC NewType cast(const OldType &x)
Eigen::Triplet< double > T
bool compute(ssize_t length, ssize_t *start, ssize_t *stop, ssize_t *step, ssize_t *slicelength) const
#define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun)
#define PYBIND11_FROM_STRING
detail::sequence_iterator begin() const
detail::tuple_accessor operator[](size_t index) const
detail::item_accessor operator[](handle h) const
#define PYBIND11_DEPRECATED(reason)
std::random_access_iterator_tag iterator_category
object(const object &o)
Copy constructor; always increases the reference count.
std::is_base_of< arg, T > is_keyword
Python argument categories (using PEP 448 terms)
bool is_cpp_function() const
const handle & dec_ref() const &
detail::tuple_iterator begin() const
Unsigned as_unsigned(PyObject *o)
static PyObject * raw_dict(PyObject *op)
Call the dict Python type – always returns a new reference.
void set(Container &c, Position position, const Value &value)
handle get_function(handle value)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator+=(half &a, const half &b)
const object & type() const
Python's dictionary protocol permits this to be a forward iterator.
friend It operator+(difference_type n, const It &b)
static memoryview from_buffer(const T *ptr, detail::any_container< ssize_t > shape, detail::any_container< ssize_t > strides)
#define PYBIND11_SLICE_OBJECT
bool matches(handle exc) const
Full read and write access using the sequence protocol: see detail::sequence_accessor ...
void operator=(T &&value)&
static type of(handle h)
Return a type object from a handle or an object.
Helper class which collects positional, keyword, * and ** arguments for a Python function call...
bool equal(const sequence_fast_readonly &b) const
void insert(size_t index, T &&val) const
Tag and check to identify a class which implements the Python object API.
const object & value() const
void check(bool b, bool ref)
#define PYBIND11_LONG_AS_LONGLONG(o)
std::input_iterator_tag iterator_category
bool compute(size_t length, size_t *start, size_t *stop, size_t *step, size_t *slicelength) const
std::is_base_of< pyobject_tag, remove_reference_t< T >> is_pyobject
std::pair< handle, handle > value_type
ssize_t distance_to(const sequence_fast_readonly &b) const
reference operator*() const
generic_iterator< iterator_policies::sequence_fast_readonly > tuple_iterator
object getattr(handle obj, handle name)
handle(PyObject *ptr)
Creates a handle from the given raw Python object pointer.
bool PyEllipsis_Check(PyObject *o)
bool PyIterable_Check(PyObject *obj)
friend difference_type operator-(const It &a, const It &b)
#define PYBIND11_MATH_OPERATOR_BINARY(op, fn)
Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object.
size_t len_hint(handle h)
void operator=(const accessor &a)&
kwargs_proxy operator*() const
#define PYBIND11_MATH_OPERATOR_UNARY(op, fn)
static memoryview from_buffer(T *ptr, detail::any_container< ssize_t > shape, detail::any_container< ssize_t > strides, bool readonly=false)
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Jet< T, N > operator-(const Jet< T, N > &f)
object & operator=(object &&other) noexcept
typename Policy::value_type value_type
std::forward_iterator_tag iterator_category
T reinterpret_steal(handle h)
bool isinstance< object >(handle obj)
Annotation for function names.
generic_iterator< iterator_policies::sequence_fast_readonly > list_iterator
generic_iterator< iterator_policies::dict_readonly > dict_iterator
detail::dict_iterator end() const
Information record describing a Python buffer object.
bool contains(T &&item) const
Check if the given item is contained within this object, i.e. item in obj.
Container::iterator get(Container &c, Position position)
accessor< accessor_policies::generic_item > item_accessor
PYBIND11_DEPRECATED("Use of obj.attr(...) as bool is deprecated in favor of pybind11::hasattr(obj, ...)") explicit operator enable_if_t< std key_type key
bool operator>=(object_api const &other) const
const value_type reference
typename Policy::key_type key_type
void setattr(handle obj, handle name, handle value)
reference dereference() const
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator/=(half &a, const half &b)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
void operator=(const accessor &a)&&
~object()
Destructor; automatically calls handle::dec_ref()
Jet< T, N > const & operator+(const Jet< T, N > &f)
#define PYBIND11_NAMESPACE_END(name)
static memoryview from_buffer(const void *ptr, ssize_t itemsize, const char *format, detail::any_container< ssize_t > shape, detail::any_container< ssize_t > strides)
friend bool operator!=(const It &a, const It &b)
#define PYBIND11_OBJECT(Name, Parent, CheckFun)
str(const char *c, size_t n)
#define PYBIND11_NAMESPACE_BEGIN(name)
detail::list_iterator begin() const
sequence_fast_readonly(handle obj, ssize_t n)
reference dereference() const
bool operator<(object_api const &other) const
#define PYBIND11_BYTES_FROM_STRING
detail::list_accessor operator[](size_t index) const
Lightweight iterator policy using just a simple pointer: see PySequence_Fast_ITEMS ...