cppyabm  1.0.17
An agent-based library to integrate C++ and Python
common.h
Go to the documentation of this file.
1 /*
2  pybind11/detail/common.h -- Basic macros
3 
4  Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5 
6  All rights reserved. Use of this source code is governed by a
7  BSD-style license that can be found in the LICENSE file.
8 */
9 
10 #pragma once
11 
12 #define PYBIND11_VERSION_MAJOR 2
13 #define PYBIND11_VERSION_MINOR 6
14 #define PYBIND11_VERSION_PATCH 3.dev1
15 
16 #define PYBIND11_NAMESPACE_BEGIN(name) namespace name {
17 #define PYBIND11_NAMESPACE_END(name) }
18 
19 // Robust support for some features and loading modules compiled against different pybind versions
20 // requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute on
21 // the main `pybind11` namespace.
22 #if !defined(PYBIND11_NAMESPACE)
23 # ifdef __GNUG__
24 # define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden")))
25 # else
26 # define PYBIND11_NAMESPACE pybind11
27 # endif
28 #endif
29 
30 #if !(defined(_MSC_VER) && __cplusplus == 199711L)
31 # if __cplusplus >= 201402L
32 # define PYBIND11_CPP14
33 # if __cplusplus >= 201703L
34 # define PYBIND11_CPP17
35 # endif
36 # endif
37 #elif defined(_MSC_VER) && __cplusplus == 199711L
38 // MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented)
39 // Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer
40 # if _MSVC_LANG >= 201402L
41 # define PYBIND11_CPP14
42 # if _MSVC_LANG > 201402L && _MSC_VER >= 1910
43 # define PYBIND11_CPP17
44 # endif
45 # endif
46 #endif
47 
48 // Compiler version assertions
49 #if defined(__INTEL_COMPILER)
50 # if __INTEL_COMPILER < 1800
51 # error pybind11 requires Intel C++ compiler v18 or newer
52 # elif __INTEL_COMPILER < 1900 && defined(PYBIND11_CPP14)
53 # error pybind11 supports only C++11 with Intel C++ compiler v18. Use v19 or newer for C++14.
54 # endif
55 #elif defined(__clang__) && !defined(__apple_build_version__)
56 # if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3)
57 # error pybind11 requires clang 3.3 or newer
58 # endif
59 #elif defined(__clang__)
60 // Apple changes clang version macros to its Xcode version; the first Xcode release based on
61 // (upstream) clang 3.3 was Xcode 5:
62 # if __clang_major__ < 5
63 # error pybind11 requires Xcode/clang 5.0 or newer
64 # endif
65 #elif defined(__GNUG__)
66 # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
67 # error pybind11 requires gcc 4.8 or newer
68 # endif
69 #elif defined(_MSC_VER)
70 // Pybind hits various compiler bugs in 2015u2 and earlier, and also makes use of some stl features
71 // (e.g. std::negation) added in 2015u3:
72 # if _MSC_FULL_VER < 190024210
73 # error pybind11 requires MSVC 2015 update 3 or newer
74 # endif
75 #endif
76 
77 #if !defined(PYBIND11_EXPORT)
78 # if defined(WIN32) || defined(_WIN32)
79 # define PYBIND11_EXPORT __declspec(dllexport)
80 # else
81 # define PYBIND11_EXPORT __attribute__ ((visibility("default")))
82 # endif
83 #endif
84 
85 #if defined(_MSC_VER)
86 # define PYBIND11_NOINLINE __declspec(noinline)
87 #else
88 # define PYBIND11_NOINLINE __attribute__ ((noinline))
89 #endif
90 
91 #if defined(PYBIND11_CPP14)
92 # define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]]
93 #else
94 # define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
95 #endif
96 
97 #if defined(PYBIND11_CPP17)
98 # define PYBIND11_MAYBE_UNUSED [[maybe_unused]]
99 #elif defined(_MSC_VER) && !defined(__clang__)
100 # define PYBIND11_MAYBE_UNUSED
101 #else
102 # define PYBIND11_MAYBE_UNUSED __attribute__ ((__unused__))
103 #endif
104 
105 /* Don't let Python.h #define (v)snprintf as macro because they are implemented
106  properly in Visual Studio since 2015. */
107 #if defined(_MSC_VER) && _MSC_VER >= 1900
108 # define HAVE_SNPRINTF 1
109 #endif
110 
111 /// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
112 #if defined(_MSC_VER)
113 # if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4)
114 # define HAVE_ROUND 1
115 # endif
116 # pragma warning(push)
117 # pragma warning(disable: 4510 4610 4512 4005)
118 # if defined(_DEBUG) && !defined(Py_DEBUG)
119 # define PYBIND11_DEBUG_MARKER
120 # undef _DEBUG
121 # endif
122 #endif
123 
124 #include <Python.h>
125 #include <frameobject.h>
126 #include <pythread.h>
127 
128 /* Python #defines overrides on all sorts of core functions, which
129  tends to weak havok in C++ codebases that expect these to work
130  like regular functions (potentially with several overloads) */
131 #if defined(isalnum)
132 # undef isalnum
133 # undef isalpha
134 # undef islower
135 # undef isspace
136 # undef isupper
137 # undef tolower
138 # undef toupper
139 #endif
140 
141 #if defined(copysign)
142 # undef copysign
143 #endif
144 
145 #if defined(_MSC_VER)
146 # if defined(PYBIND11_DEBUG_MARKER)
147 # define _DEBUG
148 # undef PYBIND11_DEBUG_MARKER
149 # endif
150 # pragma warning(pop)
151 #endif
152 
153 #include <cstddef>
154 #include <cstring>
155 #include <forward_list>
156 #include <vector>
157 #include <string>
158 #include <stdexcept>
159 #include <exception>
160 #include <unordered_set>
161 #include <unordered_map>
162 #include <memory>
163 #include <typeindex>
164 #include <type_traits>
165 #if defined(__has_include)
166 # if __has_include(<version>)
167 # include <version>
168 # endif
169 #endif
170 
171 // #define PYBIND11_STR_LEGACY_PERMISSIVE
172 // If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject
173 // (probably surprising and never documented, but this was the
174 // legacy behavior until and including v2.6.x). As a side-effect,
175 // pybind11::isinstance<str>() is true for both pybind11::str and
176 // pybind11::bytes.
177 // If UNDEFINED, pybind11::str can only hold PyUnicodeObject, and
178 // pybind11::isinstance<str>() is true only for pybind11::str.
179 // However, for Python 2 only (!), the pybind11::str caster
180 // implicitly decodes bytes to PyUnicodeObject. This is to ease
181 // the transition from the legacy behavior to the non-permissive
182 // behavior.
183 
184 #if PY_MAJOR_VERSION >= 3 /// Compatibility macros for various Python versions
185 #define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr)
186 #define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check
187 #define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION
188 #define PYBIND11_BYTES_CHECK PyBytes_Check
189 #define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
190 #define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize
191 #define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize
192 #define PYBIND11_BYTES_AS_STRING PyBytes_AsString
193 #define PYBIND11_BYTES_SIZE PyBytes_Size
194 #define PYBIND11_LONG_CHECK(o) PyLong_Check(o)
195 #define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o)
196 #define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) o)
197 #define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) o)
198 #define PYBIND11_BYTES_NAME "bytes"
199 #define PYBIND11_STRING_NAME "str"
200 #define PYBIND11_SLICE_OBJECT PyObject
201 #define PYBIND11_FROM_STRING PyUnicode_FromString
202 #define PYBIND11_STR_TYPE ::pybind11::str
203 #define PYBIND11_BOOL_ATTR "__bool__"
204 #define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool)
205 #define PYBIND11_BUILTINS_MODULE "builtins"
206 // Providing a separate declaration to make Clang's -Wmissing-prototypes happy.
207 // See comment for PYBIND11_MODULE below for why this is marked "maybe unused".
208 #define PYBIND11_PLUGIN_IMPL(name) \
209  extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT PyObject *PyInit_##name(); \
210  extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()
211 
212 #else
213 #define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyMethod_New(ptr, nullptr, class_)
214 #define PYBIND11_INSTANCE_METHOD_CHECK PyMethod_Check
215 #define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyMethod_GET_FUNCTION
216 #define PYBIND11_BYTES_CHECK PyString_Check
217 #define PYBIND11_BYTES_FROM_STRING PyString_FromString
218 #define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyString_FromStringAndSize
219 #define PYBIND11_BYTES_AS_STRING_AND_SIZE PyString_AsStringAndSize
220 #define PYBIND11_BYTES_AS_STRING PyString_AsString
221 #define PYBIND11_BYTES_SIZE PyString_Size
222 #define PYBIND11_LONG_CHECK(o) (PyInt_Check(o) || PyLong_Check(o))
223 #define PYBIND11_LONG_AS_LONGLONG(o) (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o))
224 #define PYBIND11_LONG_FROM_SIGNED(o) PyInt_FromSsize_t((ssize_t) o) // Returns long if needed.
225 #define PYBIND11_LONG_FROM_UNSIGNED(o) PyInt_FromSize_t((size_t) o) // Returns long if needed.
226 #define PYBIND11_BYTES_NAME "str"
227 #define PYBIND11_STRING_NAME "unicode"
228 #define PYBIND11_SLICE_OBJECT PySliceObject
229 #define PYBIND11_FROM_STRING PyString_FromString
230 #define PYBIND11_STR_TYPE ::pybind11::bytes
231 #define PYBIND11_BOOL_ATTR "__nonzero__"
232 #define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_nonzero)
233 #define PYBIND11_BUILTINS_MODULE "__builtin__"
234 // Providing a separate PyInit decl to make Clang's -Wmissing-prototypes happy.
235 // See comment for PYBIND11_MODULE below for why this is marked "maybe unused".
236 #define PYBIND11_PLUGIN_IMPL(name) \
237  static PyObject *pybind11_init_wrapper(); \
238  extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT void init##name(); \
239  extern "C" PYBIND11_EXPORT void init##name() { \
240  (void)pybind11_init_wrapper(); \
241  } \
242  PyObject *pybind11_init_wrapper()
243 #endif
244 
245 #if PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03050200
246 extern "C" {
247  struct _Py_atomic_address { void *value; };
248  PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current;
249 }
250 #endif
251 
252 #define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code
253 #define PYBIND11_STRINGIFY(x) #x
254 #define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
255 #define PYBIND11_CONCAT(first, second) first##second
256 #define PYBIND11_ENSURE_INTERNALS_READY \
257  pybind11::detail::get_internals();
258 
259 #define PYBIND11_CHECK_PYTHON_VERSION \
260  { \
261  const char *compiled_ver = PYBIND11_TOSTRING(PY_MAJOR_VERSION) \
262  "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \
263  const char *runtime_ver = Py_GetVersion(); \
264  size_t len = std::strlen(compiled_ver); \
265  if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \
266  || (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \
267  PyErr_Format(PyExc_ImportError, \
268  "Python version mismatch: module was compiled for Python %s, " \
269  "but the interpreter version is incompatible: %s.", \
270  compiled_ver, runtime_ver); \
271  return nullptr; \
272  } \
273  }
274 
275 #define PYBIND11_CATCH_INIT_EXCEPTIONS \
276  catch (pybind11::error_already_set &e) { \
277  PyErr_SetString(PyExc_ImportError, e.what()); \
278  return nullptr; \
279  } catch (const std::exception &e) { \
280  PyErr_SetString(PyExc_ImportError, e.what()); \
281  return nullptr; \
282  } \
283 
284 /** \rst
285  ***Deprecated in favor of PYBIND11_MODULE***
286 
287  This macro creates the entry point that will be invoked when the Python interpreter
288  imports a plugin library. Please create a `module_` in the function body and return
289  the pointer to its underlying Python object at the end.
290 
291  .. code-block:: cpp
292 
293  PYBIND11_PLUGIN(example) {
294  pybind11::module_ m("example", "pybind11 example plugin");
295  /// Set up bindings here
296  return m.ptr();
297  }
298 \endrst */
299 #define PYBIND11_PLUGIN(name) \
300  PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
301  static PyObject *pybind11_init(); \
302  PYBIND11_PLUGIN_IMPL(name) { \
303  PYBIND11_CHECK_PYTHON_VERSION \
304  PYBIND11_ENSURE_INTERNALS_READY \
305  try { \
306  return pybind11_init(); \
307  } PYBIND11_CATCH_INIT_EXCEPTIONS \
308  } \
309  PyObject *pybind11_init()
310 
311 /** \rst
312  This macro creates the entry point that will be invoked when the Python interpreter
313  imports an extension module. The module name is given as the fist argument and it
314  should not be in quotes. The second macro argument defines a variable of type
315  `py::module_` which can be used to initialize the module.
316 
317  The entry point is marked as "maybe unused" to aid dead-code detection analysis:
318  since the entry point is typically only looked up at runtime and not referenced
319  during translation, it would otherwise appear as unused ("dead") code.
320 
321  .. code-block:: cpp
322 
323  PYBIND11_MODULE(example, m) {
324  m.doc() = "pybind11 example module";
325 
326  // Add bindings here
327  m.def("foo", []() {
328  return "Hello, World!";
329  });
330  }
331 \endrst */
332 #define PYBIND11_MODULE(name, variable) \
333  static ::pybind11::module_::module_def \
334  PYBIND11_CONCAT(pybind11_module_def_, name) PYBIND11_MAYBE_UNUSED; \
335  PYBIND11_MAYBE_UNUSED \
336  static void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &); \
337  PYBIND11_PLUGIN_IMPL(name) { \
338  PYBIND11_CHECK_PYTHON_VERSION \
339  PYBIND11_ENSURE_INTERNALS_READY \
340  auto m = ::pybind11::module_::create_extension_module( \
341  PYBIND11_TOSTRING(name), nullptr, \
342  &PYBIND11_CONCAT(pybind11_module_def_, name)); \
343  try { \
344  PYBIND11_CONCAT(pybind11_init_, name)(m); \
345  return m.ptr(); \
346  } PYBIND11_CATCH_INIT_EXCEPTIONS \
347  } \
348  void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &variable)
349 
350 
352 
353 using ssize_t = Py_ssize_t;
354 using size_t = std::size_t;
355 
356 /// Approach used to cast a previously unknown C++ instance into a Python object
357 enum class return_value_policy : uint8_t {
358  /** This is the default return value policy, which falls back to the policy
359  return_value_policy::take_ownership when the return value is a pointer.
360  Otherwise, it uses return_value::move or return_value::copy for rvalue
361  and lvalue references, respectively. See below for a description of what
362  all of these different policies do. */
363  automatic = 0,
364 
365  /** As above, but use policy return_value_policy::reference when the return
366  value is a pointer. This is the default conversion policy for function
367  arguments when calling Python functions manually from C++ code (i.e. via
368  handle::operator()). You probably won't need to use this. */
369  automatic_reference,
370 
371  /** Reference an existing object (i.e. do not create a new copy) and take
372  ownership. Python will call the destructor and delete operator when the
373  object’s reference count reaches zero. Undefined behavior ensues when
374  the C++ side does the same.. */
375  take_ownership,
376 
377  /** Create a new copy of the returned object, which will be owned by
378  Python. This policy is comparably safe because the lifetimes of the two
379  instances are decoupled. */
380  copy,
381 
382  /** Use std::move to move the return value contents into a new instance
383  that will be owned by Python. This policy is comparably safe because the
384  lifetimes of the two instances (move source and destination) are
385  decoupled. */
386  move,
387 
388  /** Reference an existing object, but do not take ownership. The C++ side
389  is responsible for managing the object’s lifetime and deallocating it
390  when it is no longer used. Warning: undefined behavior will ensue when
391  the C++ side deletes an object that is still referenced and used by
392  Python. */
393  reference,
394 
395  /** This policy only applies to methods and properties. It references the
396  object without taking ownership similar to the above
397  return_value_policy::reference policy. In contrast to that policy, the
398  function or property’s implicit this argument (called the parent) is
399  considered to be the the owner of the return value (the child).
400  pybind11 then couples the lifetime of the parent to the child via a
401  reference relationship that ensures that the parent cannot be garbage
402  collected while Python is still using the child. More advanced
403  variations of this scheme are also possible using combinations of
404  return_value_policy::reference and the keep_alive call policy */
406 };
407 
409 
410 inline static constexpr int log2(size_t n, int k = 0) { return (n <= 1) ? k : log2(n >> 1, k + 1); }
411 
412 // Returns the size as a multiple of sizeof(void *), rounded up.
413 inline static constexpr size_t size_in_ptrs(size_t s) { return 1 + ((s - 1) >> log2(sizeof(void *))); }
414 
415 /**
416  * The space to allocate for simple layout instance holders (see below) in multiple of the size of
417  * a pointer (e.g. 2 means 16 bytes on 64-bit architectures). The default is the minimum required
418  * to holder either a std::unique_ptr or std::shared_ptr (which is almost always
419  * sizeof(std::shared_ptr<T>)).
420  */
421 constexpr size_t instance_simple_holder_in_ptrs() {
422  static_assert(sizeof(std::shared_ptr<int>) >= sizeof(std::unique_ptr<int>),
423  "pybind assumes std::shared_ptrs are at least as big as std::unique_ptrs");
424  return size_in_ptrs(sizeof(std::shared_ptr<int>));
425 }
426 
427 // Forward declarations
428 struct type_info;
429 struct value_and_holder;
430 
433  uint8_t *status;
434 };
435 
436 /// The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
437 struct instance {
438  PyObject_HEAD
439  /// Storage for pointers and holder; see simple_layout, below, for a description
440  union {
443  };
444  /// Weak references
445  PyObject *weakrefs;
446  /// If true, the pointer is owned which means we're free to manage it with a holder.
447  bool owned : 1;
448  /**
449  * An instance has two possible value/holder layouts.
450  *
451  * Simple layout (when this flag is true), means the `simple_value_holder` is set with a pointer
452  * and the holder object governing that pointer, i.e. [val1*][holder]. This layout is applied
453  * whenever there is no python-side multiple inheritance of bound C++ types *and* the type's
454  * holder will fit in the default space (which is large enough to hold either a std::unique_ptr
455  * or std::shared_ptr).
456  *
457  * Non-simple layout applies when using custom holders that require more space than `shared_ptr`
458  * (which is typically the size of two pointers), or when multiple inheritance is used on the
459  * python side. Non-simple layout allocates the required amount of memory to have multiple
460  * bound C++ classes as parents. Under this layout, `nonsimple.values_and_holders` is set to a
461  * pointer to allocated space of the required space to hold a sequence of value pointers and
462  * holders followed `status`, a set of bit flags (1 byte each), i.e.
463  * [val1*][holder1][val2*][holder2]...[bb...] where each [block] is rounded up to a multiple of
464  * `sizeof(void *)`. `nonsimple.status` is, for convenience, a pointer to the
465  * beginning of the [bb...] block (but not independently allocated).
466  *
467  * Status bits indicate whether the associated holder is constructed (&
468  * status_holder_constructed) and whether the value pointer is registered (&
469  * status_instance_registered) in `registered_instances`.
470  */
471  bool simple_layout : 1;
472  /// For simple layout, tracks whether the holder has been constructed
474  /// For simple layout, tracks whether the instance is registered in `registered_instances`
476  /// If true, get_internals().patients has an entry for this object
477  bool has_patients : 1;
478 
479  /// Initializes all of the above type/values/holders data (but not the instance values themselves)
480  void allocate_layout();
481 
482  /// Destroys/deallocates all of the above
483  void deallocate_layout();
484 
485  /// Returns the value_and_holder wrapper for the given type (or the first, if `find_type`
486  /// omitted). Returns a default-constructed (with `.inst = nullptr`) object on failure if
487  /// `throw_if_missing` is false.
488  value_and_holder get_value_and_holder(const type_info *find_type = nullptr, bool throw_if_missing = true);
489 
490  /// Bit values for the non-simple status flags
491  static constexpr uint8_t status_holder_constructed = 1;
492  static constexpr uint8_t status_instance_registered = 2;
493 };
494 
495 static_assert(std::is_standard_layout<instance>::value, "Internal error: `pybind11::detail::instance` is not standard layout!");
496 
497 /// from __cpp_future__ import (convenient aliases from C++14/17)
498 #if defined(PYBIND11_CPP14) && (!defined(_MSC_VER) || _MSC_VER >= 1910)
499 using std::enable_if_t;
500 using std::conditional_t;
501 using std::remove_cv_t;
503 #else
504 template <bool B, typename T = void> using enable_if_t = typename std::enable_if<B, T>::type;
505 template <bool B, typename T, typename F> using conditional_t = typename std::conditional<B, T, F>::type;
506 template <typename T> using remove_cv_t = typename std::remove_cv<T>::type;
507 template <typename T> using remove_reference_t = typename std::remove_reference<T>::type;
508 #endif
509 
510 /// Index sequences
511 #if defined(PYBIND11_CPP14)
512 using std::index_sequence;
514 #else
515 template<size_t ...> struct index_sequence { };
516 template<size_t N, size_t ...S> struct make_index_sequence_impl : make_index_sequence_impl <N - 1, N - 1, S...> { };
517 template<size_t ...S> struct make_index_sequence_impl <0, S...> { using type = index_sequence<S...>; };
518 template<size_t N> using make_index_sequence = typename make_index_sequence_impl<N>::type;
519 #endif
520 
521 /// Make an index sequence of the indices of true arguments
522 template <typename ISeq, size_t, bool...> struct select_indices_impl { using type = ISeq; };
523 template <size_t... IPrev, size_t I, bool B, bool... Bs> struct select_indices_impl<index_sequence<IPrev...>, I, B, Bs...>
524  : select_indices_impl<conditional_t<B, index_sequence<IPrev..., I>, index_sequence<IPrev...>>, I + 1, Bs...> {};
525 template <bool... Bs> using select_indices = typename select_indices_impl<index_sequence<>, 0, Bs...>::type;
526 
527 /// Backports of std::bool_constant and std::negation to accommodate older compilers
528 template <bool B> using bool_constant = std::integral_constant<bool, B>;
529 template <typename T> struct negation : bool_constant<!T::value> { };
530 
531 // PGI/Intel cannot detect operator delete with the "compatible" void_t impl, so
532 // using the new one (C++14 defect, so generally works on newer compilers, even
533 // if not in C++17 mode)
534 #if defined(__PGIC__) || defined(__INTEL_COMPILER)
535 template<typename... > using void_t = void;
536 #else
537 template <typename...> struct void_t_impl { using type = void; };
538 template <typename... Ts> using void_t = typename void_t_impl<Ts...>::type;
539 #endif
540 
541 
542 /// Compile-time all/any/none of that check the boolean value of all template types
543 #if defined(__cpp_fold_expressions) && !(defined(_MSC_VER) && (_MSC_VER < 1916))
544 template <class... Ts> using all_of = bool_constant<(Ts::value && ...)>;
545 template <class... Ts> using any_of = bool_constant<(Ts::value || ...)>;
546 #elif !defined(_MSC_VER)
547 template <bool...> struct bools {};
548 template <class... Ts> using all_of = std::is_same<
549  bools<Ts::value..., true>,
550  bools<true, Ts::value...>>;
551 template <class... Ts> using any_of = negation<all_of<negation<Ts>...>>;
552 #else
553 // MSVC has trouble with the above, but supports std::conjunction, which we can use instead (albeit
554 // at a slight loss of compilation efficiency).
555 template <class... Ts> using all_of = std::conjunction<Ts...>;
556 template <class... Ts> using any_of = std::disjunction<Ts...>;
557 #endif
558 template <class... Ts> using none_of = negation<any_of<Ts...>>;
559 
560 template <class T, template<class> class... Predicates> using satisfies_all_of = all_of<Predicates<T>...>;
561 template <class T, template<class> class... Predicates> using satisfies_any_of = any_of<Predicates<T>...>;
562 template <class T, template<class> class... Predicates> using satisfies_none_of = none_of<Predicates<T>...>;
563 
564 /// Strip the class from a method type
565 template <typename T> struct remove_class { };
566 template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...)> { using type = R (A...); };
567 template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...) const> { using type = R (A...); };
568 
569 /// Helper template to strip away type modifiers
570 template <typename T> struct intrinsic_type { using type = T; };
571 template <typename T> struct intrinsic_type<const T> { using type = typename intrinsic_type<T>::type; };
572 template <typename T> struct intrinsic_type<T*> { using type = typename intrinsic_type<T>::type; };
573 template <typename T> struct intrinsic_type<T&> { using type = typename intrinsic_type<T>::type; };
574 template <typename T> struct intrinsic_type<T&&> { using type = typename intrinsic_type<T>::type; };
575 template <typename T, size_t N> struct intrinsic_type<const T[N]> { using type = typename intrinsic_type<T>::type; };
576 template <typename T, size_t N> struct intrinsic_type<T[N]> { using type = typename intrinsic_type<T>::type; };
577 template <typename T> using intrinsic_t = typename intrinsic_type<T>::type;
578 
579 /// Helper type to replace 'void' in some expressions
580 struct void_type { };
581 
582 /// Helper template which holds a list of types
583 template <typename...> struct type_list { };
584 
585 /// Compile-time integer sum
586 #ifdef __cpp_fold_expressions
587 template <typename... Ts> constexpr size_t constexpr_sum(Ts... ns) { return (0 + ... + size_t{ns}); }
588 #else
589 constexpr size_t constexpr_sum() { return 0; }
590 template <typename T, typename... Ts>
591 constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); }
592 #endif
593 
594 PYBIND11_NAMESPACE_BEGIN(constexpr_impl)
595 /// Implementation details for constexpr functions
596 constexpr int first(int i) { return i; }
597 template <typename T, typename... Ts>
598 constexpr int first(int i, T v, Ts... vs) { return v ? i : first(i + 1, vs...); }
599 
600 constexpr int last(int /*i*/, int result) { return result; }
601 template <typename T, typename... Ts>
602 constexpr int last(int i, int result, T v, Ts... vs) { return last(i + 1, v ? i : result, vs...); }
603 PYBIND11_NAMESPACE_END(constexpr_impl)
604 
605 /// Return the index of the first type in Ts which satisfies Predicate<T>. Returns sizeof...(Ts) if
606 /// none match.
607 template <template<typename> class Predicate, typename... Ts>
609 
610 /// Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.
611 template <template<typename> class Predicate, typename... Ts>
612 constexpr int constexpr_last() { return constexpr_impl::last(0, -1, Predicate<Ts>::value...); }
613 
614 /// Return the Nth element from the parameter pack
615 template <size_t N, typename T, typename... Ts>
616 struct pack_element { using type = typename pack_element<N - 1, Ts...>::type; };
617 template <typename T, typename... Ts>
618 struct pack_element<0, T, Ts...> { using type = T; };
619 
620 /// Return the one and only type which matches the predicate, or Default if none match.
621 /// If more than one type matches the predicate, fail at compile-time.
622 template <template<typename> class Predicate, typename Default, typename... Ts>
623 struct exactly_one {
624  static constexpr auto found = constexpr_sum(Predicate<Ts>::value...);
625  static_assert(found <= 1, "Found more than one type matching the predicate");
626 
627  static constexpr auto index = found ? constexpr_first<Predicate, Ts...>() : 0;
628  using type = conditional_t<found, typename pack_element<index, Ts...>::type, Default>;
629 };
630 template <template<typename> class P, typename Default>
631 struct exactly_one<P, Default> { using type = Default; };
632 
633 template <template<typename> class Predicate, typename Default, typename... Ts>
634 using exactly_one_t = typename exactly_one<Predicate, Default, Ts...>::type;
635 
636 /// Defer the evaluation of type T until types Us are instantiated
637 template <typename T, typename... /*Us*/> struct deferred_type { using type = T; };
638 template <typename T, typename... Us> using deferred_t = typename deferred_type<T, Us...>::type;
639 
640 /// Like is_base_of, but requires a strict base (i.e. `is_strict_base_of<T, T>::value == false`,
641 /// unlike `std::is_base_of`)
642 template <typename Base, typename Derived> using is_strict_base_of = bool_constant<
644 
645 /// Like is_base_of, but also requires that the base type is accessible (i.e. that a Derived pointer
646 /// can be converted to a Base pointer)
647 /// For unions, `is_base_of<T, T>::value` is False, so we need to check `is_same` as well.
648 template <typename Base, typename Derived> using is_accessible_base_of = bool_constant<
650 
651 template <template<typename...> class Base>
653  template <typename... Us> static std::true_type check(Base<Us...> *);
654  static std::false_type check(...);
655 };
656 
657 /// Check if a template is the base of a type. For example:
658 /// `is_template_base_of<Base, T>` is true if `struct T : Base<U> {}` where U can be anything
659 template <template<typename...> class Base, typename T>
660 #if !defined(_MSC_VER)
662 #else // MSVC2015 has trouble with decltype in template aliases
663 struct is_template_base_of : decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T>*)nullptr)) { };
664 #endif
665 
666 /// Check if T is an instantiation of the template `Class`. For example:
667 /// `is_instantiation<shared_ptr, T>` is true if `T == shared_ptr<U>` where U can be anything.
668 template <template<typename...> class Class, typename T>
669 struct is_instantiation : std::false_type { };
670 template <template<typename...> class Class, typename... Us>
671 struct is_instantiation<Class, Class<Us...>> : std::true_type { };
672 
673 /// Check if T is std::shared_ptr<U> where U can be anything
675 
676 /// Check if T looks like an input iterator
677 template <typename T, typename = void> struct is_input_iterator : std::false_type {};
678 template <typename T>
679 struct is_input_iterator<T, void_t<decltype(*std::declval<T &>()), decltype(++std::declval<T &>())>>
680  : std::true_type {};
681 
682 template <typename T> using is_function_pointer = bool_constant<
683  std::is_pointer<T>::value && std::is_function<typename std::remove_pointer<T>::type>::value>;
684 
685 template <typename F> struct strip_function_object {
686  // If you are encountering an
687  // 'error: name followed by "::" must be a class or namespace name'
688  // with the Intel compiler and a noexcept function here,
689  // try to use noexcept(true) instead of plain noexcept.
690  using type = typename remove_class<decltype(&F::operator())>::type;
691 };
692 
693 // Extracts the function signature from a function, function pointer or lambda.
694 template <typename Function, typename F = remove_reference_t<Function>>
697  F,
698  typename conditional_t<
700  std::remove_pointer<F>,
702  >::type
703 >;
704 
705 /// Returns true if the type looks like a lambda: that is, isn't a function, pointer or member
706 /// pointer. Note that this can catch all sorts of other things, too; this is intended to be used
707 /// in a place where passing a lambda makes sense.
709  std::is_function, std::is_pointer, std::is_member_pointer>;
710 
711 /// Ignore that a variable is unused in compiler warnings
712 inline void ignore_unused(const int *) { }
713 
714 // [workaround(intel)] Internal error on fold expression
715 /// Apply a function over each element of a parameter pack
716 #if defined(__cpp_fold_expressions) && !defined(__INTEL_COMPILER)
717 // Intel compiler produces an internal error on this fold expression (tested with ICC 19.0.2)
718 #define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...)
719 #else
720 using expand_side_effects = bool[];
721 #define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (void)pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
722 #endif
723 
725 
726 /// C++ bindings of builtin Python exceptions
727 class builtin_exception : public std::runtime_error {
728 public:
729  using std::runtime_error::runtime_error;
730  /// Set the error using the Python C API
731  virtual void set_error() const = 0;
732 };
733 
734 #define PYBIND11_RUNTIME_EXCEPTION(name, type) \
735  class name : public builtin_exception { public: \
736  using builtin_exception::builtin_exception; \
737  name() : name("") { } \
738  void set_error() const override { PyErr_SetString(type, what()); } \
739  };
740 
741 PYBIND11_RUNTIME_EXCEPTION(stop_iteration, PyExc_StopIteration)
742 PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError)
743 PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError)
744 PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError)
745 PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
746 PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError)
747 PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
748 PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or handle::call fail due to a type casting error
749 PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
750 
751 [[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const char *reason) { throw std::runtime_error(reason); }
752 [[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const std::string &reason) { throw std::runtime_error(reason); }
753 
754 template <typename T, typename SFINAE = void> struct format_descriptor { };
755 
757 // Returns the index of the given type in the type char array below, and in the list in numpy.h
758 // The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double;
759 // complex float,double,long double. Note that the long double types only participate when long
760 // double is actually longer than double (it isn't under MSVC).
761 // NB: not only the string below but also complex.h and numpy.h rely on this order.
762 template <typename T, typename SFINAE = void> struct is_fmt_numeric { static constexpr bool value = false; };
763 template <typename T> struct is_fmt_numeric<T, enable_if_t<std::is_arithmetic<T>::value>> {
764  static constexpr bool value = true;
765  static constexpr int index = std::is_same<T, bool>::value ? 0 : 1 + (
766  std::is_integral<T>::value ? detail::log2(sizeof(T))*2 + std::is_unsigned<T>::value : 8 + (
768 };
770 
771 template <typename T> struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> {
772  static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
773  static constexpr const char value[2] = { c, '\0' };
774  static std::string format() { return std::string(1, c); }
775 };
776 
777 #if !defined(PYBIND11_CPP17)
778 
779 template <typename T> constexpr const char format_descriptor<
781 
782 #endif
783 
784 /// RAII wrapper that temporarily clears any Python error state
785 struct error_scope {
786  PyObject *type, *value, *trace;
787  error_scope() { PyErr_Fetch(&type, &value, &trace); }
788  ~error_scope() { PyErr_Restore(type, value, trace); }
789 };
790 
791 /// Dummy destructor wrapper that can be used to expose classes with a private destructor
792 struct nodelete { template <typename T> void operator()(T*) { } };
793 
795 template <typename... Args>
797  constexpr overload_cast_impl() {}; // NOLINT(modernize-use-equals-default): MSVC 2015 needs this
798 
799  template <typename Return>
800  constexpr auto operator()(Return (*pf)(Args...)) const noexcept
801  -> decltype(pf) { return pf; }
802 
803  template <typename Return, typename Class>
804  constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept
805  -> decltype(pmf) { return pmf; }
806 
807  template <typename Return, typename Class>
808  constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept
809  -> decltype(pmf) { return pmf; }
810 };
812 
813 // overload_cast requires variable templates: C++14
814 #if defined(PYBIND11_CPP14)
815 #define PYBIND11_OVERLOAD_CAST 1
816 /// Syntax sugar for resolving overloaded function pointers:
817 /// - regular: static_cast<Return (Class::*)(Arg0, Arg1, Arg2)>(&Class::func)
818 /// - sweet: overload_cast<Arg0, Arg1, Arg2>(&Class::func)
819 template <typename... Args>
820 static constexpr detail::overload_cast_impl<Args...> overload_cast = {};
821 // MSVC 2015 only accepts this particular initialization syntax for this variable template.
822 #endif
823 
824 /// Const member function selector for overload_cast
825 /// - regular: static_cast<Return (Class::*)(Arg) const>(&Class::func)
826 /// - sweet: overload_cast<Arg>(&Class::func, const_)
827 static constexpr auto const_ = std::true_type{};
828 
829 #if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails:
830 template <typename... Args> struct overload_cast {
832  "pybind11::overload_cast<...> requires compiling in C++14 mode");
833 };
834 #endif // overload_cast
835 
837 
838 // Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from
839 // any standard container (or C-style array) supporting std::begin/std::end, any singleton
840 // arithmetic type (if T is arithmetic), or explicitly constructible from an iterator pair.
841 template <typename T>
843  std::vector<T> v;
844 public:
845  any_container() = default;
846 
847  // Can construct from a pair of iterators
849  any_container(It first, It last) : v(first, last) { }
850 
851  // Implicit conversion constructor from any arbitrary container type with values convertible to T
852  template <typename Container, typename = enable_if_t<std::is_convertible<decltype(*std::begin(std::declval<const Container &>())), T>::value>>
853  any_container(const Container &c) : any_container(std::begin(c), std::end(c)) { }
854 
855  // initializer_list's aren't deducible, so don't get matched by the above template; we need this
856  // to explicitly allow implicit conversion from one:
858  any_container(const std::initializer_list<TIn> &c) : any_container(c.begin(), c.end()) { }
859 
860  // Avoid copying if given an rvalue vector of the correct type.
861  any_container(std::vector<T> &&v) : v(std::move(v)) { }
862 
863  // Moves the vector out of an rvalue any_container
864  operator std::vector<T> &&() && { return std::move(v); }
865 
866  // Dereferencing obtains a reference to the underlying vector
867  std::vector<T> &operator*() { return v; }
868  const std::vector<T> &operator*() const { return v; }
869 
870  // -> lets you call methods on the underlying vector
871  std::vector<T> *operator->() { return &v; }
872  const std::vector<T> *operator->() const { return &v; }
873 };
874 
875 // Forward-declaration; see detail/class.h
876 std::string get_fully_qualified_tp_name(PyTypeObject*);
877 
878 template <typename T>
879 inline static std::shared_ptr<T> try_get_shared_from_this(std::enable_shared_from_this<T> *holder_value_ptr) {
880 // Pre C++17, this code path exploits undefined behavior, but is known to work on many platforms.
881 // Use at your own risk!
882 // See also https://en.cppreference.com/w/cpp/memory/enable_shared_from_this, and in particular
883 // the `std::shared_ptr<Good> gp1 = not_so_good.getptr();` and `try`-`catch` parts of the example.
884 #if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
885  return holder_value_ptr->weak_from_this().lock();
886 #else
887  try {
888  return holder_value_ptr->shared_from_this();
889  }
890  catch (const std::bad_weak_ptr &) {
891  return nullptr;
892  }
893 #endif
894 }
895 
enable_if_t
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Definition: common.h:504
PYBIND11_RUNTIME_EXCEPTION
#define PYBIND11_RUNTIME_EXCEPTION(name, type)
Definition: common.h:734
test_multiple_inheritance.i
i
Definition: test_multiple_inheritance.py:22
format_descriptor
Definition: common.h:754
nonsimple_values_and_holders
Definition: common.h:431
error_scope
RAII wrapper that temporarily clears any Python error state.
Definition: common.h:785
pack_element
Return the Nth element from the parameter pack.
Definition: common.h:616
is_instantiation
Definition: common.h:669
format_descriptor< T, detail::enable_if_t< std::is_arithmetic< T >::value > >::format
static std::string format()
Definition: common.h:774
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: common.h:16
is_fmt_numeric
Definition: common.h:762
is_function_pointer
bool_constant< std::is_pointer< T >::value &&std::is_function< typename std::remove_pointer< T >::type >::value > is_function_pointer
Definition: common.h:683
strip_function_object::type
typename remove_class< decltype(&F::operator())>::type type
Definition: common.h:690
deferred_t
typename deferred_type< T, Us... >::type deferred_t
Definition: common.h:638
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: common.h:17
ignore_unused
void ignore_unused(const int *)
Ignore that a variable is unused in compiler warnings.
Definition: common.h:712
intrinsic_type
Helper template to strip away type modifiers.
Definition: common.h:570
index_sequence
Index sequences.
Definition: common.h:515
instance::simple_layout
bool simple_layout
Definition: common.h:471
type_info
Definition: internals.h:128
PYBIND11_NAMESPACE
#define PYBIND11_NAMESPACE
Definition: common.h:26
instance::nonsimple
nonsimple_values_and_holders nonsimple
Definition: common.h:442
exactly_one::found
static constexpr auto found
Definition: common.h:624
any_container::operator->
const std::vector< T > * operator->() const
Definition: common.h:872
instance::get_value_and_holder
value_and_holder get_value_and_holder(const type_info *find_type=nullptr, bool throw_if_missing=true)
Definition: cast.h:339
is_template_base_of_impl
Definition: common.h:652
instance::status_instance_registered
static constexpr uint8_t status_instance_registered
Definition: common.h:492
exactly_one
Definition: common.h:623
any_container::any_container
any_container(It first, It last)
Definition: common.h:849
is_accessible_base_of
bool_constant<(std::is_same< Base, Derived >::value||std::is_base_of< Base, Derived >::value) &&std::is_convertible< Derived *, Base * >::value > is_accessible_base_of
Definition: common.h:649
satisfies_all_of
all_of< Predicates< T >... > satisfies_all_of
Definition: common.h:560
error_scope::error_scope
error_scope()
Definition: common.h:787
error_scope::trace
PyObject * trace
Definition: common.h:786
remove_class
Strip the class from a method type.
Definition: common.h:565
void_t
typename void_t_impl< Ts... >::type void_t
Definition: common.h:538
PYBIND11_NOINLINE
#define PYBIND11_NOINLINE
Definition: common.h:88
bool_constant
std::integral_constant< bool, B > bool_constant
Backports of std::bool_constant and std::negation to accommodate older compilers.
Definition: common.h:528
make_index_sequence_impl
Definition: common.h:516
all_of
std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... > > all_of
Definition: common.h:550
type
Definition: pytypes.h:915
value_and_holder
Definition: cast.h:223
bools
Compile-time all/any/none of that check the boolean value of all template types.
Definition: common.h:547
constexpr_sum
constexpr size_t constexpr_sum()
Compile-time integer sum.
Definition: common.h:589
nonsimple_values_and_holders::values_and_holders
void ** values_and_holders
Definition: common.h:432
instance::simple_value_holder
void * simple_value_holder[1+instance_simple_holder_in_ptrs()]
Definition: common.h:441
nonsimple_values_and_holders::status
uint8_t * status
Definition: common.h:433
overload_cast_impl::overload_cast_impl
constexpr overload_cast_impl()
Definition: common.h:797
any_container::operator->
std::vector< T > * operator->()
Definition: common.h:871
script.begin
begin
Definition: script.py:184
conditional_t
typename std::conditional< B, T, F >::type conditional_t
Definition: common.h:505
instance::allocate_layout
void allocate_layout()
Initializes all of the above type/values/holders data (but not the instance values themselves)
Definition: cast.h:363
remove_reference_t
typename std::remove_reference< T >::type remove_reference_t
Definition: common.h:507
type_list
Helper template which holds a list of types.
Definition: common.h:583
builtin_exception::set_error
virtual void set_error() const =0
Set the error using the Python C API.
instance
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
Definition: common.h:437
is_template_base_of_impl::check
static std::false_type check(...)
exactly_one::type
conditional_t< found, typename pack_element< index, Ts... >::type, Default > type
Definition: common.h:628
any_container
Definition: common.h:842
get_fully_qualified_tp_name
std::string get_fully_qualified_tp_name(PyTypeObject *)
Definition: class.h:27
is_fmt_numeric::value
static constexpr bool value
Definition: common.h:762
any_container::any_container
any_container(const Container &c)
Definition: common.h:853
is_strict_base_of
bool_constant< std::is_base_of< Base, Derived >::value &&!std::is_same< Base, Derived >::value > is_strict_base_of
Definition: common.h:643
pack_element::type
typename pack_element< N - 1, Ts... >::type type
Definition: common.h:616
instance::simple_instance_registered
bool simple_instance_registered
For simple layout, tracks whether the instance is registered in registered_instances
Definition: common.h:475
instance::deallocate_layout
void deallocate_layout()
Destroys/deallocates all of the above.
Definition: cast.h:411
intrinsic_t
typename intrinsic_type< T >::type intrinsic_t
Definition: common.h:577
overload_cast_impl
Definition: common.h:796
select_indices
typename select_indices_impl< index_sequence<>, 0, Bs... >::type select_indices
Definition: common.h:525
negation
Definition: common.h:529
any_container::operator*
std::vector< T > & operator*()
Definition: common.h:867
constexpr_first
constexpr int constexpr_first()
Definition: common.h:608
strip_function_object
Definition: common.h:685
instance::has_patients
bool has_patients
If true, get_internals().patients has an entry for this object.
Definition: common.h:477
any_container::operator*
const std::vector< T > & operator*() const
Definition: common.h:868
exactly_one::index
static constexpr auto index
Definition: common.h:627
instance::owned
bool owned
If true, the pointer is owned which means we're free to manage it with a holder.
Definition: common.h:447
first
constexpr int first(int i)
Implementation details for constexpr functions.
Definition: common.h:596
ssize_t
Py_ssize_t ssize_t
Definition: common.h:353
test_call_policies.reason
reason
Definition: test_call_policies.py:10
error_scope::value
PyObject * value
Definition: common.h:786
instance::status_holder_constructed
static constexpr uint8_t status_holder_constructed
Bit values for the non-simple status flags.
Definition: common.h:491
A
Definition: test_numpy_dtypes.cpp:254
size_t
std::size_t size_t
Definition: common.h:354
pybind11_fail
PyExc_RuntimeError PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
Definition: common.h:751
deferred_type
Defer the evaluation of type T until types Us are instantiated.
Definition: common.h:637
exactly_one_t
typename exactly_one< Predicate, Default, Ts... >::type exactly_one_t
Definition: common.h:634
nodelete::operator()
void operator()(T *)
Definition: common.h:792
move
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Definition: cast.h:1798
Base
Definition: test_virtual_functions.cpp:152
instance_simple_holder_in_ptrs
constexpr size_t instance_simple_holder_in_ptrs()
Definition: common.h:421
overload_cast_impl::operator()
constexpr auto operator()(Return(*pf)(Args...)) const noexcept -> decltype(pf)
Definition: common.h:800
instance::simple_holder_constructed
bool simple_holder_constructed
For simple layout, tracks whether the holder has been constructed.
Definition: common.h:473
intrinsic_type::type
T type
Definition: common.h:570
make_index_sequence
typename make_index_sequence_impl< N >::type make_index_sequence
Definition: common.h:518
is_input_iterator
Check if T looks like an input iterator.
Definition: common.h:677
void_type
Helper type to replace 'void' in some expressions.
Definition: common.h:580
any_container::any_container
any_container(const std::initializer_list< TIn > &c)
Definition: common.h:858
return_value_policy
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Definition: common.h:357
error_scope::type
PyObject * type
Definition: common.h:786
instance::weakrefs
PyObject * weakrefs
Weak references.
Definition: common.h:445
constexpr_last
constexpr int constexpr_last()
Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.
Definition: common.h:612
overload_cast_impl::operator()
constexpr auto operator()(Return(Class::*pmf)(Args...), std::false_type={}) const noexcept -> decltype(pmf)
Definition: common.h:804
void_t_impl
Definition: common.h:537
B
Definition: test_numpy_dtypes.cpp:255
nodelete
Dummy destructor wrapper that can be used to expose classes with a private destructor.
Definition: common.h:792
select_indices_impl
Make an index sequence of the indices of true arguments.
Definition: common.h:522
script.end
end
Definition: script.py:188
expand_side_effects
bool[] expand_side_effects
Apply a function over each element of a parameter pack.
Definition: common.h:720
last
constexpr int last(int, int result)
Definition: common.h:600
error_scope::~error_scope
~error_scope()
Definition: common.h:788
builtin_exception
C++ bindings of builtin Python exceptions.
Definition: common.h:727
any_container::any_container
any_container(std::vector< T > &&v)
Definition: common.h:861
is_template_base_of_impl::check
static std::true_type check(Base< Us... > *)
test_callbacks.value
value
Definition: test_callbacks.py:126
return_value_policy::automatic
@ automatic
remove_cv_t
typename std::remove_cv< T >::type remove_cv_t
Definition: common.h:506
function_signature_t
conditional_t< std::is_function< F >::value, F, typename conditional_t< std::is_pointer< F >::value||std::is_member_pointer< F >::value, std::remove_pointer< F >, strip_function_object< F > >::type > function_signature_t
Definition: common.h:703
overload_cast
Definition: common.h:830
overload_cast_impl::operator()
constexpr auto operator()(Return(Class::*pmf)(Args...) const, std::true_type) const noexcept -> decltype(pmf)
Definition: common.h:808
any_container::any_container
any_container()=default
is_template_base_of
decltype(is_template_base_of_impl< Base >::check((intrinsic_t< T > *) nullptr)) is_template_base_of
Definition: common.h:661