15 #include <type_traits> 20 class handle;
class object;
21 class str;
class iterator;
22 struct arg;
struct arg_v;
30 namespace accessor_policies {
47 template <
typename T>
using is_pyobject = std::is_base_of<pyobject_tag, remove_reference_t<T>>;
53 template <
typename Derived>
55 const Derived &
derived()
const {
return static_cast<const Derived &
>(*this); }
95 template <
typename T>
bool contains(T &&item)
const;
107 template <
return_value_policy policy = return_value_policy::automatic_reference,
typename... Args>
108 object operator()(Args &&...
args)
const;
109 template <
return_value_policy policy = return_value_policy::automatic_reference,
typename... Args>
116 bool is_none()
const {
return derived().ptr() == Py_None; }
153 int ref_count()
const {
return static_cast<int>(Py_REFCNT(derived().ptr())); }
182 PyObject *
ptr()
const {
return m_ptr; }
183 PyObject *&
ptr() {
return m_ptr; }
203 template <
typename T> T
cast()
const;
205 explicit operator bool()
const {
return m_ptr !=
nullptr; }
215 bool check()
const {
return m_ptr !=
nullptr; }
217 PyObject *m_ptr =
nullptr;
238 object(
object &&other) noexcept { m_ptr = other.m_ptr; other.m_ptr =
nullptr; }
248 PyObject *tmp = m_ptr;
261 if (
this != &other) {
264 other.m_ptr =
nullptr;
271 template <
typename T> T
cast()
const &;
273 template <
typename T> T
cast() &&;
327 PyErr_Fetch(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr());
338 void restore() { PyErr_Restore(m_type.release().ptr(), m_value.release().ptr(), m_trace.release().ptr()); }
347 bool matches(
handle exc)
const {
return PyErr_GivenExceptionMatches(m_type.ptr(), exc.
ptr()); }
349 const object&
type()
const {
return m_type; }
350 const object&
value()
const {
return m_value; }
351 const object&
trace()
const {
return m_trace; }
379 const auto result = PyObject_IsInstance(obj.
ptr(), type.
ptr());
388 return PyObject_HasAttr(obj.
ptr(), name.
ptr()) == 1;
392 return PyObject_HasAttrString(obj.
ptr(), name) == 1;
404 PyObject *result = PyObject_GetAttr(obj.
ptr(), name.
ptr());
406 return reinterpret_steal<object>(result);
410 PyObject *result = PyObject_GetAttrString(obj.
ptr(), name);
412 return reinterpret_steal<object>(result);
416 if (PyObject *result = PyObject_GetAttr(obj.
ptr(), name.
ptr())) {
417 return reinterpret_steal<object>(result);
420 return reinterpret_borrow<object>(default_);
425 if (PyObject *result = PyObject_GetAttrString(obj.
ptr(), name)) {
426 return reinterpret_steal<object>(result);
429 return reinterpret_borrow<object>(default_);
442 auto h = PyObject_Hash(obj.
ptr());
452 #if PY_MAJOR_VERSION >= 3 453 if (PyInstanceMethod_Check(
value.ptr()))
454 value = PyInstanceMethod_GET_FUNCTION(
value.ptr());
457 if (PyMethod_Check(
value.ptr()))
467 auto object_or_cast(T &&o) -> decltype(std::forward<T>(o)) {
return std::forward<T>(o); }
474 template <
typename Policy>
495 template <
typename T = Policy>
498 std::is_same<T, accessor_policies::obj_attr>::
value,
bool>()
const {
501 template <
typename T = Policy>
507 operator object()
const {
return get_cache(); }
508 PyObject *ptr()
const {
return get_cache().ptr(); }
509 template <
typename T> T
cast()
const {
return get_cache().template cast<T>(); }
512 object &get_cache()
const {
513 if (!cache) { cache = Policy::get(obj, key); }
532 static object get(
handle obj,
const char *key) {
return getattr(obj, key); }
540 PyObject *result = PyObject_GetItem(obj.ptr(), key.ptr());
542 return reinterpret_steal<object>(result);
546 if (PyObject_SetItem(obj.ptr(), key.ptr(), val.ptr()) != 0) {
throw error_already_set(); }
553 static object get(
handle obj,
size_t index) {
554 PyObject *result = PySequence_GetItem(obj.ptr(),
static_cast<ssize_t>(index));
556 return reinterpret_steal<object>(result);
561 if (PySequence_SetItem(obj.ptr(),
static_cast<ssize_t>(index), val.ptr()) != 0) {
570 static object get(
handle obj,
size_t index) {
571 PyObject *result = PyList_GetItem(obj.ptr(),
static_cast<ssize_t>(index));
573 return reinterpret_borrow<object>(result);
578 if (PyList_SetItem(obj.ptr(),
static_cast<ssize_t>(index), val.inc_ref().ptr()) != 0) {
587 static object get(
handle obj,
size_t index) {
588 PyObject *result = PyTuple_GetItem(obj.ptr(),
static_cast<ssize_t>(index));
590 return reinterpret_borrow<object>(result);
595 if (PyTuple_SetItem(obj.ptr(),
static_cast<ssize_t>(index), val.inc_ref().ptr()) != 0) {
602 template <
typename Policy>
643 template <
typename T>
711 PyObject *key =
nullptr, *
value =
nullptr;
716 #if !defined(PYPY_VERSION) 728 PyObject *
iter = PyObject_GetIter(obj);
739 #if PY_MAJOR_VERSION >= 3 740 inline bool PyEllipsis_Check(PyObject *o) {
return o == Py_Ellipsis; }
759 template <
typename T>
using is_keyword = std::is_base_of<arg, T>;
768 template <return_value_policy policy = return_value_policy::automatic_reference>
770 template <return_value_policy policy = return_value_policy::automatic_reference>
779 #define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \ 781 PYBIND11_DEPRECATED("Use reinterpret_borrow<"#Name">() or reinterpret_steal<"#Name">()") \ 782 Name(handle h, bool is_borrowed) : Parent(is_borrowed ? Parent(h, borrowed_t{}) : Parent(h, stolen_t{})) { } \ 783 Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) { } \ 784 Name(handle h, stolen_t) : Parent(h, stolen_t{}) { } \ 785 PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \ 786 bool check() const { return m_ptr != nullptr && (bool) CheckFun(m_ptr); } \ 787 static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } 789 #define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \ 790 PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \ 792 Name(const object &o) \ 793 : Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) \ 794 { if (!m_ptr) throw error_already_set(); } \ 796 : Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) \ 797 { if (!m_ptr) throw error_already_set(); } \ 798 template <typename Policy_> \ 799 Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) { } 801 #define PYBIND11_OBJECT(Name, Parent, CheckFun) \ 802 PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \ 804 Name(const object &o) : Parent(o) { } \ 805 Name(object &&o) : Parent(std::move(o)) { } 807 #define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun) \ 808 PYBIND11_OBJECT(Name, Parent, CheckFun) \ 809 Name() : Parent() { } 844 if (m_ptr && !
value.ptr()) {
845 auto&
self =
const_cast<iterator &
>(*this);
866 static iterator sentinel() {
return {}; }
873 value = reinterpret_steal<object>(PyIter_Next(m_ptr));
892 str(
const char *c,
size_t n)
894 if (!m_ptr) pybind11_fail(
"Could not allocate string object!");
898 str(
const char *c =
"")
900 if (!m_ptr) pybind11_fail(
"Could not allocate string object!");
903 str(
const std::string &s) :
str(s.data(), s.size()) { }
913 operator std::string()
const {
915 if (PyUnicode_Check(m_ptr)) {
916 temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(m_ptr));
918 pybind11_fail(
"Unable to extract string contents! (encoding issue)");
923 pybind11_fail(
"Unable to extract string contents! (invalid type)");
924 return std::string(buffer, (
size_t) length);
927 template <
typename... Args>
929 return attr(
"format")(std::forward<Args>(
args)...);
935 PyObject *str_value = PyObject_Str(op);
936 #if PY_MAJOR_VERSION < 3 938 PyObject *unicode = PyUnicode_FromEncodedObject(str_value,
"utf-8",
nullptr);
939 Py_XDECREF(str_value); str_value = unicode;
946 inline namespace literals {
950 inline str operator"" _s(
const char *s,
size_t size) {
return {s, size}; }
960 bytes(
const char *c =
"")
962 if (!m_ptr) pybind11_fail(
"Could not allocate bytes object!");
965 bytes(
const char *c,
size_t n)
967 if (!m_ptr) pybind11_fail(
"Could not allocate bytes object!");
971 bytes(
const std::string &s) :
bytes(s.data(), s.size()) { }
975 operator std::string()
const {
979 pybind11_fail(
"Unable to extract bytes contents!");
980 return std::string(buffer, (
size_t) length);
986 if (PyUnicode_Check(s.
ptr())) {
987 temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(s.
ptr()));
989 pybind11_fail(
"Unable to extract string contents! (encoding issue)");
994 pybind11_fail(
"Unable to extract string contents! (invalid type)");
997 pybind11_fail(
"Could not allocate bytes object!");
998 m_ptr = obj.release().
ptr();
1005 pybind11_fail(
"Unable to extract bytes contents!");
1006 auto obj = reinterpret_steal<object>(PyUnicode_FromStringAndSize(buffer, (
ssize_t) length));
1008 pybind11_fail(
"Could not allocate string object!");
1009 m_ptr = obj.release().
ptr();
1018 #if PY_MAJOR_VERSION >= 3 1019 class ellipsis :
public object {
1032 operator bool()
const {
return m_ptr && PyLong_AsLong(m_ptr) != 0; }
1036 static PyObject *raw_bool(PyObject *op) {
1037 const auto value = PyObject_IsTrue(op);
1038 if (value == -1)
return nullptr;
1039 return handle(value ? Py_True : Py_False).inc_ref().ptr();
1048 template <
typename Un
signed>
1050 if (
sizeof(Unsigned) <=
sizeof(
unsigned long)
1051 #
if PY_VERSION_HEX < 0x03000000
1055 unsigned long v = PyLong_AsUnsignedLong(o);
1056 return v == (
unsigned long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
1059 unsigned long long v = PyLong_AsUnsignedLongLong(o);
1060 return v == (
unsigned long long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
1070 template <
typename T,
1073 if (
sizeof(T) <=
sizeof(
long)) {
1075 m_ptr = PyLong_FromLong((
long) value);
1077 m_ptr = PyLong_FromUnsignedLong((
unsigned long) value);
1080 m_ptr = PyLong_FromLongLong((
long long) value);
1082 m_ptr = PyLong_FromUnsignedLongLong((
unsigned long long) value);
1084 if (!m_ptr) pybind11_fail(
"Could not allocate int object!");
1087 template <
typename T,
1088 detail::enable_if_t<std::is_integral<T>::value,
int> = 0>
1089 operator T()
const {
1091 ? detail::as_unsigned<T>(m_ptr)
1092 :
sizeof(T) <=
sizeof(long)
1093 ? (T) PyLong_AsLong(m_ptr)
1103 if (!m_ptr) pybind11_fail(
"Could not allocate float object!");
1106 if (!m_ptr) pybind11_fail(
"Could not allocate float object!");
1108 operator float()
const {
return (
float) PyFloat_AsDouble(m_ptr); }
1109 operator double()
const {
return (
double) PyFloat_AsDouble(m_ptr); }
1116 :
object(PyWeakref_NewRef(obj.
ptr(), callback.ptr()),
stolen_t{}) {
1117 if (!m_ptr) pybind11_fail(
"Could not allocate weak reference!");
1125 int_ start(start_), stop(stop_), step(step_);
1126 m_ptr = PySlice_New(start.ptr(), stop.ptr(), step.
ptr());
1127 if (!m_ptr) pybind11_fail(
"Could not allocate slice object!");
1129 bool compute(
size_t length,
size_t *start,
size_t *stop,
size_t *step,
1130 size_t *slicelength)
const {
1134 (
ssize_t *) slicelength) == 0;
1149 capsule(PyObject *ptr,
bool is_borrowed) :
object(is_borrowed ?
object(ptr,
borrowed_t{}) :
object(ptr,
stolen_t{})) { }
1151 explicit capsule(
const void *
value,
const char *
name =
nullptr,
void (*destructor)(PyObject *) =
nullptr)
1154 pybind11_fail(
"Could not allocate capsule object!");
1158 capsule(
const void *value,
void (*destruct)(PyObject *))
1159 :
object(PyCapsule_New(const_cast<void*>(value),
nullptr, destruct),
stolen_t{}) {
1161 pybind11_fail(
"Could not allocate capsule object!");
1164 capsule(
const void *value,
void (*destructor)(
void *)) {
1165 m_ptr = PyCapsule_New(const_cast<void *>(value),
nullptr, [](PyObject *o) {
1166 auto destructor =
reinterpret_cast<void (*)(
void *)
>(PyCapsule_GetContext(o));
1167 void *ptr = PyCapsule_GetPointer(o,
nullptr);
1172 pybind11_fail(
"Could not allocate capsule object!");
1174 if (PyCapsule_SetContext(m_ptr, (
void *) destructor) != 0)
1175 pybind11_fail(
"Could not set capsule context!");
1178 capsule(
void (*destructor)()) {
1179 m_ptr = PyCapsule_New(reinterpret_cast<void *>(destructor),
nullptr, [](PyObject *o) {
1180 auto destructor =
reinterpret_cast<void (*)()
>(PyCapsule_GetPointer(o,
nullptr));
1185 pybind11_fail(
"Could not allocate capsule object!");
1188 template <
typename T>
operator T *()
const {
1190 T * result =
static_cast<T *
>(PyCapsule_GetPointer(m_ptr,
name));
1191 if (!result) pybind11_fail(
"Unable to extract capsule contents!");
1195 const char *
name()
const {
return PyCapsule_GetName(m_ptr); }
1202 if (!m_ptr) pybind11_fail(
"Could not allocate tuple object!");
1204 size_t size()
const {
return (
size_t) PyTuple_Size(m_ptr); }
1205 bool empty()
const {
return size() == 0; }
1216 if (!m_ptr) pybind11_fail(
"Could not allocate dict object!");
1218 template <
typename... Args,
1224 size_t size()
const {
return (
size_t) PyDict_Size(m_ptr); }
1228 void clear()
const { PyDict_Clear(ptr()); }
1229 template <
typename T>
bool contains(T &&key)
const {
1235 static PyObject *raw_dict(PyObject *op) {
1236 if (PyDict_Check(op))
1237 return handle(op).inc_ref().ptr();
1238 return PyObject_CallFunctionObjArgs((PyObject *) &PyDict_Type, op,
nullptr);
1245 size_t size()
const {
return (
size_t) PySequence_Size(m_ptr); }
1246 bool empty()
const {
return size() == 0; }
1257 if (!m_ptr) pybind11_fail(
"Could not allocate list object!");
1259 size_t size()
const {
return (
size_t) PyList_Size(m_ptr); }
1260 bool empty()
const {
return size() == 0; }
1265 template <
typename T>
void append(T &&val)
const {
1268 template <
typename T>
void insert(
size_t index, T &&val)
const {
1269 PyList_Insert(m_ptr, static_cast<ssize_t>(index),
1280 set() :
object(PySet_New(
nullptr),
stolen_t{}) {
1281 if (!m_ptr) pybind11_fail(
"Could not allocate set object!");
1283 size_t size()
const {
return (
size_t) PySet_Size(m_ptr); }
1284 bool empty()
const {
return size() == 0; }
1285 template <
typename T>
bool add(T &&val)
const {
1288 void clear()
const { PySet_Clear(m_ptr); }
1289 template <
typename T>
bool contains(T &&val)
const {
1299 if (fun && PyCFunction_Check(fun.
ptr()))
1303 bool is_cpp_function()
const {
return (
bool)
cpp_function(); }
1315 buffer_info request(
bool writable =
false)
const {
1316 int flags = PyBUF_STRIDES | PyBUF_FORMAT;
1317 if (writable) flags |= PyBUF_WRITABLE;
1318 Py_buffer *view =
new Py_buffer();
1319 if (PyObject_GetBuffer(m_ptr, view, flags) != 0) {
1330 static Py_buffer buf { };
1332 static std::vector<Py_ssize_t> py_strides { };
1333 static std::vector<Py_ssize_t> py_shape { };
1336 buf.format =
const_cast<char *
>(info.
format.c_str());
1337 buf.ndim = (int) info.
ndim;
1338 buf.len = info.
size;
1342 py_strides.push_back(info.
strides[
i]);
1343 py_shape.push_back(info.
shape[
i]);
1345 buf.strides = py_strides.data();
1346 buf.shape = py_shape.data();
1347 buf.suboffsets =
nullptr;
1348 buf.readonly =
false;
1349 buf.internal =
nullptr;
1351 m_ptr = PyMemoryView_FromBuffer(&buf);
1353 pybind11_fail(
"Unable to create memoryview from buffer descriptor");
1365 pybind11_fail(
"Unable to compute length of object");
1366 return (
size_t) result;
1370 #if PY_VERSION_HEX >= 0x03040000 1371 ssize_t result = PyObject_LengthHint(h.
ptr(), 0);
1381 return (
size_t) result;
1385 PyObject *str_value = PyObject_Repr(h.
ptr());
1387 #if PY_MAJOR_VERSION < 3 1388 PyObject *unicode = PyUnicode_FromEncodedObject(str_value,
"utf-8",
nullptr);
1389 Py_XDECREF(str_value); str_value = unicode;
1392 return reinterpret_steal<str>(str_value);
1396 PyObject *result = PyObject_GetIter(obj.
ptr());
1398 return reinterpret_steal<iterator>(result);
1406 return {derived(), reinterpret_borrow<object>(key)};
1412 return {derived(), reinterpret_borrow<object>(key)};
1415 return {derived(), key};
1421 return attr(
"__contains__")(std::forward<T>(item)).template cast<bool>();
1424 template <
typename D>
1427 template <
typename D>
1430 template <
typename D>
1433 template <
typename D>
1435 int rv = PyObject_RichCompareBool(derived().ptr(), other.
derived().ptr(),
value);
1441 #define PYBIND11_MATH_OPERATOR_UNARY(op, fn) \ 1442 template <typename D> object object_api<D>::op() const { \ 1443 object result = reinterpret_steal<object>(fn(derived().ptr())); \ 1444 if (!result.ptr()) \ 1445 throw error_already_set(); \ 1449 #define PYBIND11_MATH_OPERATOR_BINARY(op, fn) \ 1450 template <typename D> \ 1451 object object_api<D>::op(object_api const &other) const { \ 1452 object result = reinterpret_steal<object>( \ 1453 fn(derived().ptr(), other.derived().ptr())); \ 1454 if (!result.ptr()) \ 1455 throw error_already_set(); \ 1480 #undef PYBIND11_MATH_OPERATOR_UNARY 1481 #undef PYBIND11_MATH_OPERATOR_BINARY bool isinstance< handle >(handle obj)=delete
op_< op_invert, op_u, self_t, undefined_t > operator~(const self_t &)
friend It operator-(const It &a, difference_type n)
kwargs_proxy operator*() const
bool is(object_api const &other) const
Equivalent to obj is other in Python.
op_< op_float, op_u, self_t, undefined_t > float_(const self_t &)
friend bool operator<=(const It &a, const It &b)
op_< op_ixor, op_l, self_t, T > operator^=(const self_t &, const T &)
std::random_access_iterator_tag iterator_category
op_< op_xor, op_l, self_t, self_t > operator^(const self_t &, const self_t &)
T reinterpret_steal(handle h)
object getattr(handle obj, const char *name, handle default_)
Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object.
constexpr bool operator!=(const day &x, const day &y) noexcept
#define PYBIND11_SLICE_OBJECT
object(handle h, stolen_t)
#define PYBIND11_NAMESPACE
bool contains(T &&item) const
Check if the given item is contained within this object, i.e. item in obj.
op_< op_or, op_l, self_t, self_t > operator|(const self_t &, const self_t &)
PyObject * ptr() const
Return the underlying PyObject * pointer.
bool isinstance< object >(handle obj)
constexpr day operator-(const day &x, const days &y) noexcept
typename Policy::reference reference
Quick proxy class needed to implement operator-> for iterators which can't return pointers...
Helper class which collects positional, keyword, * and ** arguments for a Python function call...
const object & value() const
std::is_base_of< pyobject_tag, remove_reference_t< T > > is_pyobject
std::string error_string()
op_< op_irshift, op_l, self_t, T > operator>>=(const self_t &, const T &)
typename Policy::iterator_category iterator_category
bool operator>(object_api const &other) const
~object()
Destructor; automatically calls handle::dec_ref()
int ref_count() const
Return the object's current reference count.
bool hasattr(handle obj, const char *name)
reference operator*() const
bool equal(object_api const &other) const
Equivalent to obj == other in Python.
dict_readonly(handle obj, ssize_t pos)
Tag and check to identify a class which implements the Python object API.
ssize_t distance_to(const sequence_slow_readwrite &b) const
op_< op_mul, op_l, self_t, self_t > operator*(const self_t &, const self_t &)
typename Policy::value_type value_type
std::vector< ssize_t > strides
op_< op_ilshift, op_l, self_t, T > operator<<=(const self_t &, const T &)
accessor< accessor_policies::sequence_item > sequence_accessor
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun)
std::pair< handle, handle > value_type
Information record describing a Python buffer object.
std::vector< ssize_t > shape
const handle & dec_ref() const &
It & operator-=(difference_type n)
constexpr bool operator>(const day &x, const day &y) noexcept
object(handle h, borrowed_t)
object & operator=(const object &other)
bool PyUnicode_Check_Permissive(PyObject *o)
op_< op_isub, op_l, self_t, T > operator-=(const self_t &, const T &)
bool is_none() const
Equivalent to obj is None in Python.
typename deferred_type< T, Us... >::type deferred_t
bool isinstance_generic(handle obj, const std::type_info &tp)
op_< op_int, op_u, self_t, undefined_t > int_(const self_t &)
op_< op_iadd, op_l, self_t, T > operator+=(const self_t &, const T &)
friend bool operator>=(const It &a, const It &b)
std::is_same< args_proxy, T > is_s_unpacking
bool isinstance(handle obj, handle type)
#define NAMESPACE_END(name)
const Derived & derived() const
__attribute__((deprecated("Use of obj.attr(...) as bool is deprecated in favor of pybind11::hasattr(obj, ...)"))) explicit operator enable_if_t< std key_type key
op_< op_ior, op_l, self_t, T > operator|=(const self_t &, const T &)
static PyObject * raw_str(PyObject *op)
Return string representation – always returns a new reference, even if already a str...
handle(PyObject *ptr)
Creates a handle from the given raw Python object pointer.
void operator=(const accessor &a) &&
bool operator<=(object_api const &other) const
void delattr(handle obj, const char *name)
#define PYBIND11_LONG_CHECK(o)
accessor(handle obj, key_type key)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
void setattr(handle obj, const char *name, handle value)
#define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun)
bool PyIterable_Check(PyObject *obj)
typename Policy::pointer pointer
op_< op_itruediv, op_l, self_t, T > operator/=(const self_t &, const T &)
size_t function_call & call
sequence_slow_readwrite(handle obj, ssize_t index)
object & operator=(object &&other) noexcept
std::forward_iterator_tag iterator_category
bool PyNone_Check(PyObject *o)
#define PYBIND11_BYTES_FROM_STRING
generic_iterator(handle seq, ssize_t index)
std::istream & operator>>(std::istream &in, T &item)
input streaming for enumerations
typename Policy::key_type key_type
constexpr year_month operator/(const year &y, const month &m) noexcept
bool equal(const sequence_slow_readwrite &b) const
sequence_fast_readonly(handle obj, ssize_t n)
size_t len_hint(handle h)
std::ostream & operator<<(std::ostream &in, const T &item)
output streaming for enumerations
#define PYBIND11_BYTES_AS_STRING_AND_SIZE
str format(Args &&...args) const
Python's dictionary protocol permits this to be a forward iterator.
const std::type_info & tp
reference dereference() const
#define PYBIND11_BYTES_CHECK
handle object_or_cast(PyObject *ptr)
bool equal(const dict_readonly &b) const
ssize_t distance_to(const sequence_fast_readonly &b) const
Full read and write access using the sequence protocol: see detail::sequence_accessor ...
const value_type reference
reference operator[](difference_type n) const
op_< op_and, op_l, self_t, self_t > operator &(const self_t &, const self_t &)
reference dereference() const
std::is_same< kwargs_proxy, T > is_ds_unpacking
bool PyStaticMethod_Check(PyObject *o)
bool operator==(const NonZeroIterator< std::pair< A, B >> &it, const NonZeroSentinel &)
const detail::type_info * type
Annotation for function names.
bool operator>=(object_api const &other) const
constexpr day operator+(const day &x, const days &y) noexcept
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
op_< op_imul, op_l, self_t, T > operator*=(const self_t &, const T &)
std::is_base_of< arg, T > is_keyword
Python argument categories (using PEP 448 terms)
handle get_function(handle value)
bool matches(handle exc) const
friend bool operator==(const It &a, const It &b)
void operator=(T &&value) &&
#define PYBIND11_MATH_OPERATOR_BINARY(op, fn)
const object & trace() const
#define PYBIND11_MATH_OPERATOR_UNARY(op, fn)
#define PYBIND11_DEPRECATED(reason)
T reinterpret_borrow(handle h)
It & operator+=(difference_type n)
object(const object &o)
Copy constructor; always increases the reference count.
Lightweight iterator policy using just a simple pointer: see PySequence_Fast_ITEMS ...
op_< op_iand, op_l, self_t, T > operator &=(const self_t &, const T &)
std::random_access_iterator_tag iterator_category
#define NAMESPACE_BEGIN(name)
friend It operator+(difference_type n, const It &b)
iterator iter(handle obj)
void operator=(const accessor &a) &
friend It operator+(const It &a, difference_type n)
STL iterator template used for tuple, list, sequence and dict.
constexpr bool operator<(const day &x, const day &y) noexcept
T cast(const handle &handle)
friend difference_type operator-(const It &a, const It &b)
bool equal(const sequence_fast_readonly &b) const
reference dereference() const
const object & type() const
object(object &&other) noexcept
Move constructor; steals the object from other and preserves its reference count. ...
Unsigned as_unsigned(PyObject *o)
bool not_equal(object_api const &other) const
std::input_iterator_tag iterator_category
bool operator<(object_api const &other) const
#define PYBIND11_BYTES_FROM_STRING_AND_SIZE
void operator=(T &&value) &
#define PYBIND11_OBJECT(Name, Parent, CheckFun)
pointer operator->() const
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
const handle & inc_ref() const &
friend bool operator!=(const It &a, const It &b)
#define PYBIND11_LONG_AS_LONGLONG(o)