wrap/pybind11/include/pybind11/detail/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 0.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) && !defined(__INTEL_COMPILER)
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 < 1700
51 # error pybind11 requires Intel C++ compiler v17 or newer
52 # endif
53 #elif defined(__clang__) && !defined(__apple_build_version__)
54 # if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3)
55 # error pybind11 requires clang 3.3 or newer
56 # endif
57 #elif defined(__clang__)
58 // Apple changes clang version macros to its Xcode version; the first Xcode release based on
59 // (upstream) clang 3.3 was Xcode 5:
60 # if __clang_major__ < 5
61 # error pybind11 requires Xcode/clang 5.0 or newer
62 # endif
63 #elif defined(__GNUG__)
64 # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
65 # error pybind11 requires gcc 4.8 or newer
66 # endif
67 #elif defined(_MSC_VER)
68 // Pybind hits various compiler bugs in 2015u2 and earlier, and also makes use of some stl features
69 // (e.g. std::negation) added in 2015u3:
70 # if _MSC_FULL_VER < 190024210
71 # error pybind11 requires MSVC 2015 update 3 or newer
72 # endif
73 #endif
74 
75 #if !defined(PYBIND11_EXPORT)
76 # if defined(WIN32) || defined(_WIN32)
77 # define PYBIND11_EXPORT __declspec(dllexport)
78 # else
79 # define PYBIND11_EXPORT __attribute__ ((visibility("default")))
80 # endif
81 #endif
82 
83 #if defined(_MSC_VER)
84 # define PYBIND11_NOINLINE __declspec(noinline)
85 #else
86 # define PYBIND11_NOINLINE __attribute__ ((noinline))
87 #endif
88 
89 #if defined(PYBIND11_CPP14)
90 # define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]]
91 #else
92 # define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
93 #endif
94 
95 #if defined(PYBIND11_CPP17)
96 # define PYBIND11_MAYBE_UNUSED [[maybe_unused]]
97 #elif defined(_MSC_VER) && !defined(__clang__)
98 # define PYBIND11_MAYBE_UNUSED
99 #else
100 # define PYBIND11_MAYBE_UNUSED __attribute__ ((__unused__))
101 #endif
102 
103 /* Don't let Python.h #define (v)snprintf as macro because they are implemented
104  properly in Visual Studio since 2015. */
105 #if defined(_MSC_VER) && _MSC_VER >= 1900
106 # define HAVE_SNPRINTF 1
107 #endif
108 
110 #if defined(_MSC_VER)
111 # if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4)
112 # define HAVE_ROUND 1
113 # endif
114 # pragma warning(push)
115 # pragma warning(disable: 4510 4610 4512 4005)
116 # if defined(_DEBUG) && !defined(Py_DEBUG)
117 # define PYBIND11_DEBUG_MARKER
118 # undef _DEBUG
119 # endif
120 #endif
121 
122 #include <Python.h>
123 #include <frameobject.h>
124 #include <pythread.h>
125 
126 /* Python #defines overrides on all sorts of core functions, which
127  tends to weak havok in C++ codebases that expect these to work
128  like regular functions (potentially with several overloads) */
129 #if defined(isalnum)
130 # undef isalnum
131 # undef isalpha
132 # undef islower
133 # undef isspace
134 # undef isupper
135 # undef tolower
136 # undef toupper
137 #endif
138 
139 #if defined(copysign)
140 # undef copysign
141 #endif
142 
143 #if defined(_MSC_VER)
144 # if defined(PYBIND11_DEBUG_MARKER)
145 # define _DEBUG
146 # undef PYBIND11_DEBUG_MARKER
147 # endif
148 # pragma warning(pop)
149 #endif
150 
151 #include <cstddef>
152 #include <cstring>
153 #include <forward_list>
154 #include <vector>
155 #include <string>
156 #include <stdexcept>
157 #include <exception>
158 #include <unordered_set>
159 #include <unordered_map>
160 #include <memory>
161 #include <typeindex>
162 #include <type_traits>
163 
164 #if PY_MAJOR_VERSION >= 3
165 #define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr)
166 #define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check
167 #define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION
168 #define PYBIND11_BYTES_CHECK PyBytes_Check
169 #define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
170 #define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize
171 #define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize
172 #define PYBIND11_BYTES_AS_STRING PyBytes_AsString
173 #define PYBIND11_BYTES_SIZE PyBytes_Size
174 #define PYBIND11_LONG_CHECK(o) PyLong_Check(o)
175 #define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o)
176 #define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) o)
177 #define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) o)
178 #define PYBIND11_BYTES_NAME "bytes"
179 #define PYBIND11_STRING_NAME "str"
180 #define PYBIND11_SLICE_OBJECT PyObject
181 #define PYBIND11_FROM_STRING PyUnicode_FromString
182 #define PYBIND11_STR_TYPE ::pybind11::str
183 #define PYBIND11_BOOL_ATTR "__bool__"
184 #define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool)
185 // Providing a separate declaration to make Clang's -Wmissing-prototypes happy.
186 // See comment for PYBIND11_MODULE below for why this is marked "maybe unused".
187 #define PYBIND11_PLUGIN_IMPL(name) \
188  extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT PyObject *PyInit_##name(); \
189  extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()
190 
191 #else
192 #define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyMethod_New(ptr, nullptr, class_)
193 #define PYBIND11_INSTANCE_METHOD_CHECK PyMethod_Check
194 #define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyMethod_GET_FUNCTION
195 #define PYBIND11_BYTES_CHECK PyString_Check
196 #define PYBIND11_BYTES_FROM_STRING PyString_FromString
197 #define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyString_FromStringAndSize
198 #define PYBIND11_BYTES_AS_STRING_AND_SIZE PyString_AsStringAndSize
199 #define PYBIND11_BYTES_AS_STRING PyString_AsString
200 #define PYBIND11_BYTES_SIZE PyString_Size
201 #define PYBIND11_LONG_CHECK(o) (PyInt_Check(o) || PyLong_Check(o))
202 #define PYBIND11_LONG_AS_LONGLONG(o) (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o))
203 #define PYBIND11_LONG_FROM_SIGNED(o) PyInt_FromSsize_t((ssize_t) o) // Returns long if needed.
204 #define PYBIND11_LONG_FROM_UNSIGNED(o) PyInt_FromSize_t((size_t) o) // Returns long if needed.
205 #define PYBIND11_BYTES_NAME "str"
206 #define PYBIND11_STRING_NAME "unicode"
207 #define PYBIND11_SLICE_OBJECT PySliceObject
208 #define PYBIND11_FROM_STRING PyString_FromString
209 #define PYBIND11_STR_TYPE ::pybind11::bytes
210 #define PYBIND11_BOOL_ATTR "__nonzero__"
211 #define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_nonzero)
212 // Providing a separate PyInit decl to make Clang's -Wmissing-prototypes happy.
213 // See comment for PYBIND11_MODULE below for why this is marked "maybe unused".
214 #define PYBIND11_PLUGIN_IMPL(name) \
215  static PyObject *pybind11_init_wrapper(); \
216  extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT void init##name(); \
217  extern "C" PYBIND11_EXPORT void init##name() { \
218  (void)pybind11_init_wrapper(); \
219  } \
220  PyObject *pybind11_init_wrapper()
221 #endif
222 
223 #if PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03050200
224 extern "C" {
225  struct _Py_atomic_address { void *value; };
226  PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current;
227 }
228 #endif
229 
230 #define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code
231 #define PYBIND11_STRINGIFY(x) #x
232 #define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
233 #define PYBIND11_CONCAT(first, second) first##second
234 #define PYBIND11_ENSURE_INTERNALS_READY \
235  pybind11::detail::get_internals();
236 
237 #define PYBIND11_CHECK_PYTHON_VERSION \
238  { \
239  const char *compiled_ver = PYBIND11_TOSTRING(PY_MAJOR_VERSION) \
240  "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \
241  const char *runtime_ver = Py_GetVersion(); \
242  size_t len = std::strlen(compiled_ver); \
243  if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \
244  || (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \
245  PyErr_Format(PyExc_ImportError, \
246  "Python version mismatch: module was compiled for Python %s, " \
247  "but the interpreter version is incompatible: %s.", \
248  compiled_ver, runtime_ver); \
249  return nullptr; \
250  } \
251  }
252 
253 #define PYBIND11_CATCH_INIT_EXCEPTIONS \
254  catch (pybind11::error_already_set &e) { \
255  PyErr_SetString(PyExc_ImportError, e.what()); \
256  return nullptr; \
257  } catch (const std::exception &e) { \
258  PyErr_SetString(PyExc_ImportError, e.what()); \
259  return nullptr; \
260  } \
261 
262 
274 
277 #define PYBIND11_PLUGIN(name) \
278  PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
279  static PyObject *pybind11_init(); \
280  PYBIND11_PLUGIN_IMPL(name) { \
281  PYBIND11_CHECK_PYTHON_VERSION \
282  PYBIND11_ENSURE_INTERNALS_READY \
283  try { \
284  return pybind11_init(); \
285  } PYBIND11_CATCH_INIT_EXCEPTIONS \
286  } \
287  PyObject *pybind11_init()
288 
310 #define PYBIND11_MODULE(name, variable) \
311  PYBIND11_MAYBE_UNUSED \
312  static void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &); \
313  PYBIND11_PLUGIN_IMPL(name) { \
314  PYBIND11_CHECK_PYTHON_VERSION \
315  PYBIND11_ENSURE_INTERNALS_READY \
316  auto m = pybind11::module(PYBIND11_TOSTRING(name)); \
317  try { \
318  PYBIND11_CONCAT(pybind11_init_, name)(m); \
319  return m.ptr(); \
320  } PYBIND11_CATCH_INIT_EXCEPTIONS \
321  } \
322  void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable)
323 
324 
326 
327 using ssize_t = Py_ssize_t;
328 using size_t = std::size_t;
329 
337  automatic = 0,
338 
344 
350 
354  copy,
355 
360  move,
361 
367  reference,
368 
380 };
381 
383 
384 inline static constexpr int log2(size_t n, int k = 0) { return (n <= 1) ? k : log2(n >> 1, k + 1); }
385 
386 // Returns the size as a multiple of sizeof(void *), rounded up.
387 inline static constexpr size_t size_in_ptrs(size_t s) { return 1 + ((s - 1) >> log2(sizeof(void *))); }
388 
395 constexpr size_t instance_simple_holder_in_ptrs() {
396  static_assert(sizeof(std::shared_ptr<int>) >= sizeof(std::unique_ptr<int>),
397  "pybind assumes std::shared_ptrs are at least as big as std::unique_ptrs");
398  return size_in_ptrs(sizeof(std::shared_ptr<int>));
399 }
400 
401 // Forward declarations
402 struct type_info;
403 struct value_and_holder;
404 
408 };
409 
411 struct instance {
412  PyObject_HEAD
414  union {
415  void *simple_value_holder[1 + instance_simple_holder_in_ptrs()];
417  };
419  PyObject *weakrefs;
421  bool owned : 1;
445  bool simple_layout : 1;
447  bool simple_holder_constructed : 1;
449  bool simple_instance_registered : 1;
451  bool has_patients : 1;
452 
454  void allocate_layout();
455 
457  void deallocate_layout();
458 
462  value_and_holder get_value_and_holder(const type_info *find_type = nullptr, bool throw_if_missing = true);
463 
465  static constexpr uint8_t status_holder_constructed = 1;
466  static constexpr uint8_t status_instance_registered = 2;
467 };
468 
469 static_assert(std::is_standard_layout<instance>::value, "Internal error: `pybind11::detail::instance` is not standard layout!");
470 
472 #if defined(PYBIND11_CPP14) && (!defined(_MSC_VER) || _MSC_VER >= 1910)
473 using std::enable_if_t;
474 using std::conditional_t;
475 using std::remove_cv_t;
477 #else
478 template <bool B, typename T = void> using enable_if_t = typename std::enable_if<B, T>::type;
479 template <bool B, typename T, typename F> using conditional_t = typename std::conditional<B, T, F>::type;
480 template <typename T> using remove_cv_t = typename std::remove_cv<T>::type;
481 template <typename T> using remove_reference_t = typename std::remove_reference<T>::type;
482 #endif
483 
485 #if defined(PYBIND11_CPP14)
486 using std::index_sequence;
488 #else
489 template<size_t ...> struct index_sequence { };
490 template<size_t N, size_t ...S> struct make_index_sequence_impl : make_index_sequence_impl <N - 1, N - 1, S...> { };
491 template<size_t ...S> struct make_index_sequence_impl <0, S...> { typedef index_sequence<S...> type; };
492 template<size_t N> using make_index_sequence = typename make_index_sequence_impl<N>::type;
493 #endif
494 
496 template <typename ISeq, size_t, bool...> struct select_indices_impl { using type = ISeq; };
497 template <size_t... IPrev, size_t I, bool B, bool... Bs> struct select_indices_impl<index_sequence<IPrev...>, I, B, Bs...>
498  : select_indices_impl<conditional_t<B, index_sequence<IPrev..., I>, index_sequence<IPrev...>>, I + 1, Bs...> {};
499 template <bool... Bs> using select_indices = typename select_indices_impl<index_sequence<>, 0, Bs...>::type;
500 
502 template <bool B> using bool_constant = std::integral_constant<bool, B>;
503 template <typename T> struct negation : bool_constant<!T::value> { };
504 
505 // PGI cannot detect operator delete with the "compatible" void_t impl, so
506 // using the new one (C++14 defect, so generally works on newer compilers, even
507 // if not in C++17 mode)
508 #if defined(__PGIC__)
509 template<typename... > using void_t = void;
510 #else
511 template <typename...> struct void_t_impl { using type = void; };
512 template <typename... Ts> using void_t = typename void_t_impl<Ts...>::type;
513 #endif
514 
515 
517 #if defined(__cpp_fold_expressions) && !(defined(_MSC_VER) && (_MSC_VER < 1916))
518 template <class... Ts> using all_of = bool_constant<(Ts::value && ...)>;
519 template <class... Ts> using any_of = bool_constant<(Ts::value || ...)>;
520 #elif !defined(_MSC_VER)
521 template <bool...> struct bools {};
522 template <class... Ts> using all_of = std::is_same<
523  bools<Ts::value..., true>,
524  bools<true, Ts::value...>>;
525 template <class... Ts> using any_of = negation<all_of<negation<Ts>...>>;
526 #else
527 // MSVC has trouble with the above, but supports std::conjunction, which we can use instead (albeit
528 // at a slight loss of compilation efficiency).
529 template <class... Ts> using all_of = std::conjunction<Ts...>;
530 template <class... Ts> using any_of = std::disjunction<Ts...>;
531 #endif
532 template <class... Ts> using none_of = negation<any_of<Ts...>>;
533 
534 template <class T, template<class> class... Predicates> using satisfies_all_of = all_of<Predicates<T>...>;
535 template <class T, template<class> class... Predicates> using satisfies_any_of = any_of<Predicates<T>...>;
536 template <class T, template<class> class... Predicates> using satisfies_none_of = none_of<Predicates<T>...>;
537 
539 template <typename T> struct remove_class { };
540 template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...)> { using type = R (A...); };
541 template <typename C, typename R, typename... A> struct remove_class<R (C::*)(A...) const> { using type = R (A...); };
542 
544 template <typename T> struct intrinsic_type { using type = T; };
545 template <typename T> struct intrinsic_type<const T> { using type = typename intrinsic_type<T>::type; };
546 template <typename T> struct intrinsic_type<T*> { using type = typename intrinsic_type<T>::type; };
547 template <typename T> struct intrinsic_type<T&> { using type = typename intrinsic_type<T>::type; };
548 template <typename T> struct intrinsic_type<T&&> { using type = typename intrinsic_type<T>::type; };
549 template <typename T, size_t N> struct intrinsic_type<const T[N]> { using type = typename intrinsic_type<T>::type; };
550 template <typename T, size_t N> struct intrinsic_type<T[N]> { using type = typename intrinsic_type<T>::type; };
551 template <typename T> using intrinsic_t = typename intrinsic_type<T>::type;
552 
554 struct void_type { };
555 
557 template <typename...> struct type_list { };
558 
560 #ifdef __cpp_fold_expressions
561 template <typename... Ts> constexpr size_t constexpr_sum(Ts... ns) { return (0 + ... + size_t{ns}); }
562 #else
563 constexpr size_t constexpr_sum() { return 0; }
564 template <typename T, typename... Ts>
565 constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); }
566 #endif
567 
568 PYBIND11_NAMESPACE_BEGIN(constexpr_impl)
570 constexpr int first(int i) { return i; }
571 template <typename T, typename... Ts>
572 constexpr int first(int i, T v, Ts... vs) { return v ? i : first(i + 1, vs...); }
573 
574 constexpr int last(int /*i*/, int result) { return result; }
575 template <typename T, typename... Ts>
576 constexpr int last(int i, int result, T v, Ts... vs) { return last(i + 1, v ? i : result, vs...); }
577 PYBIND11_NAMESPACE_END(constexpr_impl)
578 
579 template <template<typename> class Predicate, typename... Ts>
583 
585 template <template<typename> class Predicate, typename... Ts>
586 constexpr int constexpr_last() { return constexpr_impl::last(0, -1, Predicate<Ts>::value...); }
587 
589 template <size_t N, typename T, typename... Ts>
590 struct pack_element { using type = typename pack_element<N - 1, Ts...>::type; };
591 template <typename T, typename... Ts>
592 struct pack_element<0, T, Ts...> { using type = T; };
593 
596 template <template<typename> class Predicate, typename Default, typename... Ts>
597 struct exactly_one {
598  static constexpr auto found = constexpr_sum(Predicate<Ts>::value...);
599  static_assert(found <= 1, "Found more than one type matching the predicate");
600 
601  static constexpr auto index = found ? constexpr_first<Predicate, Ts...>() : 0;
602  using type = conditional_t<found, typename pack_element<index, Ts...>::type, Default>;
603 };
604 template <template<typename> class P, typename Default>
605 struct exactly_one<P, Default> { using type = Default; };
606 
607 template <template<typename> class Predicate, typename Default, typename... Ts>
608 using exactly_one_t = typename exactly_one<Predicate, Default, Ts...>::type;
609 
611 template <typename T, typename... /*Us*/> struct deferred_type { using type = T; };
612 template <typename T, typename... Us> using deferred_t = typename deferred_type<T, Us...>::type;
613 
616 template <typename Base, typename Derived> using is_strict_base_of = bool_constant<
618 
621 template <typename Base, typename Derived> using is_accessible_base_of = bool_constant<
623 
624 template <template<typename...> class Base>
626  template <typename... Us> static std::true_type check(Base<Us...> *);
627  static std::false_type check(...);
628 };
629 
632 template <template<typename...> class Base, typename T>
633 #if !defined(_MSC_VER)
635 #else // MSVC2015 has trouble with decltype in template aliases
636 struct is_template_base_of : decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T>*)nullptr)) { };
637 #endif
638 
641 template <template<typename...> class Class, typename T>
642 struct is_instantiation : std::false_type { };
643 template <template<typename...> class Class, typename... Us>
644 struct is_instantiation<Class, Class<Us...>> : std::true_type { };
645 
648 
650 template <typename T, typename = void> struct is_input_iterator : std::false_type {};
651 template <typename T>
652 struct is_input_iterator<T, void_t<decltype(*std::declval<T &>()), decltype(++std::declval<T &>())>>
653  : std::true_type {};
654 
655 template <typename T> using is_function_pointer = bool_constant<
657 
658 template <typename F> struct strip_function_object {
660 };
661 
662 // Extracts the function signature from a function, function pointer or lambda.
663 template <typename Function, typename F = remove_reference_t<Function>>
666  F,
667  typename conditional_t<
669  std::remove_pointer<F>,
671  >::type
672 >;
673 
677 template <typename T> using is_lambda = satisfies_none_of<remove_reference_t<T>,
678  std::is_function, std::is_pointer, std::is_member_pointer>;
679 
681 inline void ignore_unused(const int *) { }
682 
684 #ifdef __cpp_fold_expressions
685 #define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...)
686 #else
687 using expand_side_effects = bool[];
688 #define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (void)pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
689 #endif
690 
692 
693 class builtin_exception : public std::runtime_error {
695 public:
696  using std::runtime_error::runtime_error;
698  virtual void set_error() const = 0;
699 };
700 
701 #define PYBIND11_RUNTIME_EXCEPTION(name, type) \
702  class name : public builtin_exception { public: \
703  using builtin_exception::builtin_exception; \
704  name() : name("") { } \
705  void set_error() const override { PyErr_SetString(type, what()); } \
706  };
707 
708 PYBIND11_RUNTIME_EXCEPTION(stop_iteration, PyExc_StopIteration)
709 PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError)
710 PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError)
711 PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError)
712 PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
713 PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError)
714 PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
715 PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError)
716 PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError)
717 
718 [[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const char *reason) { throw std::runtime_error(reason); }
719 [[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const std::string &reason) { throw std::runtime_error(reason); }
720 
721 template <typename T, typename SFINAE = void> struct format_descriptor { };
722 
724 // Returns the index of the given type in the type char array below, and in the list in numpy.h
725 // The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double;
726 // complex float,double,long double. Note that the long double types only participate when long
727 // double is actually longer than double (it isn't under MSVC).
728 // NB: not only the string below but also complex.h and numpy.h rely on this order.
729 template <typename T, typename SFINAE = void> struct is_fmt_numeric { static constexpr bool value = false; };
730 template <typename T> struct is_fmt_numeric<T, enable_if_t<std::is_arithmetic<T>::value>> {
731  static constexpr bool value = true;
732  static constexpr int index = std::is_same<T, bool>::value ? 0 : 1 + (
735 };
737 
738 template <typename T> struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> {
739  static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
740  static constexpr const char value[2] = { c, '\0' };
741  static std::string format() { return std::string(1, c); }
742 };
743 
744 #if !defined(PYBIND11_CPP17)
745 
746 template <typename T> constexpr const char format_descriptor<
748 
749 #endif
750 
752 struct error_scope {
753  PyObject *type, *value, *trace;
754  error_scope() { PyErr_Fetch(&type, &value, &trace); }
755  ~error_scope() { PyErr_Restore(type, value, trace); }
756 };
757 
759 struct nodelete { template <typename T> void operator()(T*) { } };
760 
762 template <typename... Args>
764  constexpr overload_cast_impl() {}; // NOLINT(modernize-use-equals-default): MSVC 2015 needs this
765 
766  template <typename Return>
767  constexpr auto operator()(Return (*pf)(Args...)) const noexcept
768  -> decltype(pf) { return pf; }
769 
770  template <typename Return, typename Class>
771  constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept
772  -> decltype(pmf) { return pmf; }
773 
774  template <typename Return, typename Class>
775  constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept
776  -> decltype(pmf) { return pmf; }
777 };
779 
780 // overload_cast requires variable templates: C++14
781 #if defined(PYBIND11_CPP14)
782 #define PYBIND11_OVERLOAD_CAST 1
783 template <typename... Args>
787 static constexpr detail::overload_cast_impl<Args...> overload_cast = {};
788 // MSVC 2015 only accepts this particular initialization syntax for this variable template.
789 #endif
790 
794 static constexpr auto const_ = std::true_type{};
795 
796 #if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails:
797 template <typename... Args> struct overload_cast {
799  "pybind11::overload_cast<...> requires compiling in C++14 mode");
800 };
801 #endif // overload_cast
802 
804 
805 // Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from
806 // any standard container (or C-style array) supporting std::begin/std::end, any singleton
807 // arithmetic type (if T is arithmetic), or explicitly constructible from an iterator pair.
808 template <typename T>
810  std::vector<T> v;
811 public:
812  any_container() = default;
813 
814  // Can construct from a pair of iterators
816  any_container(It first, It last) : v(first, last) { }
817 
818  // Implicit conversion constructor from any arbitrary container type with values convertible to T
819  template <typename Container, typename = enable_if_t<std::is_convertible<decltype(*std::begin(std::declval<const Container &>())), T>::value>>
820  any_container(const Container &c) : any_container(std::begin(c), std::end(c)) { }
821 
822  // initializer_list's aren't deducible, so don't get matched by the above template; we need this
823  // to explicitly allow implicit conversion from one:
825  any_container(const std::initializer_list<TIn> &c) : any_container(c.begin(), c.end()) { }
826 
827  // Avoid copying if given an rvalue vector of the correct type.
828  any_container(std::vector<T> &&v) : v(std::move(v)) { }
829 
830  // Moves the vector out of an rvalue any_container
831  operator std::vector<T> &&() && { return std::move(v); }
832 
833  // Dereferencing obtains a reference to the underlying vector
834  std::vector<T> &operator*() { return v; }
835  const std::vector<T> &operator*() const { return v; }
836 
837  // -> lets you call methods on the underlying vector
838  std::vector<T> *operator->() { return &v; }
839  const std::vector<T> *operator->() const { return &v; }
840 };
841 
843 
844 
845 
typename std::conditional< B, T, F >::type conditional_t
Helper template which holds a list of types.
unsigned char uint8_t
Definition: ms_stdint.h:83
void ignore_unused(const int *)
Ignore that a variable is unused in compiler warnings.
PyObject * weakrefs
Weak references.
constexpr int last(int, int result)
Helper template to strip away type modifiers.
any_container(const std::initializer_list< TIn > &c)
bool[] expand_side_effects
Apply a function over each element of a parameter pack.
constexpr size_t instance_simple_holder_in_ptrs()
typename std::remove_cv< T >::type remove_cv_t
ArrayXcf v
Definition: Cwise_arg.cpp:1
const std::vector< T > * operator->() const
int n
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
Rot2 R(Rot2::fromAngle(0.1))
Compile-time all/any/none of that check the boolean value of all template types.
Definition: Half.h:150
static constexpr size_t size_in_ptrs(size_t s)
bool_constant< std::is_base_of< Base, Derived >::value &&std::is_convertible< Derived *, Base * >::value > is_accessible_base_of
#define N
Definition: gksort.c:12
typename exactly_one< Predicate, Default, Ts... >::type exactly_one_t
constexpr auto operator()(Return(*pf)(Args...)) const noexcept-> decltype(pf)
Strip the class from a method type.
The &#39;instance&#39; type which needs to be standard layout (need to be able to use &#39;offsetof&#39;) ...
())>> bool_constant< std::is_pointer< T >::value &&std::is_function< typename std::remove_pointer< T >::type >::value > is_function_pointer
constexpr size_t constexpr_sum()
Compile-time integer sum.
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
PyExc_RuntimeError[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
static constexpr auto const_
all_of< Predicates< T >... > satisfies_all_of
typename select_indices_impl< index_sequence<>, 0, Bs... >::type select_indices
constexpr auto operator()(Return(Class::*pmf)(Args...), std::false_type={}) const noexcept-> decltype(pmf)
Signature::Row F
Definition: Signature.cpp:53
const std::vector< T > & operator*() const
bool_constant< std::is_base_of< Base, Derived >::value &&!std::is_same< Base, Derived >::value > is_strict_base_of
constexpr int first(int i)
Implementation details for constexpr functions.
Values result
Key S(std::uint64_t j)
std::integral_constant< bool, B > bool_constant
Backports of std::bool_constant and std::negation to accommodate older compilers. ...
Eigen::Triplet< double > T
RealScalar s
typename remove_class< decltype(&F::operator())>::type type
Make an index sequence of the indices of true arguments.
typename std::remove_reference< T >::type remove_reference_t
typename void_t_impl< Ts... >::type void_t
static const Matrix I
Definition: lago.cpp:35
Defer the evaluation of type T until types Us are instantiated.
Helper type to replace &#39;void&#39; in some expressions.
string::const_iterator It
Definition: Signature.cpp:35
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:37
constexpr int constexpr_last()
Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match...
void check(bool b, bool ref)
Definition: fastmath.cpp:12
decltype(is_template_base_of_impl< Base >::check((intrinsic_t< T > *) nullptr)) is_template_base_of
typename intrinsic_type< T >::type intrinsic_t
RAII wrapper that temporarily clears any Python error state.
constexpr auto operator()(Return(Class::*pmf)(Args...) const, std::true_type) const noexcept-> decltype(pmf)
std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... >> all_of
typename deferred_type< T, Us... >::type deferred_t
Dummy destructor wrapper that can be used to expose classes with a private destructor.
static constexpr int log2(size_t n, int k=0)
C++ bindings of builtin Python exceptions.
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
#define PYBIND11_RUNTIME_EXCEPTION(name, type)
Check if T looks like an input iterator.
typename make_index_sequence_impl< N >::type make_index_sequence
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
nonsimple_values_and_holders nonsimple
#define PYBIND11_NAMESPACE_END(name)
Definition: pytypes.h:897
#define PYBIND11_NAMESPACE_BEGIN(name)
Return the Nth element from the parameter pack.


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:48