μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 10
14#define PYBIND11_VERSION_PATCH 4
15
16// Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
17// Additional convention: 0xD = dev
18#define PYBIND11_VERSION_HEX 0x020A0400
19
20// Define some generic pybind11 helper macros for warning management.
21//
22// Note that compiler-specific push/pop pairs are baked into the
23// PYBIND11_NAMESPACE_BEGIN/PYBIND11_NAMESPACE_END pair of macros. Therefore manual
24// PYBIND11_WARNING_PUSH/PYBIND11_WARNING_POP are usually only needed in `#include` sections.
25//
26// If you find you need to suppress a warning, please try to make the suppression as local as
27// possible using these macros. Please also be sure to push/pop with the pybind11 macros. Please
28// only use compiler specifics if you need to check specific versions, e.g. Apple Clang vs. vanilla
29// Clang.
30#if defined(_MSC_VER)
31# define PYBIND11_COMPILER_MSVC
32# define PYBIND11_PRAGMA(...) __pragma(__VA_ARGS__)
33# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning(push))
34# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning(pop))
35#elif defined(__INTEL_COMPILER)
36# define PYBIND11_COMPILER_INTEL
37# define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__)
38# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning push)
39# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning pop)
40#elif defined(__clang__)
41# define PYBIND11_COMPILER_CLANG
42# define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__)
43# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(clang diagnostic push)
44# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(clang diagnostic push)
45#elif defined(__GNUC__)
46# define PYBIND11_COMPILER_GCC
47# define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__)
48# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(GCC diagnostic push)
49# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(GCC diagnostic pop)
50#endif
51
52#ifdef PYBIND11_COMPILER_MSVC
53# define PYBIND11_WARNING_DISABLE_MSVC(name) PYBIND11_PRAGMA(warning(disable : name))
54#else
55# define PYBIND11_WARNING_DISABLE_MSVC(name)
56#endif
57
58#ifdef PYBIND11_COMPILER_CLANG
59# define PYBIND11_WARNING_DISABLE_CLANG(name) PYBIND11_PRAGMA(clang diagnostic ignored name)
60#else
61# define PYBIND11_WARNING_DISABLE_CLANG(name)
62#endif
63
64#ifdef PYBIND11_COMPILER_GCC
65# define PYBIND11_WARNING_DISABLE_GCC(name) PYBIND11_PRAGMA(GCC diagnostic ignored name)
66#else
67# define PYBIND11_WARNING_DISABLE_GCC(name)
68#endif
69
70#ifdef PYBIND11_COMPILER_INTEL
71# define PYBIND11_WARNING_DISABLE_INTEL(name) PYBIND11_PRAGMA(warning disable name)
72#else
73# define PYBIND11_WARNING_DISABLE_INTEL(name)
74#endif
75
76#define PYBIND11_NAMESPACE_BEGIN(name) \
77 namespace name { \
78 PYBIND11_WARNING_PUSH
79
80#define PYBIND11_NAMESPACE_END(name) \
81 PYBIND11_WARNING_POP \
82 }
83
84// Robust support for some features and loading modules compiled against different pybind versions
85// requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute
86// on the main `pybind11` namespace.
87#if !defined(PYBIND11_NAMESPACE)
88# ifdef __GNUG__
89# define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden")))
90# else
91# define PYBIND11_NAMESPACE pybind11
92# endif
93#endif
94
95#if !(defined(_MSC_VER) && __cplusplus == 199711L)
96# if __cplusplus >= 201402L
97# define PYBIND11_CPP14
98# if __cplusplus >= 201703L
99# define PYBIND11_CPP17
100# if __cplusplus >= 202002L
101# define PYBIND11_CPP20
102// Please update tests/pybind11_tests.cpp `cpp_std()` when adding a macro here.
103# endif
104# endif
105# endif
106#elif defined(_MSC_VER) && __cplusplus == 199711L
107// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully
108// implemented). Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3
109// or newer.
110# if _MSVC_LANG >= 201402L
111# define PYBIND11_CPP14
112# if _MSVC_LANG > 201402L
113# define PYBIND11_CPP17
114# if _MSVC_LANG >= 202002L
115# define PYBIND11_CPP20
116# endif
117# endif
118# endif
119#endif
120
121// Compiler version assertions
122#if defined(__INTEL_COMPILER)
123# if __INTEL_COMPILER < 1800
124# error pybind11 requires Intel C++ compiler v18 or newer
125# elif __INTEL_COMPILER < 1900 && defined(PYBIND11_CPP14)
126# error pybind11 supports only C++11 with Intel C++ compiler v18. Use v19 or newer for C++14.
127# endif
128/* The following pragma cannot be pop'ed:
129 https://community.intel.com/t5/Intel-C-Compiler/Inline-and-no-inline-warning/td-p/1216764 */
130# pragma warning disable 2196 // warning #2196: routine is both "inline" and "noinline"
131#elif defined(__clang__) && !defined(__apple_build_version__)
132# if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3)
133# error pybind11 requires clang 3.3 or newer
134# endif
135#elif defined(__clang__)
136// Apple changes clang version macros to its Xcode version; the first Xcode release based on
137// (upstream) clang 3.3 was Xcode 5:
138# if __clang_major__ < 5
139# error pybind11 requires Xcode/clang 5.0 or newer
140# endif
141#elif defined(__GNUG__)
142# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
143# error pybind11 requires gcc 4.8 or newer
144# endif
145#elif defined(_MSC_VER)
146# if _MSC_VER < 1910
147# error pybind11 2.10+ requires MSVC 2017 or newer
148# endif
149#endif
150
151#if !defined(PYBIND11_EXPORT)
152# if defined(WIN32) || defined(_WIN32)
153# define PYBIND11_EXPORT __declspec(dllexport)
154# else
155# define PYBIND11_EXPORT __attribute__((visibility("default")))
156# endif
157#endif
158
159#if !defined(PYBIND11_EXPORT_EXCEPTION)
160# if defined(__apple_build_version__)
161# define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT
162# else
163# define PYBIND11_EXPORT_EXCEPTION
164# endif
165#endif
166
167// For CUDA, GCC7, GCC8:
168// PYBIND11_NOINLINE_FORCED is incompatible with `-Wattributes -Werror`.
169// When defining PYBIND11_NOINLINE_FORCED, it is best to also use `-Wno-attributes`.
170// However, the measured shared-library size saving when using noinline are only
171// 1.7% for CUDA, -0.2% for GCC7, and 0.0% for GCC8 (using -DCMAKE_BUILD_TYPE=MinSizeRel,
172// the default under pybind11/tests).
173#if !defined(PYBIND11_NOINLINE_FORCED) \
174 && (defined(__CUDACC__) || (defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8)))
175# define PYBIND11_NOINLINE_DISABLED
176#endif
177
178// The PYBIND11_NOINLINE macro is for function DEFINITIONS.
179// In contrast, FORWARD DECLARATIONS should never use this macro:
180// https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions
181#if defined(PYBIND11_NOINLINE_DISABLED) // Option for maximum portability and experimentation.
182# define PYBIND11_NOINLINE inline
183#elif defined(_MSC_VER)
184# define PYBIND11_NOINLINE __declspec(noinline) inline
185#else
186# define PYBIND11_NOINLINE __attribute__((noinline)) inline
187#endif
188
189#if defined(__MINGW32__)
190// For unknown reasons all PYBIND11_DEPRECATED member trigger a warning when declared
191// whether it is used or not
192# define PYBIND11_DEPRECATED(reason)
193#elif defined(PYBIND11_CPP14)
194# define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]]
195#else
196# define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
197#endif
198
199#if defined(PYBIND11_CPP17)
200# define PYBIND11_MAYBE_UNUSED [[maybe_unused]]
201#elif defined(_MSC_VER) && !defined(__clang__)
202# define PYBIND11_MAYBE_UNUSED
203#else
204# define PYBIND11_MAYBE_UNUSED __attribute__((__unused__))
205#endif
206
207/* Don't let Python.h #define (v)snprintf as macro because they are implemented
208 properly in Visual Studio since 2015. */
209#if defined(_MSC_VER)
210# define HAVE_SNPRINTF 1
211#endif
212
214#if defined(_MSC_VER)
215PYBIND11_WARNING_PUSH
217// C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only)
218# if defined(_DEBUG) && !defined(Py_DEBUG)
219// Workaround for a VS 2022 issue.
220// NOTE: This workaround knowingly violates the Python.h include order requirement:
221// https://docs.python.org/3/c-api/intro.html#include-files
222// See https://github.com/pybind/pybind11/pull/3497 for full context.
223# include <yvals.h>
224# if _MSVC_STL_VERSION >= 143
225# include <crtdefs.h>
226# endif
227# define PYBIND11_DEBUG_MARKER
228# undef _DEBUG
229# endif
230#endif
231
232// https://en.cppreference.com/w/c/chrono/localtime
233#if defined(__STDC_LIB_EXT1__) && !defined(__STDC_WANT_LIB_EXT1__)
234# define __STDC_WANT_LIB_EXT1__
235#endif
236
237#ifdef __has_include
238// std::optional (but including it in c++14 mode isn't allowed)
239# if defined(PYBIND11_CPP17) && __has_include(<optional>)
240# define PYBIND11_HAS_OPTIONAL 1
241# endif
242// std::experimental::optional (but not allowed in c++11 mode)
243# if defined(PYBIND11_CPP14) && (__has_include(<experimental/optional>) && \
244 !__has_include(<optional>))
245# define PYBIND11_HAS_EXP_OPTIONAL 1
246# endif
247// std::variant
248# if defined(PYBIND11_CPP17) && __has_include(<variant>)
249# define PYBIND11_HAS_VARIANT 1
250# endif
251#elif defined(_MSC_VER) && defined(PYBIND11_CPP17)
252# define PYBIND11_HAS_OPTIONAL 1
253# define PYBIND11_HAS_VARIANT 1
254#endif
255
256#if defined(PYBIND11_CPP17)
257# if defined(__has_include)
258# if __has_include(<string_view>)
259# define PYBIND11_HAS_STRING_VIEW
260# endif
261# elif defined(_MSC_VER)
262# define PYBIND11_HAS_STRING_VIEW
263# endif
264#endif
265
266#include <Python.h>
267// Reminder: WITH_THREAD is always defined if PY_VERSION_HEX >= 0x03070000
268#if PY_VERSION_HEX < 0x03060000
269# error "PYTHON < 3.6 IS UNSUPPORTED. pybind11 v2.9 was the last to support Python 2 and 3.5."
270#endif
271#include <frameobject.h>
272#include <pythread.h>
273
274/* Python #defines overrides on all sorts of core functions, which
275 tends to weak havok in C++ codebases that expect these to work
276 like regular functions (potentially with several overloads) */
277#if defined(isalnum)
278# undef isalnum
279# undef isalpha
280# undef islower
281# undef isspace
282# undef isupper
283# undef tolower
284# undef toupper
285#endif
286
287#if defined(copysign)
288# undef copysign
289#endif
290
291#if defined(PYPY_VERSION) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
292# define PYBIND11_SIMPLE_GIL_MANAGEMENT
293#endif
294
295#if defined(_MSC_VER)
296# if defined(PYBIND11_DEBUG_MARKER)
297# define _DEBUG
298# undef PYBIND11_DEBUG_MARKER
299# endif
301#endif
302
303#include <cstddef>
304#include <cstring>
305#include <exception>
306#include <forward_list>
307#include <memory>
308#include <stdexcept>
309#include <string>
310#include <type_traits>
311#include <typeindex>
312#include <unordered_map>
313#include <unordered_set>
314#include <vector>
315#if defined(__has_include)
316# if __has_include(<version>)
317# include <version>
318# endif
319#endif
320
321// Must be after including <version> or one of the other headers specified by the standard
322#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
323# define PYBIND11_HAS_U8STRING
324#endif
325
326// See description of PR #4246:
327#if !defined(NDEBUG) && !defined(PY_ASSERT_GIL_HELD_INCREF_DECREF) \
328 && !(defined(PYPY_VERSION) \
329 && defined(_MSC_VER)) /* PyPy Windows: pytest hangs indefinitely at the end of the \
330 process (see PR #4268) */ \
331 && !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
332// The following define will be enabled by default in the 2.11 release
333// define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
334#endif
335
336// #define PYBIND11_STR_LEGACY_PERMISSIVE
337// If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject
338// (probably surprising and never documented, but this was the
339// legacy behavior until and including v2.6.x). As a side-effect,
340// pybind11::isinstance<str>() is true for both pybind11::str and
341// pybind11::bytes.
342// If UNDEFINED, pybind11::str can only hold PyUnicodeObject, and
343// pybind11::isinstance<str>() is true only for pybind11::str.
344// However, for Python 2 only (!), the pybind11::str caster
345// implicitly decoded bytes to PyUnicodeObject. This was to ease
346// the transition from the legacy behavior to the non-permissive
347// behavior.
348
350#define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr)
351#define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check
352#define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION
353#define PYBIND11_BYTES_CHECK PyBytes_Check
354#define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
355#define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize
356#define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize
357#define PYBIND11_BYTES_AS_STRING PyBytes_AsString
358#define PYBIND11_BYTES_SIZE PyBytes_Size
359#define PYBIND11_LONG_CHECK(o) PyLong_Check(o)
360#define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o)
361#define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) (o))
362#define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) (o))
363#define PYBIND11_BYTES_NAME "bytes"
364#define PYBIND11_STRING_NAME "str"
365#define PYBIND11_SLICE_OBJECT PyObject
366#define PYBIND11_FROM_STRING PyUnicode_FromString
367#define PYBIND11_STR_TYPE ::pybind11::str
368#define PYBIND11_BOOL_ATTR "__bool__"
369#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool)
370#define PYBIND11_BUILTINS_MODULE "builtins"
371// Providing a separate declaration to make Clang's -Wmissing-prototypes happy.
372// See comment for PYBIND11_MODULE below for why this is marked "maybe unused".
373#define PYBIND11_PLUGIN_IMPL(name) \
374 extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT PyObject *PyInit_##name(); \
375 extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()
376
377#define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code
378#define PYBIND11_STRINGIFY(x) #x
379#define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
380#define PYBIND11_CONCAT(first, second) first##second
381#define PYBIND11_ENSURE_INTERNALS_READY pybind11::detail::get_internals();
382
383#define PYBIND11_CHECK_PYTHON_VERSION \
384 { \
385 const char *compiled_ver \
386 = PYBIND11_TOSTRING(PY_MAJOR_VERSION) "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \
387 const char *runtime_ver = Py_GetVersion(); \
388 size_t len = std::strlen(compiled_ver); \
389 if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \
390 || (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \
391 PyErr_Format(PyExc_ImportError, \
392 "Python version mismatch: module was compiled for Python %s, " \
393 "but the interpreter version is incompatible: %s.", \
394 compiled_ver, \
395 runtime_ver); \
396 return nullptr; \
397 } \
398 }
399
400#define PYBIND11_CATCH_INIT_EXCEPTIONS \
401 catch (pybind11::error_already_set & e) { \
402 pybind11::raise_from(e, PyExc_ImportError, "initialization failed"); \
403 return nullptr; \
404 } \
405 catch (const std::exception &e) { \
406 PyErr_SetString(PyExc_ImportError, e.what()); \
407 return nullptr; \
408 }
409
422
425#define PYBIND11_PLUGIN(name) \
426 PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
427 static PyObject *pybind11_init(); \
428 PYBIND11_PLUGIN_IMPL(name) { \
429 PYBIND11_CHECK_PYTHON_VERSION \
430 PYBIND11_ENSURE_INTERNALS_READY \
431 try { \
432 return pybind11_init(); \
433 } \
434 PYBIND11_CATCH_INIT_EXCEPTIONS \
435 } \
436 PyObject *pybind11_init()
437
459#define PYBIND11_MODULE(name, variable) \
460 static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name) \
461 PYBIND11_MAYBE_UNUSED; \
462 PYBIND11_MAYBE_UNUSED \
463 static void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &); \
464 PYBIND11_PLUGIN_IMPL(name) { \
465 PYBIND11_CHECK_PYTHON_VERSION \
466 PYBIND11_ENSURE_INTERNALS_READY \
467 auto m = ::pybind11::module_::create_extension_module( \
468 PYBIND11_TOSTRING(name), nullptr, &PYBIND11_CONCAT(pybind11_module_def_, name)); \
469 try { \
470 PYBIND11_CONCAT(pybind11_init_, name)(m); \
471 return m.ptr(); \
472 } \
473 PYBIND11_CATCH_INIT_EXCEPTIONS \
474 } \
475 void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ & (variable))
476
478
479using ssize_t = Py_ssize_t;
480using size_t = std::size_t;
481
482template <typename IntType>
483inline ssize_t ssize_t_cast(const IntType &val) {
484 static_assert(sizeof(IntType) <= sizeof(ssize_t), "Implicit narrowing is not permitted.");
485 return static_cast<ssize_t>(val);
486}
487
489enum class return_value_policy : uint8_t {
495 automatic = 0,
496
502
508
512 copy,
513
518 move,
519
525 reference,
526
538};
539
541
542inline static constexpr int log2(size_t n, int k = 0) {
543 return (n <= 1) ? k : log2(n >> 1, k + 1);
544}
545
546// Returns the size as a multiple of sizeof(void *), rounded up.
547inline static constexpr size_t size_in_ptrs(size_t s) {
548 return 1 + ((s - 1) >> log2(sizeof(void *)));
549}
550
558 static_assert(sizeof(std::shared_ptr<int>) >= sizeof(std::unique_ptr<int>),
559 "pybind assumes std::shared_ptrs are at least as big as std::unique_ptrs");
560 return size_in_ptrs(sizeof(std::shared_ptr<int>));
561}
562
563// Forward declarations
564struct type_info;
565struct value_and_holder;
566
568 void **values_and_holders;
569 uint8_t *status;
570};
571
573struct instance {
574 PyObject_HEAD
576 union {
579 };
581 PyObject *weakrefs;
583 bool owned : 1;
607 bool simple_layout : 1;
613 bool has_patients : 1;
614
618
621
626 bool throw_if_missing = true);
627
629 static constexpr uint8_t status_holder_constructed = 1;
630 static constexpr uint8_t status_instance_registered = 2;
631};
632
633static_assert(std::is_standard_layout<instance>::value,
634 "Internal error: `pybind11::detail::instance` is not standard layout!");
635
637#if defined(PYBIND11_CPP14)
638using std::conditional_t;
639using std::enable_if_t;
640using std::remove_cv_t;
641using std::remove_reference_t;
642#else
643template <bool B, typename T = void>
644using enable_if_t = typename std::enable_if<B, T>::type;
645template <bool B, typename T, typename F>
646using conditional_t = typename std::conditional<B, T, F>::type;
647template <typename T>
648using remove_cv_t = typename std::remove_cv<T>::type;
649template <typename T>
650using remove_reference_t = typename std::remove_reference<T>::type;
651#endif
652
653#if defined(PYBIND11_CPP20)
654using std::remove_cvref;
655using std::remove_cvref_t;
656#else
657template <class T>
658struct remove_cvref {
660};
661template <class T>
663#endif
664
666#if defined(PYBIND11_CPP14)
667using std::index_sequence;
668using std::make_index_sequence;
669#else
670template <size_t...>
671struct index_sequence {};
672template <size_t N, size_t... S>
673struct make_index_sequence_impl : make_index_sequence_impl<N - 1, N - 1, S...> {};
674template <size_t... S>
675struct make_index_sequence_impl<0, S...> {
676 using type = index_sequence<S...>;
677};
678template <size_t N>
680#endif
681
683template <typename ISeq, size_t, bool...>
684struct select_indices_impl {
685 using type = ISeq;
686};
687template <size_t... IPrev, size_t I, bool B, bool... Bs>
688struct select_indices_impl<index_sequence<IPrev...>, I, B, Bs...>
689 : select_indices_impl<conditional_t<B, index_sequence<IPrev..., I>, index_sequence<IPrev...>>,
690 I + 1,
691 Bs...> {};
692template <bool... Bs>
694
696template <bool B>
697using bool_constant = std::integral_constant<bool, B>;
698template <typename T>
699struct negation : bool_constant<!T::value> {};
700
701// PGI/Intel cannot detect operator delete with the "compatible" void_t impl, so
702// using the new one (C++14 defect, so generally works on newer compilers, even
703// if not in C++17 mode)
704#if defined(__PGIC__) || defined(__INTEL_COMPILER)
705template <typename...>
706using void_t = void;
707#else
708template <typename...>
709struct void_t_impl {
710 using type = void;
711};
712template <typename... Ts>
713using void_t = typename void_t_impl<Ts...>::type;
714#endif
715
717#if defined(__cpp_fold_expressions) && !(defined(_MSC_VER) && (_MSC_VER < 1916))
718template <class... Ts>
719using all_of = bool_constant<(Ts::value && ...)>;
720template <class... Ts>
721using any_of = bool_constant<(Ts::value || ...)>;
722#elif !defined(_MSC_VER)
723template <bool...>
724struct bools {};
725template <class... Ts>
726using all_of = std::is_same<bools<Ts::value..., true>, bools<true, Ts::value...>>;
727template <class... Ts>
729#else
730// MSVC has trouble with the above, but supports std::conjunction, which we can use instead (albeit
731// at a slight loss of compilation efficiency).
732template <class... Ts>
733using all_of = std::conjunction<Ts...>;
734template <class... Ts>
735using any_of = std::disjunction<Ts...>;
736#endif
737template <class... Ts>
738using none_of = negation<any_of<Ts...>>;
739
740template <class T, template <class> class... Predicates>
742template <class T, template <class> class... Predicates>
744template <class T, template <class> class... Predicates>
746
748template <typename T>
749struct remove_class {};
750template <typename C, typename R, typename... A>
751struct remove_class<R (C::*)(A...)> {
752 using type = R(A...);
753};
754template <typename C, typename R, typename... A>
755struct remove_class<R (C::*)(A...) const> {
756 using type = R(A...);
757};
758
760template <typename T>
761struct intrinsic_type {
762 using type = T;
763};
764template <typename T>
765struct intrinsic_type<const T> {
767};
768template <typename T>
769struct intrinsic_type<T *> {
771};
772template <typename T>
773struct intrinsic_type<T &> {
775};
776template <typename T>
777struct intrinsic_type<T &&> {
779};
780template <typename T, size_t N>
781struct intrinsic_type<const T[N]> {
783};
784template <typename T, size_t N>
785struct intrinsic_type<T[N]> {
787};
788template <typename T>
790
792struct void_type {};
793
795template <typename...>
796struct type_list {};
797
799#ifdef __cpp_fold_expressions
800template <typename... Ts>
801constexpr size_t constexpr_sum(Ts... ns) {
802 return (0 + ... + size_t{ns});
803}
804#else
805constexpr size_t constexpr_sum() { return 0; }
806template <typename T, typename... Ts>
807constexpr size_t constexpr_sum(T n, Ts... ns) {
808 return size_t{n} + constexpr_sum(ns...);
809}
810#endif
811
812PYBIND11_NAMESPACE_BEGIN(constexpr_impl)
814constexpr int first(int i) { return i; }
815template <typename T, typename... Ts>
816constexpr int first(int i, T v, Ts... vs) {
817 return v ? i : first(i + 1, vs...);
818}
819
820constexpr int last(int /*i*/, int result) { return result; }
821template <typename T, typename... Ts>
822constexpr int last(int i, int result, T v, Ts... vs) {
823 return last(i + 1, v ? i : result, vs...);
824}
825PYBIND11_NAMESPACE_END(constexpr_impl)
826
827
829template <template <typename> class Predicate, typename... Ts>
830constexpr int constexpr_first() {
831 return constexpr_impl::first(0, Predicate<Ts>::value...);
832}
833
835template <template <typename> class Predicate, typename... Ts>
836constexpr int constexpr_last() {
837 return constexpr_impl::last(0, -1, Predicate<Ts>::value...);
838}
839
841template <size_t N, typename T, typename... Ts>
842struct pack_element {
843 using type = typename pack_element<N - 1, Ts...>::type;
844};
845template <typename T, typename... Ts>
846struct pack_element<0, T, Ts...> {
847 using type = T;
848};
849
852template <template <typename> class Predicate, typename Default, typename... Ts>
853struct exactly_one {
854 static constexpr auto found = constexpr_sum(Predicate<Ts>::value...);
855 static_assert(found <= 1, "Found more than one type matching the predicate");
856
857 static constexpr auto index = found ? constexpr_first<Predicate, Ts...>() : 0;
858 using type = conditional_t<found, typename pack_element<index, Ts...>::type, Default>;
859};
860template <template <typename> class P, typename Default>
861struct exactly_one<P, Default> {
862 using type = Default;
863};
864
865template <template <typename> class Predicate, typename Default, typename... Ts>
866using exactly_one_t = typename exactly_one<Predicate, Default, Ts...>::type;
867
869template <typename T, typename... /*Us*/>
870struct deferred_type {
871 using type = T;
872};
873template <typename T, typename... Us>
874using deferred_t = typename deferred_type<T, Us...>::type;
875
878template <typename Base, typename Derived>
880 = bool_constant<std::is_base_of<Base, Derived>::value && !std::is_same<Base, Derived>::value>;
881
885template <typename Base, typename Derived>
887 = bool_constant<(std::is_same<Base, Derived>::value || std::is_base_of<Base, Derived>::value)
888 && std::is_convertible<Derived *, Base *>::value>;
889
890template <template <typename...> class Base>
892 template <typename... Us>
893 static std::true_type check(Base<Us...> *);
894 static std::false_type check(...);
895};
896
899template <template <typename...> class Base, typename T>
900// Sadly, all MSVC versions incl. 2022 need the workaround, even in C++20 mode.
901// See also: https://github.com/pybind/pybind11/pull/3741
902#if !defined(_MSC_VER)
905#else
907 : decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr)) {
908};
909#endif
910
913template <template <typename...> class Class, typename T>
914struct is_instantiation : std::false_type {};
915template <template <typename...> class Class, typename... Us>
916struct is_instantiation<Class, Class<Us...>> : std::true_type {};
917
919template <typename T>
921
923template <typename T, typename = void>
924struct is_input_iterator : std::false_type {};
925template <typename T>
926struct is_input_iterator<T,
927 void_t<decltype(*std::declval<T &>()), decltype(++std::declval<T &>())>>
928 : std::true_type {};
929
930template <typename T>
933 && std::is_function<typename std::remove_pointer<T>::type>::value>;
934
935template <typename F>
937 // If you are encountering an
938 // 'error: name followed by "::" must be a class or namespace name'
939 // with the Intel compiler and a noexcept function here,
940 // try to use noexcept(true) instead of plain noexcept.
941 using type = typename remove_class<decltype(&F::operator())>::type;
942};
943
944// Extracts the function signature from a function, function pointer or lambda.
945template <typename Function, typename F = remove_reference_t<Function>>
947 std::is_function<F>::value,
948 F,
949 typename conditional_t<std::is_pointer<F>::value || std::is_member_pointer<F>::value,
950 std::remove_pointer<F>,
952
956template <typename T>
958 std::is_function,
959 std::is_pointer,
960 std::is_member_pointer>;
961
962// [workaround(intel)] Internal error on fold expression
964#if defined(__cpp_fold_expressions) && !defined(__INTEL_COMPILER)
965// Intel compiler produces an internal error on this fold expression (tested with ICC 19.0.2)
966# define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...)
967#else
968using expand_side_effects = bool[];
969# define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) \
970 (void) pybind11::detail::expand_side_effects { ((PATTERN), void(), false)..., false }
971#endif
972
974
975
976class PYBIND11_EXPORT_EXCEPTION builtin_exception : public std::runtime_error {
977public:
978 using std::runtime_error::runtime_error;
980 virtual void set_error() const = 0;
981};
982
983#define PYBIND11_RUNTIME_EXCEPTION(name, type) \
984 class PYBIND11_EXPORT_EXCEPTION name : public builtin_exception { \
985 public: \
986 using builtin_exception::builtin_exception; \
987 name() : name("") {} \
988 void set_error() const override { PyErr_SetString(type, what()); } \
989 };
990
991PYBIND11_RUNTIME_EXCEPTION(stop_iteration, PyExc_StopIteration)
992PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError)
993PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError)
994PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError)
995PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
996PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError)
997PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
998PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError)
999PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError)
1002PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError)
1003
1004[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason) {
1005 assert(!PyErr_Occurred());
1006 throw std::runtime_error(reason);
1007}
1008[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const std::string &reason) {
1009 assert(!PyErr_Occurred());
1010 throw std::runtime_error(reason);
1011}
1012
1013template <typename T, typename SFINAE = void>
1014struct format_descriptor {};
1015
1017// Returns the index of the given type in the type char array below, and in the list in numpy.h
1018// The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double;
1019// complex float,double,long double. Note that the long double types only participate when long
1020// double is actually longer than double (it isn't under MSVC).
1021// NB: not only the string below but also complex.h and numpy.h rely on this order.
1022template <typename T, typename SFINAE = void>
1023struct is_fmt_numeric {
1024 static constexpr bool value = false;
1025};
1026template <typename T>
1027struct is_fmt_numeric<T, enable_if_t<std::is_arithmetic<T>::value>> {
1028 static constexpr bool value = true;
1029 static constexpr int index
1030 = std::is_same<T, bool>::value
1031 ? 0
1032 : 1
1033 + (std::is_integral<T>::value
1034 ? detail::log2(sizeof(T)) * 2 + std::is_unsigned<T>::value
1035 : 8
1036 + (std::is_same<T, double>::value ? 1
1037 : std::is_same<T, long double>::value ? 2
1038 : 0));
1039};
1041
1042template <typename T>
1043struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> {
1044 static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
1045 static constexpr const char value[2] = {c, '\0'};
1046 static std::string format() { return std::string(1, c); }
1047};
1048
1049#if !defined(PYBIND11_CPP17)
1050
1051template <typename T>
1052constexpr const char
1054
1055#endif
1056
1058struct error_scope {
1059 PyObject *type, *value, *trace;
1060 error_scope() { PyErr_Fetch(&type, &value, &trace); }
1061 error_scope(const error_scope &) = delete;
1063 ~error_scope() { PyErr_Restore(type, value, trace); }
1064};
1065
1067struct nodelete {
1068 template <typename T>
1069 void operator()(T *) {}
1070};
1071
1073template <typename... Args>
1074struct overload_cast_impl {
1075 template <typename Return>
1076 constexpr auto operator()(Return (*pf)(Args...)) const noexcept -> decltype(pf) {
1077 return pf;
1078 }
1079
1080 template <typename Return, typename Class>
1081 constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept
1082 -> decltype(pmf) {
1083 return pmf;
1084 }
1085
1086 template <typename Return, typename Class>
1087 constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept
1088 -> decltype(pmf) {
1089 return pmf;
1090 }
1091};
1093
1094// overload_cast requires variable templates: C++14
1095#if defined(PYBIND11_CPP14)
1096# define PYBIND11_OVERLOAD_CAST 1
1100template <typename... Args>
1101static constexpr detail::overload_cast_impl<Args...> overload_cast{};
1102#endif
1103
1107static constexpr auto const_ = std::true_type{};
1108
1109#if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails:
1110template <typename... Args>
1111struct overload_cast {
1112 static_assert(detail::deferred_t<std::false_type, Args...>::value,
1113 "pybind11::overload_cast<...> requires compiling in C++14 mode");
1114};
1115#endif // overload_cast
1116
1118
1119// Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from
1120// any standard container (or C-style array) supporting std::begin/std::end, any singleton
1121// arithmetic type (if T is arithmetic), or explicitly constructible from an iterator pair.
1122template <typename T>
1123class any_container {
1124 std::vector<T> v;
1125
1126public:
1127 any_container() = default;
1128
1129 // Can construct from a pair of iterators
1130 template <typename It, typename = enable_if_t<is_input_iterator<It>::value>>
1132
1133 // Implicit conversion constructor from any arbitrary container type
1134 // with values convertible to T
1135 template <typename Container,
1136 typename = enable_if_t<
1137 std::is_convertible<decltype(*std::begin(std::declval<const Container &>())),
1138 T>::value>>
1139 // NOLINTNEXTLINE(google-explicit-constructor)
1140 any_container(const Container &c) : any_container(std::begin(c), std::end(c)) {}
1141
1142 // initializer_list's aren't deducible, so don't get matched by the above template;
1143 // we need this to explicitly allow implicit conversion from one:
1144 template <typename TIn, typename = enable_if_t<std::is_convertible<TIn, T>::value>>
1145 any_container(const std::initializer_list<TIn> &c) : any_container(c.begin(), c.end()) {}
1146
1147 // Avoid copying if given an rvalue vector of the correct type.
1148 // NOLINTNEXTLINE(google-explicit-constructor)
1149 any_container(std::vector<T> &&v) : v(std::move(v)) {}
1150
1151 // Moves the vector out of an rvalue any_container
1152 // NOLINTNEXTLINE(google-explicit-constructor)
1153 operator std::vector<T> &&() && { return std::move(v); }
1154
1155 // Dereferencing obtains a reference to the underlying vector
1156 std::vector<T> &operator*() { return v; }
1157 const std::vector<T> &operator*() const { return v; }
1158
1159 // -> lets you call methods on the underlying vector
1160 std::vector<T> *operator->() { return &v; }
1161 const std::vector<T> *operator->() const { return &v; }
1162};
1163
1164// Forward-declaration; see detail/class.h
1165std::string get_fully_qualified_tp_name(PyTypeObject *);
1166
1167template <typename T>
1168inline static std::shared_ptr<T>
1169try_get_shared_from_this(std::enable_shared_from_this<T> *holder_value_ptr) {
1170// Pre C++17, this code path exploits undefined behavior, but is known to work on many platforms.
1171// Use at your own risk!
1172// See also https://en.cppreference.com/w/cpp/memory/enable_shared_from_this, and in particular
1173// the `std::shared_ptr<Good> gp1 = not_so_good.getptr();` and `try`-`catch` parts of the example.
1174#if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
1175 return holder_value_ptr->weak_from_this().lock();
1176#else
1177 try {
1178 return holder_value_ptr->shared_from_this();
1179 } catch (const std::bad_weak_ptr &) {
1180 return nullptr;
1181 }
1182#endif
1183}
1184
1185// For silencing "unused" compiler warnings in special situations.
1186template <typename... Args>
1187#if defined(_MSC_VER) && _MSC_VER < 1920 // MSVC 2017
1188constexpr
1189#endif
1190 inline void
1192}
1193
1194// MSVC warning C4100: Unreferenced formal parameter
1195#if defined(_MSC_VER) && _MSC_VER <= 1916
1196# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...) \
1197 detail::silence_unused_warnings(__VA_ARGS__)
1198#else
1199# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
1200#endif
1201
1202// GCC -Wunused-but-set-parameter All GCC versions (as of July 2021).
1203#if defined(__GNUG__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
1204# define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...) \
1205 detail::silence_unused_warnings(__VA_ARGS__)
1206#else
1207# define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
1208#endif
1209
1210#if defined(__clang__) \
1211 && (defined(__apple_build_version__) /* AppleClang 13.0.0.13000029 was the only data point \
1212 available. */ \
1213 || (__clang_major__ >= 7 \
1214 && __clang_major__ <= 12) /* Clang 3, 5, 13, 14, 15 do not generate the warning. */ \
1215 )
1216# define PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING
1217// Example:
1218// tests/test_kwargs_and_defaults.cpp:46:68: error: local variable 'args' will be copied despite
1219// being returned by name [-Werror,-Wreturn-std-move]
1220// m.def("args_function", [](py::args args) -> py::tuple { return args; });
1221// ^~~~
1222// test_kwargs_and_defaults.cpp:46:68: note: call 'std::move' explicitly to avoid copying
1223// m.def("args_function", [](py::args args) -> py::tuple { return args; });
1224// ^~~~
1225// std::move(args)
1226#endif
1227
1228// Pybind offers detailed error messages by default for all builts that are debug (through the
1229// negation of ndebug). This can also be manually enabled by users, for any builds, through
1230// defining PYBIND11_DETAILED_ERROR_MESSAGES.
1231#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) && !defined(NDEBUG)
1232# define PYBIND11_DETAILED_ERROR_MESSAGES
1233#endif
1234
any_container(It first, It last)
Definition: common.h:1131
std::vector< T > * operator->()
Definition: common.h:1160
any_container(const Container &c)
Definition: common.h:1140
std::vector< T > & operator*()
Definition: common.h:1156
any_container(std::vector< T > &&v)
Definition: common.h:1149
any_container(const std::initializer_list< TIn > &c)
Definition: common.h:1145
const std::vector< T > & operator*() const
Definition: common.h:1157
const std::vector< T > * operator->() const
Definition: common.h:1161
std::vector< T > v
Definition: common.h:1112
any_container()=default
C++ bindings of builtin Python exceptions.
Definition: common.h:961
virtual void set_error() const =0
Set the error using the Python C API.
Definition: pytypes.h:1167
PYBIND11_WARNING_PUSH PYBIND11_WARNING_POP
Definition: matrix.h:35
ClientInterface * c
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Definition: common.h:625
std::string get_fully_qualified_tp_name(PyTypeObject *)
Definition: class.h:28
typename deferred_type< T, Us... >::type deferred_t
Definition: common.h:855
std::integral_constant< bool, B > bool_constant
Backports of std::bool_constant and std::negation to accommodate older compilers.
Definition: common.h:678
constexpr int last(int, int result)
Definition: common.h:801
static constexpr size_t size_in_ptrs(size_t s)
Definition: common.h:528
PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Thrown when pybind11::cast or.
Definition: common.h:992
#define PYBIND11_NOINLINE
Definition: common.h:129
constexpr size_t instance_simple_holder_in_ptrs()
The space to allocate for simple layout instance holders (see below) in multiple of the size of a poi...
Definition: common.h:538
void silence_unused_warnings(Args &&...)
Definition: common.h:1179
typename std::remove_reference< T >::type remove_reference_t
Definition: common.h:631
constexpr int constexpr_first()
Return the index of the first type in Ts which satisfies Predicate<T>.
Definition: common.h:811
typename remove_cvref< T >::type remove_cvref_t
Definition: common.h:643
static std::shared_ptr< T > try_get_shared_from_this(std::enable_shared_from_this< T > *holder_value_ptr)
Definition: common.h:1157
typename intrinsic_type< T >::type intrinsic_t
Definition: common.h:770
bool_constant< std::is_pointer< T >::value &&std::is_function< typename std::remove_pointer< T >::type >::value > is_function_pointer
Definition: common.h:912
all_of< Predicates< T >... > satisfies_all_of
Definition: common.h:722
#define PYBIND11_EXPORT_EXCEPTION
Definition: common.h:106
decltype(is_template_base_of_impl< Base >::check((intrinsic_t< T > *) nullptr)) is_template_base_of
Check if a template is the base of a type.
Definition: common.h:883
constexpr int first(int i)
Implementation details for constexpr functions.
Definition: common.h:795
static constexpr auto const_
Const member function selector for overload_cast.
Definition: common.h:1095
static constexpr int log2(size_t n, int k=0)
Definition: common.h:523
std::size_t size_t
Definition: common.h:461
constexpr size_t constexpr_sum()
Compile-time integer sum.
Definition: common.h:786
#define PYBIND11_RUNTIME_EXCEPTION(name, type)
Definition: common.h:971
typename std::remove_cv< T >::type remove_cv_t
Definition: common.h:629
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
Like is_base_of, but also requires that the base type is accessible (i.e.
Definition: common.h:869
#define PYBIND11_NAMESPACE_END(name)
Definition: common.h:21
typename exactly_one< Predicate, Default, Ts... >::type exactly_one_t
Definition: common.h:847
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:930
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: common.h:20
typename make_index_sequence_impl< N >::type make_index_sequence
Definition: common.h:660
bool_constant< std::is_base_of< Base, Derived >::value &&!std::is_same< Base, Derived >::value > is_strict_base_of
Like is_base_of, but requires a strict base (i.e.
Definition: common.h:861
Py_ssize_t ssize_t
Definition: common.h:460
typename void_t_impl< Ts... >::type void_t
Definition: common.h:694
std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... > > all_of
Definition: common.h:707
typename std::conditional< B, T, F >::type conditional_t
Definition: common.h:627
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:817
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Definition: common.h:470
@ copy
Create a new copy of the returned object, which will be owned by Python.
@ automatic_reference
As above, but use policy return_value_policy::reference when the return value is a pointer.
@ automatic
This is the default return value policy, which falls back to the policy return_value_policy::take_own...
@ move
Use std::move to move the return value contents into a new instance that will be owned by Python.
@ take_ownership
Reference an existing object (i.e.
@ reference_internal
This policy only applies to methods and properties.
@ reference
Reference an existing object, but do not take ownership.
ssize_t ssize_t_cast(const IntType &val)
Definition: common.h:464
bool[] expand_side_effects
Apply a function over each element of a parameter pack.
Definition: common.h:947
typename select_indices_impl< index_sequence<>, 0, Bs... >::type select_indices
Definition: common.h:674
constexpr int last(int, int result)
Definition: common.h:820
constexpr size_t instance_simple_holder_in_ptrs()
The space to allocate for simple layout instance holders (see below) in multiple of the size of a poi...
Definition: common.h:557
constexpr int constexpr_first()
Return the index of the first type in Ts which satisfies Predicate<T>.
Definition: common.h:830
constexpr int first(int i)
Implementation details for constexpr functions.
Definition: common.h:814
#define PYBIND11_WARNING_DISABLE_MSVC(name)
Definition: common.h:55
constexpr size_t constexpr_sum()
Compile-time integer sum.
Definition: common.h:805
typename std::remove_cv< T >::type remove_cv_t
Definition: common.h:648
typename std::conditional< B, T, F >::type conditional_t
Definition: common.h:646
@ move
Use std::move to move the return value contents into a new instance that will be owned by Python.
Compile-time all/any/none of that check the boolean value of all template types.
Definition: common.h:705
Defer the evaluation of type T until types Us are instantiated.
Definition: common.h:851
RAII wrapper that temporarily clears any Python error state.
Definition: common.h:1044
PyObject * value
Definition: common.h:1045
error_scope()
Definition: common.h:1060
PyObject * type
Definition: common.h:1045
error_scope & operator=(const error_scope &)=delete
error_scope(const error_scope &)=delete
PyObject * trace
Definition: common.h:1045
~error_scope()
Definition: common.h:1063
Return the one and only type which matches the predicate, or Default if none match.
Definition: common.h:834
static constexpr auto index
Definition: common.h:838
static constexpr auto found
Definition: common.h:835
conditional_t< found, typename pack_element< index, Ts... >::type, Default > type
Definition: common.h:839
Index sequences.
Definition: common.h:652
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
Definition: common.h:554
nonsimple_values_and_holders nonsimple
Definition: common.h:559
bool simple_layout
An instance has two possible value/holder layouts.
Definition: common.h:588
bool has_patients
If true, get_internals().patients has an entry for this object.
Definition: common.h:594
PyObject * weakrefs
Weak references.
Definition: common.h:562
void * simple_value_holder[1+instance_simple_holder_in_ptrs()]
Definition: common.h:558
bool simple_instance_registered
For simple layout, tracks whether the instance is registered in registered_instances
Definition: common.h:592
bool owned
If true, the pointer is owned which means we're free to manage it with a holder.
Definition: common.h:564
static constexpr uint8_t status_instance_registered
Definition: common.h:611
bool simple_holder_constructed
For simple layout, tracks whether the holder has been constructed.
Definition: common.h:590
void allocate_layout()
Initializes all of the above type/values/holders data (but not the instance values themselves)
static constexpr uint8_t status_holder_constructed
Bit values for the non-simple status flags.
Definition: common.h:610
value_and_holder get_value_and_holder(const type_info *find_type=nullptr, bool throw_if_missing=true)
Returns the value_and_holder wrapper for the given type (or the first, if find_type omitted).
void deallocate_layout()
Destroys/deallocates all of the above.
Helper template to strip away type modifiers.
Definition: common.h:742
static constexpr bool value
Definition: common.h:1010
Check if T looks like an input iterator.
Definition: common.h:903
Check if T is an instantiation of the template Class.
Definition: common.h:893
static std::false_type check(...)
static std::true_type check(Base< Us... > *)
Dummy destructor wrapper that can be used to expose classes with a private destructor.
Definition: common.h:1051
void operator()(T *)
Definition: common.h:1069
constexpr auto operator()(Return(*pf)(Args...)) const noexcept -> decltype(pf)
Definition: common.h:1076
constexpr auto operator()(Return(Class::*pmf)(Args...), std::false_type={}) const noexcept -> decltype(pmf)
Definition: common.h:1081
constexpr auto operator()(Return(Class::*pmf)(Args...) const, std::true_type) const noexcept -> decltype(pmf)
Definition: common.h:1087
Return the Nth element from the parameter pack.
Definition: common.h:823
typename pack_element< N - 1, Ts... >::type type
Definition: common.h:824
Strip the class from a method type.
Definition: common.h:730
remove_cv_t< remove_reference_t< T > > type
Definition: common.h:640
Make an index sequence of the indices of true arguments.
Definition: common.h:665
Additional type information which does not fit into the PyTypeObject.
Definition: internals.h:196
Helper template which holds a list of types.
Definition: common.h:777
Helper type to replace 'void' in some expressions.
Definition: common.h:773