μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Macros | Typedefs | Enumerations | Functions | Variables
common.h File Reference
#include <Python.h>
#include <frameobject.h>
#include <pythread.h>
#include <cstddef>
#include <cstring>
#include <exception>
#include <forward_list>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#include <vector>
Include dependency graph for common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nonsimple_values_and_holders
 
struct  instance
 The 'instance' type which needs to be standard layout (need to be able to use 'offsetof') More...
 
struct  remove_cvref< T >
 
struct  index_sequence<... >
 Index sequences. More...
 
struct  make_index_sequence_impl< N, S >
 
struct  make_index_sequence_impl< 0, S... >
 
struct  select_indices_impl< ISeq, size_t,... >
 Make an index sequence of the indices of true arguments. More...
 
struct  select_indices_impl< index_sequence< IPrev... >, I, B, Bs... >
 
struct  negation< T >
 
struct  void_t_impl<... >
 
struct  bools<... >
 Compile-time all/any/none of that check the boolean value of all template types. More...
 
struct  remove_class< T >
 Strip the class from a method type. More...
 
struct  remove_class< R(C::*)(A...)>
 
struct  remove_class< R(C::*)(A...) const >
 
struct  intrinsic_type< T >
 Helper template to strip away type modifiers. More...
 
struct  intrinsic_type< const T >
 
struct  intrinsic_type< T * >
 
struct  intrinsic_type< T & >
 
struct  intrinsic_type< T && >
 
struct  intrinsic_type< const T[N]>
 
struct  intrinsic_type< T[N]>
 
struct  void_type
 Helper type to replace 'void' in some expressions. More...
 
struct  type_list<... >
 Helper template which holds a list of types. More...
 
struct  pack_element< N, T, Ts >
 Return the Nth element from the parameter pack. More...
 
struct  pack_element< 0, T, Ts... >
 
struct  exactly_one< Predicate, Default, Ts >
 Return the one and only type which matches the predicate, or Default if none match. More...
 
struct  exactly_one< P, Default >
 
struct  deferred_type< T,... >
 Defer the evaluation of type T until types Us are instantiated. More...
 
struct  is_template_base_of_impl< Base >
 
struct  is_instantiation< Class, T >
 Check if T is an instantiation of the template Class. More...
 
struct  is_instantiation< Class, Class< Us... > >
 
struct  is_input_iterator< T, typename >
 Check if T looks like an input iterator. More...
 
struct  is_input_iterator< T, void_t< decltype(*std::declval< T & >()), decltype(++std::declval< T & >())> >
 
struct  strip_function_object< F >
 
class  builtin_exception
 C++ bindings of builtin Python exceptions. More...
 
struct  format_descriptor< T, SFINAE >
 
struct  is_fmt_numeric< T, SFINAE >
 
struct  is_fmt_numeric< T, enable_if_t< std::is_arithmetic< T >::value > >
 
struct  format_descriptor< T, detail::enable_if_t< std::is_arithmetic< T >::value > >
 
struct  error_scope
 RAII wrapper that temporarily clears any Python error state. More...
 
struct  nodelete
 Dummy destructor wrapper that can be used to expose classes with a private destructor. More...
 
struct  overload_cast_impl< Args >
 
struct  overload_cast< Args >
 
class  any_container< T >
 

Macros

#define PYBIND11_VERSION_MAJOR   2
 
#define PYBIND11_VERSION_MINOR   9
 
#define PYBIND11_VERSION_PATCH   2
 
#define PYBIND11_VERSION_HEX   0x02090200
 
#define PYBIND11_NAMESPACE_BEGIN(name)   namespace name {
 
#define PYBIND11_NAMESPACE_END(name)   }
 
#define PYBIND11_NAMESPACE   pybind11
 
#define PYBIND11_EXPORT   __attribute__((visibility("default")))
 
#define PYBIND11_EXPORT_EXCEPTION   PYBIND11_EXPORT
 
#define PYBIND11_NOINLINE   __attribute__((noinline)) inline
 
#define PYBIND11_DEPRECATED(reason)   __attribute__((deprecated(reason)))
 
#define PYBIND11_MAYBE_UNUSED   __attribute__((__unused__))
 
#define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_)   PyMethod_New(ptr, nullptr, class_)
 Include Python header, disable linking to pythonX_d.lib on Windows in debug mode. More...
 
#define PYBIND11_INSTANCE_METHOD_CHECK   PyMethod_Check
 
#define PYBIND11_INSTANCE_METHOD_GET_FUNCTION   PyMethod_GET_FUNCTION
 
#define PYBIND11_BYTES_CHECK   PyString_Check
 
#define PYBIND11_BYTES_FROM_STRING   PyString_FromString
 
#define PYBIND11_BYTES_FROM_STRING_AND_SIZE   PyString_FromStringAndSize
 
#define PYBIND11_BYTES_AS_STRING_AND_SIZE   PyString_AsStringAndSize
 
#define PYBIND11_BYTES_AS_STRING   PyString_AsString
 
#define PYBIND11_BYTES_SIZE   PyString_Size
 
#define PYBIND11_LONG_CHECK(o)   (PyInt_Check(o) || PyLong_Check(o))
 
#define PYBIND11_LONG_AS_LONGLONG(o)    (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o))
 
#define PYBIND11_LONG_FROM_SIGNED(o)   PyInt_FromSsize_t((ssize_t) o)
 
#define PYBIND11_LONG_FROM_UNSIGNED(o)   PyInt_FromSize_t((size_t) o)
 
#define PYBIND11_BYTES_NAME   "str"
 
#define PYBIND11_STRING_NAME   "unicode"
 
#define PYBIND11_SLICE_OBJECT   PySliceObject
 
#define PYBIND11_FROM_STRING   PyString_FromString
 
#define PYBIND11_STR_TYPE   ::pybind11::bytes
 
#define PYBIND11_BOOL_ATTR   "__nonzero__"
 
#define PYBIND11_NB_BOOL(ptr)   ((ptr)->nb_nonzero)
 
#define PYBIND11_BUILTINS_MODULE   "__builtin__"
 
#define PYBIND11_PLUGIN_IMPL(name)
 
#define PYBIND11_TRY_NEXT_OVERLOAD   ((PyObject *) 1)
 
#define PYBIND11_STRINGIFY(x)   #x
 
#define PYBIND11_TOSTRING(x)   PYBIND11_STRINGIFY(x)
 
#define PYBIND11_CONCAT(first, second)   first##second
 
#define PYBIND11_ENSURE_INTERNALS_READY   pybind11::detail::get_internals();
 
#define PYBIND11_CHECK_PYTHON_VERSION
 
#define PYBIND11_CATCH_INIT_EXCEPTIONS
 
#define PYBIND11_PLUGIN(name)
 \rst Deprecated in favor of PYBIND11_MODULE*** More...
 
#define PYBIND11_MODULE(name, variable)
 \rst This macro creates the entry point that will be invoked when the Python interpreter imports an extension module. More...
 
#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN)    (void) pybind11::detail::expand_side_effects { ((PATTERN), void(), false)..., false }
 
#define PYBIND11_RUNTIME_EXCEPTION(name, type)
 
#define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
 
#define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
 
#define PYBIND11_SILENCE_MSVC_C4127(...)   __VA_ARGS__
 

Typedefs

using ssize_t = Py_ssize_t
 
using size_t = std::size_t
 
template<bool B, typename T = void>
using enable_if_t = typename std::enable_if< B, T >::type
 from cpp_future import (convenient aliases from C++14/17) More...
 
template<bool B, typename T , typename F >
using conditional_t = typename std::conditional< B, T, F >::type
 
template<typename T >
using remove_cv_t = typename std::remove_cv< T >::type
 
template<typename T >
using remove_reference_t = typename std::remove_reference< T >::type
 
template<class T >
using remove_cvref_t = typename remove_cvref< T >::type
 
template<size_t N>
using make_index_sequence = typename make_index_sequence_impl< N >::type
 
template<bool... Bs>
using select_indices = typename select_indices_impl< index_sequence<>, 0, Bs... >::type
 
template<bool B>
using bool_constant = std::integral_constant< bool, B >
 Backports of std::bool_constant and std::negation to accommodate older compilers. More...
 
template<typename... Ts>
using void_t = typename void_t_impl< Ts... >::type
 
template<class... Ts>
using all_of = std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... > >
 
template<class... Ts>
using any_of = negation< all_of< negation< Ts >... > >
 
template<class... Ts>
using none_of = negation< any_of< Ts... > >
 
template<class T , template< class > class... Predicates>
using satisfies_all_of = all_of< Predicates< T >... >
 
template<class T , template< class > class... Predicates>
using satisfies_any_of = any_of< Predicates< T >... >
 
template<class T , template< class > class... Predicates>
using satisfies_none_of = none_of< Predicates< T >... >
 
template<typename T >
using intrinsic_t = typename intrinsic_type< T >::type
 
template<template< typename > class Predicate, typename Default , typename... Ts>
using exactly_one_t = typename exactly_one< Predicate, Default, Ts... >::type
 
template<typename T , typename... Us>
using deferred_t = typename deferred_type< T, Us... >::type
 
template<typename Base , typename Derived >
using is_strict_base_of = bool_constant< std::is_base_of< Base, Derived >::value &&!std::is_same< Base, Derived >::value >
 Like is_base_of, but requires a strict base (i.e. More...
 
template<typename Base , typename Derived >
using 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 >
 Like is_base_of, but also requires that the base type is accessible (i.e. More...
 
template<template< typename... > class Base, typename T >
using is_template_base_of = decltype(is_template_base_of_impl< Base >::check((intrinsic_t< T > *) nullptr))
 Check if a template is the base of a type. More...
 
template<typename T >
using is_shared_ptr = is_instantiation< std::shared_ptr, T >
 Check if T is std::shared_ptr<U> where U can be anything. More...
 
template<typename T >
using is_function_pointer = bool_constant< std::is_pointer< T >::value &&std::is_function< typename std::remove_pointer< T >::type >::value >
 
template<typename Function , typename F = remove_reference_t<Function>>
using 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 >
 
template<typename T >
using is_lambda = satisfies_none_of< remove_reference_t< T >, std::is_function, std::is_pointer, std::is_member_pointer >
 Returns true if the type looks like a lambda: that is, isn't a function, pointer or member pointer. More...
 
using expand_side_effects = bool[]
 Apply a function over each element of a parameter pack. More...
 

Enumerations

enum class  return_value_policy : uint8_t {
  automatic = 0 , automatic_reference , take_ownership , copy ,
  move , reference , reference_internal , automatic = 0 ,
  automatic_reference , take_ownership , copy , move ,
  reference , reference_internal
}
 Approach used to cast a previously unknown C++ instance into a Python object. More...
 

Functions

template<typename IntType >
ssize_t ssize_t_cast (const IntType &val)
 
static constexpr int log2 (size_t n, int k=0)
 
static constexpr size_t size_in_ptrs (size_t s)
 
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 pointer (e.g. More...
 
constexpr size_t constexpr_sum ()
 Compile-time integer sum. More...
 
template<typename T , typename... Ts>
constexpr size_t constexpr_sum (T n, Ts... ns)
 
constexpr int first (int i)
 Implementation details for constexpr functions. More...
 
template<typename T , typename... Ts>
constexpr int first (int i, T v, Ts... vs)
 
constexpr int last (int, int result)
 
template<typename T , typename... Ts>
constexpr int last (int i, int result, T v, Ts... vs)
 
template<template< typename > class Predicate, typename... Ts>
constexpr int constexpr_first ()
 Return the index of the first type in Ts which satisfies Predicate<T>. More...
 
template<template< typename > class Predicate, typename... Ts>
constexpr int constexpr_last ()
 Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match. More...
 
PYBIND11_NOINLINE void pybind11_fail (const char *reason)
 Thrown when pybind11::cast or. More...
 
PYBIND11_NOINLINE void pybind11_fail (const std::string &reason)
 
std::string get_fully_qualified_tp_name (PyTypeObject *)
 
template<typename T >
static std::shared_ptr< T > try_get_shared_from_this (std::enable_shared_from_this< T > *holder_value_ptr)
 
template<typename... Args>
void silence_unused_warnings (Args &&...)
 

Variables

static constexpr auto const_ = std::true_type{}
 Const member function selector for overload_cast. More...
 

Macro Definition Documentation

◆ PYBIND11_BOOL_ATTR

#define PYBIND11_BOOL_ATTR   "__nonzero__"

Definition at line 321 of file common.h.

◆ PYBIND11_BUILTINS_MODULE

#define PYBIND11_BUILTINS_MODULE   "__builtin__"

Definition at line 323 of file common.h.

◆ PYBIND11_BYTES_AS_STRING

#define PYBIND11_BYTES_AS_STRING   PyString_AsString

Definition at line 309 of file common.h.

◆ PYBIND11_BYTES_AS_STRING_AND_SIZE

#define PYBIND11_BYTES_AS_STRING_AND_SIZE   PyString_AsStringAndSize

Definition at line 308 of file common.h.

◆ PYBIND11_BYTES_CHECK

#define PYBIND11_BYTES_CHECK   PyString_Check

Definition at line 305 of file common.h.

◆ PYBIND11_BYTES_FROM_STRING

#define PYBIND11_BYTES_FROM_STRING   PyString_FromString

Definition at line 306 of file common.h.

◆ PYBIND11_BYTES_FROM_STRING_AND_SIZE

#define PYBIND11_BYTES_FROM_STRING_AND_SIZE   PyString_FromStringAndSize

Definition at line 307 of file common.h.

◆ PYBIND11_BYTES_NAME

#define PYBIND11_BYTES_NAME   "str"

Definition at line 316 of file common.h.

◆ PYBIND11_BYTES_SIZE

#define PYBIND11_BYTES_SIZE   PyString_Size

Definition at line 310 of file common.h.

◆ PYBIND11_CATCH_INIT_EXCEPTIONS

#define PYBIND11_CATCH_INIT_EXCEPTIONS
Value:
catch (pybind11::error_already_set & e) { \
PyErr_SetString(PyExc_ImportError, e.what()); \
return nullptr; \
} \
catch (const std::exception &e) { \
PyErr_SetString(PyExc_ImportError, e.what()); \
return nullptr; \
}

Definition at line 379 of file common.h.

◆ PYBIND11_CHECK_PYTHON_VERSION

#define PYBIND11_CHECK_PYTHON_VERSION
Value:
{ \
const char *compiled_ver \
= PYBIND11_TOSTRING(PY_MAJOR_VERSION) "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \
const char *runtime_ver = Py_GetVersion(); \
size_t len = std::strlen(compiled_ver); \
if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \
|| (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \
PyErr_Format(PyExc_ImportError, \
"Python version mismatch: module was compiled for Python %s, " \
"but the interpreter version is incompatible: %s.", \
compiled_ver, \
runtime_ver); \
return nullptr; \
} \
}
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2002
#define PYBIND11_TOSTRING(x)
Definition: common.h:344

Definition at line 348 of file common.h.

◆ PYBIND11_CONCAT

#define PYBIND11_CONCAT (   first,
  second 
)    first##second

Definition at line 345 of file common.h.

◆ PYBIND11_DEPRECATED

#define PYBIND11_DEPRECATED (   reason)    __attribute__((deprecated(reason)))

Definition at line 139 of file common.h.

◆ PYBIND11_ENSURE_INTERNALS_READY

#define PYBIND11_ENSURE_INTERNALS_READY   pybind11::detail::get_internals();

Definition at line 346 of file common.h.

◆ PYBIND11_EXPAND_SIDE_EFFECTS

#define PYBIND11_EXPAND_SIDE_EFFECTS (   PATTERN)     (void) pybind11::detail::expand_side_effects { ((PATTERN), void(), false)..., false }

Definition at line 948 of file common.h.

◆ PYBIND11_EXPORT

#define PYBIND11_EXPORT   __attribute__((visibility("default")))

Definition at line 95 of file common.h.

◆ PYBIND11_EXPORT_EXCEPTION

#define PYBIND11_EXPORT_EXCEPTION   PYBIND11_EXPORT

Definition at line 106 of file common.h.

◆ PYBIND11_FROM_STRING

#define PYBIND11_FROM_STRING   PyString_FromString

Definition at line 319 of file common.h.

◆ PYBIND11_INSTANCE_METHOD_CHECK

#define PYBIND11_INSTANCE_METHOD_CHECK   PyMethod_Check

Definition at line 303 of file common.h.

◆ PYBIND11_INSTANCE_METHOD_GET_FUNCTION

#define PYBIND11_INSTANCE_METHOD_GET_FUNCTION   PyMethod_GET_FUNCTION

Definition at line 304 of file common.h.

◆ PYBIND11_INSTANCE_METHOD_NEW

#define PYBIND11_INSTANCE_METHOD_NEW (   ptr,
  class_ 
)    PyMethod_New(ptr, nullptr, class_)

Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.

Compatibility macros for various Python versions

Definition at line 302 of file common.h.

◆ PYBIND11_LONG_AS_LONGLONG

#define PYBIND11_LONG_AS_LONGLONG (   o)     (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o))

Definition at line 312 of file common.h.

◆ PYBIND11_LONG_CHECK

#define PYBIND11_LONG_CHECK (   o)    (PyInt_Check(o) || PyLong_Check(o))

Definition at line 311 of file common.h.

◆ PYBIND11_LONG_FROM_SIGNED

#define PYBIND11_LONG_FROM_SIGNED (   o)    PyInt_FromSsize_t((ssize_t) o)

Definition at line 314 of file common.h.

◆ PYBIND11_LONG_FROM_UNSIGNED

#define PYBIND11_LONG_FROM_UNSIGNED (   o)    PyInt_FromSize_t((size_t) o)

Definition at line 315 of file common.h.

◆ PYBIND11_MAYBE_UNUSED

#define PYBIND11_MAYBE_UNUSED   __attribute__((__unused__))

Definition at line 147 of file common.h.

◆ PYBIND11_MODULE

#define PYBIND11_MODULE (   name,
  variable 
)
Value:
static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name) \
PYBIND11_MAYBE_UNUSED \
static void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &); \
PYBIND11_PLUGIN_IMPL(name) { \
PYBIND11_CHECK_PYTHON_VERSION \
PYBIND11_ENSURE_INTERNALS_READY \
auto m = ::pybind11::module_::create_extension_module( \
PYBIND11_TOSTRING(name), nullptr, &PYBIND11_CONCAT(pybind11_module_def_, name)); \
try { \
PYBIND11_CONCAT(pybind11_init_, name)(m); \
return m.ptr(); \
} \
} \
void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ & (variable))
@ variable
Variable width.
#define PYBIND11_CATCH_INIT_EXCEPTIONS
Definition: common.h:379
#define PYBIND11_CONCAT(first, second)
Definition: common.h:345
#define PYBIND11_MAYBE_UNUSED
Definition: common.h:147
Annotation for function names.
Definition: attr.h:47

\rst This macro creates the entry point that will be invoked when the Python interpreter imports an extension module.

The module name is given as the fist argument and it should not be in quotes. The second macro argument defines a variable of type py::module_ which can be used to initialize the module.

The entry point is marked as "maybe unused" to aid dead-code detection analysis: since the entry point is typically only looked up at runtime and not referenced during translation, it would otherwise appear as unused ("dead") code.

.. code-block:: cpp

PYBIND11_MODULE(example, m) {
    m.doc() = "pybind11 example module";

Add bindings here m.def("foo", []() { return "Hello, World!"; }); } \endrst

Definition at line 440 of file common.h.

◆ PYBIND11_NAMESPACE

#define PYBIND11_NAMESPACE   pybind11

Definition at line 30 of file common.h.

◆ PYBIND11_NAMESPACE_BEGIN

#define PYBIND11_NAMESPACE_BEGIN (   name)    namespace name {

Definition at line 20 of file common.h.

◆ PYBIND11_NAMESPACE_END

#define PYBIND11_NAMESPACE_END (   name)    }

Definition at line 21 of file common.h.

◆ PYBIND11_NB_BOOL

#define PYBIND11_NB_BOOL (   ptr)    ((ptr)->nb_nonzero)

Definition at line 322 of file common.h.

◆ PYBIND11_NOINLINE

#define PYBIND11_NOINLINE   __attribute__((noinline)) inline

Definition at line 129 of file common.h.

◆ PYBIND11_PLUGIN

#define PYBIND11_PLUGIN (   name)
Value:
PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
static PyObject *pybind11_init(); \
PYBIND11_PLUGIN_IMPL(name) { \
PYBIND11_CHECK_PYTHON_VERSION \
PYBIND11_ENSURE_INTERNALS_READY \
try { \
return pybind11_init(); \
} \
} \
PyObject *pybind11_init()
#define PYBIND11_DEPRECATED(reason)
Definition: common.h:139

\rst Deprecated in favor of PYBIND11_MODULE***

This macro creates the entry point that will be invoked when the Python interpreter imports a plugin library. Please create a module_ in the function body and return the pointer to its underlying Python object at the end.

.. code-block:: cpp

PYBIND11_PLUGIN(example) {
    pybind11::module_ m("example", "pybind11 example plugin");

/ Set up bindings here return m.ptr(); } \endrst

Definition at line 406 of file common.h.

◆ PYBIND11_PLUGIN_IMPL

#define PYBIND11_PLUGIN_IMPL (   name)
Value:
static PyObject *pybind11_init_wrapper(); \
extern "C" PYBIND11_EXPORT void init##name() { (void) pybind11_init_wrapper(); } \
PyObject *pybind11_init_wrapper()
#define PYBIND11_EXPORT
Definition: common.h:95
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
Definition: pybind11.h:1900

Definition at line 326 of file common.h.

◆ PYBIND11_RUNTIME_EXCEPTION

#define PYBIND11_RUNTIME_EXCEPTION (   name,
  type 
)
Value:
public: \
using builtin_exception::builtin_exception; \
name() : name("") {} \
void set_error() const override { PyErr_SetString(type, what()); } \
};
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
#define PYBIND11_EXPORT_EXCEPTION
Definition: common.h:106

Definition at line 971 of file common.h.

◆ PYBIND11_SILENCE_MSVC_C4127

#define PYBIND11_SILENCE_MSVC_C4127 (   ...)    __VA_ARGS__

Definition at line 1206 of file common.h.

◆ PYBIND11_SLICE_OBJECT

#define PYBIND11_SLICE_OBJECT   PySliceObject

Definition at line 318 of file common.h.

◆ PYBIND11_STR_TYPE

#define PYBIND11_STR_TYPE   ::pybind11::bytes

Definition at line 320 of file common.h.

◆ PYBIND11_STRING_NAME

#define PYBIND11_STRING_NAME   "unicode"

Definition at line 317 of file common.h.

◆ PYBIND11_STRINGIFY

#define PYBIND11_STRINGIFY (   x)    #x

Definition at line 343 of file common.h.

◆ PYBIND11_TOSTRING

#define PYBIND11_TOSTRING (   x)    PYBIND11_STRINGIFY(x)

Definition at line 344 of file common.h.

◆ PYBIND11_TRY_NEXT_OVERLOAD

#define PYBIND11_TRY_NEXT_OVERLOAD   ((PyObject *) 1)

Definition at line 342 of file common.h.

◆ PYBIND11_VERSION_HEX

#define PYBIND11_VERSION_HEX   0x02090200

Definition at line 18 of file common.h.

◆ PYBIND11_VERSION_MAJOR

#define PYBIND11_VERSION_MAJOR   2

Definition at line 12 of file common.h.

◆ PYBIND11_VERSION_MINOR

#define PYBIND11_VERSION_MINOR   9

Definition at line 13 of file common.h.

◆ PYBIND11_VERSION_PATCH

#define PYBIND11_VERSION_PATCH   2

Definition at line 14 of file common.h.

◆ PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER

#define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER (   ...)

Definition at line 1195 of file common.h.

◆ PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100

#define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100 (   ...)

Definition at line 1187 of file common.h.

Typedef Documentation

◆ all_of

template<class... Ts>
using all_of = std::is_same<bools<Ts::value..., true>, bools<true, Ts::value...> >

Definition at line 707 of file common.h.

◆ any_of

template<class... Ts>
using any_of = negation<all_of<negation<Ts>...> >

Definition at line 709 of file common.h.

◆ bool_constant

template<bool B>
using bool_constant = std::integral_constant<bool, B>

Backports of std::bool_constant and std::negation to accommodate older compilers.

Definition at line 678 of file common.h.

◆ conditional_t

template<bool B, typename T , typename F >
using conditional_t = typename std::conditional<B, T, F>::type

Definition at line 627 of file common.h.

◆ deferred_t

template<typename T , typename... Us>
using deferred_t = typename deferred_type<T, Us...>::type

Definition at line 855 of file common.h.

◆ enable_if_t

template<bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type

from cpp_future import (convenient aliases from C++14/17)

Definition at line 625 of file common.h.

◆ exactly_one_t

template<template< typename > class Predicate, typename Default , typename... Ts>
using exactly_one_t = typename exactly_one<Predicate, Default, Ts...>::type

Definition at line 847 of file common.h.

◆ expand_side_effects

using expand_side_effects = bool[]

Apply a function over each element of a parameter pack.

Definition at line 947 of file common.h.

◆ function_signature_t

template<typename Function , typename F = remove_reference_t<Function>>
using 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>

Definition at line 925 of file common.h.

◆ intrinsic_t

template<typename T >
using intrinsic_t = typename intrinsic_type<T>::type

Definition at line 770 of file common.h.

◆ is_accessible_base_of

template<typename Base , typename Derived >
using 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>

Like is_base_of, but also requires that the base type is accessible (i.e.

that a Derived pointer can be converted to a Base pointer) For unions, is_base_of<T, T>::value is False, so we need to check is_same as well.

Definition at line 867 of file common.h.

◆ is_function_pointer

template<typename T >
using is_function_pointer = bool_constant<std::is_pointer<T>::value && std::is_function<typename std::remove_pointer<T>::type>::value>

Definition at line 910 of file common.h.

◆ is_lambda

template<typename T >
using is_lambda = satisfies_none_of<remove_reference_t<T>, std::is_function, std::is_pointer, std::is_member_pointer>

Returns true if the type looks like a lambda: that is, isn't a function, pointer or member pointer.

Note that this can catch all sorts of other things, too; this is intended to be used in a place where passing a lambda makes sense.

Definition at line 936 of file common.h.

◆ is_shared_ptr

template<typename T >
using is_shared_ptr = is_instantiation<std::shared_ptr, T>

Check if T is std::shared_ptr<U> where U can be anything.

Definition at line 899 of file common.h.

◆ is_strict_base_of

template<typename Base , typename Derived >
using is_strict_base_of = bool_constant<std::is_base_of<Base, Derived>::value && !std::is_same<Base, Derived>::value>

Like is_base_of, but requires a strict base (i.e.

is_strict_base_of<T, T>::value == false, unlike std::is_base_of)

Definition at line 860 of file common.h.

◆ is_template_base_of

template<template< typename... > class Base, typename T >
using is_template_base_of = decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr))

Check if a template is the base of a type.

For example: is_template_base_of<Base, T> is true if struct T : Base<U> {} where U can be anything

Definition at line 882 of file common.h.

◆ make_index_sequence

Definition at line 660 of file common.h.

◆ none_of

template<class... Ts>
using none_of = negation<any_of<Ts...> >

Definition at line 719 of file common.h.

◆ remove_cv_t

template<typename T >
using remove_cv_t = typename std::remove_cv<T>::type

Definition at line 629 of file common.h.

◆ remove_cvref_t

template<class T >
using remove_cvref_t = typename remove_cvref<T>::type

Definition at line 643 of file common.h.

◆ remove_reference_t

template<typename T >
using remove_reference_t = typename std::remove_reference<T>::type

Definition at line 631 of file common.h.

◆ satisfies_all_of

template<class T , template< class > class... Predicates>
using satisfies_all_of = all_of<Predicates<T>...>

Definition at line 722 of file common.h.

◆ satisfies_any_of

template<class T , template< class > class... Predicates>
using satisfies_any_of = any_of<Predicates<T>...>

Definition at line 724 of file common.h.

◆ satisfies_none_of

template<class T , template< class > class... Predicates>
using satisfies_none_of = none_of<Predicates<T>...>

Definition at line 726 of file common.h.

◆ select_indices

template<bool... Bs>
using select_indices = typename select_indices_impl<index_sequence<>, 0, Bs...>::type

Definition at line 674 of file common.h.

◆ size_t

using size_t = std::size_t

Definition at line 461 of file common.h.

◆ ssize_t

using ssize_t = Py_ssize_t

Definition at line 460 of file common.h.

◆ void_t

template<typename... Ts>
using void_t = typename void_t_impl<Ts...>::type

Definition at line 694 of file common.h.

Enumeration Type Documentation

◆ return_value_policy

enum class return_value_policy : uint8_t
strong

Approach used to cast a previously unknown C++ instance into a Python object.

Enumerator
automatic 

This is the default return value policy, which falls back to the policy return_value_policy::take_ownership when the return value is a pointer.

Otherwise, it uses return_value::move or return_value::copy for rvalue and lvalue references, respectively. See below for a description of what all of these different policies do.

automatic_reference 

As above, but use policy return_value_policy::reference when the return value is a pointer.

This is the default conversion policy for function arguments when calling Python functions manually from C++ code (i.e. via handle::operator()). You probably won't need to use this.

take_ownership 

Reference an existing object (i.e.

do not create a new copy) and take ownership. Python will call the destructor and delete operator when the object’s reference count reaches zero. Undefined behavior ensues when the C++ side does the same..

copy 

Create a new copy of the returned object, which will be owned by Python.

This policy is comparably safe because the lifetimes of the two instances are decoupled.

move 

Use std::move to move the return value contents into a new instance that will be owned by Python.

This policy is comparably safe because the lifetimes of the two instances (move source and destination) are decoupled.

reference 

Reference an existing object, but do not take ownership.

The C++ side is responsible for managing the object’s lifetime and deallocating it when it is no longer used. Warning: undefined behavior will ensue when the C++ side deletes an object that is still referenced and used by Python.

reference_internal 

This policy only applies to methods and properties.

It references the object without taking ownership similar to the above return_value_policy::reference policy. In contrast to that policy, the function or property’s implicit this argument (called the parent) is considered to be the the owner of the return value (the child). pybind11 then couples the lifetime of the parent to the child via a reference relationship that ensures that the parent cannot be garbage collected while Python is still using the child. More advanced variations of this scheme are also possible using combinations of return_value_policy::reference and the keep_alive call policy

automatic 

This is the default return value policy, which falls back to the policy return_value_policy::take_ownership when the return value is a pointer.

Otherwise, it uses return_value::move or return_value::copy for rvalue and lvalue references, respectively. See below for a description of what all of these different policies do.

automatic_reference 

As above, but use policy return_value_policy::reference when the return value is a pointer.

This is the default conversion policy for function arguments when calling Python functions manually from C++ code (i.e. via handle::operator()). You probably won't need to use this.

take_ownership 

Reference an existing object (i.e.

do not create a new copy) and take ownership. Python will call the destructor and delete operator when the object's reference count reaches zero. Undefined behavior ensues when the C++ side does the same..

copy 

Create a new copy of the returned object, which will be owned by Python.

This policy is comparably safe because the lifetimes of the two instances are decoupled.

move 

Use std::move to move the return value contents into a new instance that will be owned by Python.

This policy is comparably safe because the lifetimes of the two instances (move source and destination) are decoupled.

reference 

Reference an existing object, but do not take ownership.

The C++ side is responsible for managing the object's lifetime and deallocating it when it is no longer used. Warning: undefined behavior will ensue when the C++ side deletes an object that is still referenced and used by Python.

reference_internal 

This policy only applies to methods and properties.

It references the object without taking ownership similar to the above return_value_policy::reference policy. In contrast to that policy, the function or property's implicit this argument (called the parent) is considered to be the the owner of the return value (the child). pybind11 then couples the lifetime of the parent to the child via a reference relationship that ensures that the parent cannot be garbage collected while Python is still using the child. More advanced variations of this scheme are also possible using combinations of return_value_policy::reference and the keep_alive call policy

Definition at line 470 of file common.h.

Function Documentation

◆ constexpr_first()

template<template< typename > class Predicate, typename... Ts>
constexpr int constexpr_first ( )
constexpr

Return the index of the first type in Ts which satisfies Predicate<T>.

Returns sizeof...(Ts) if none match.

Definition at line 811 of file common.h.

Referenced by cpp_function::initialize().

◆ constexpr_last()

template<template< typename > class Predicate, typename... Ts>
constexpr int constexpr_last ( )
constexpr

Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.

Definition at line 817 of file common.h.

Referenced by collect_arguments().

◆ constexpr_sum() [1/2]

constexpr size_t constexpr_sum ( )
constexpr

Compile-time integer sum.

Definition at line 786 of file common.h.

Referenced by class_< type_, options >::class_(), constexpr_sum(), and cpp_function::initialize().

◆ constexpr_sum() [2/2]

template<typename T , typename... Ts>
constexpr size_t constexpr_sum ( n,
Ts...  ns 
)
constexpr

Definition at line 788 of file common.h.

References constexpr_sum().

◆ first() [1/2]

constexpr int first ( int  i)
constexpr

◆ first() [2/2]

template<typename T , typename... Ts>
constexpr int first ( int  i,
v,
Ts...  vs 
)
constexpr

Definition at line 797 of file common.h.

References first().

◆ get_fully_qualified_tp_name()

std::string get_fully_qualified_tp_name ( PyTypeObject *  type)
inline

Definition at line 28 of file class.h.

◆ instance_simple_holder_in_ptrs()

constexpr size_t instance_simple_holder_in_ptrs ( )
constexpr

The space to allocate for simple layout instance holders (see below) in multiple of the size of a pointer (e.g.

2 means 16 bytes on 64-bit architectures). The default is the minimum required to holder either a std::unique_ptr or std::shared_ptr (which is almost always sizeof(std::shared_ptr<T>)).

Definition at line 538 of file common.h.

References size_in_ptrs().

◆ last() [1/2]

template<typename T , typename... Ts>
constexpr int last ( int  i,
int  result,
v,
Ts...  vs 
)
constexpr

Definition at line 803 of file common.h.

References last().

◆ last() [2/2]

constexpr int last ( int  ,
int  result 
)
constexpr

◆ log2()

static constexpr int log2 ( size_t  n,
int  k = 0 
)
inlinestaticconstexpr

Definition at line 523 of file common.h.

References log2().

Referenced by log2(), and size_in_ptrs().

◆ pybind11_fail() [1/2]

PYBIND11_NOINLINE void pybind11_fail ( const char *  reason)

Thrown when pybind11::cast or.

handle::call fail due to a type casting error Used internally

Definition at line 992 of file common.h.

Referenced by type_record::add_base(), module_::add_object(), array::array(), broadcast(), buffer_info::buffer_info(), bytearray::bytearray(), bytes::bytes(), eigen_map_caster< MapType >::cast(), type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast(), type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast_impl(), type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::cast_impl(), cast_ref(), cast_safe(), check_kw_only_arg(), clear_instance(), module_::create_extension_module(), cpp_function::dispatcher(), npy_format_descriptor< T, enable_if_t< satisfies_any_of< T, std::is_arithmetic, is_complex >::value > >::dtype(), embedded_module::embedded_module(), error_fetch_and_normalize::error_fetch_and_normalize(), eval(), eval_file(), exception< type >::exception(), float_::float_(), memoryview::from_memory(), get_internals(), numpy_internals::get_type_info(), get_type_info(), implicitly_convertible(), process_attribute< arg_v >::init(), process_attribute< kw_only >::init(), process_attribute< pos_only >::init(), generic_type::initialize(), cpp_function::initialize_generic(), initialize_interpreter(), generic_type::install_buffer_funcs(), int_::int_(), keep_alive_impl(), list::list(), string_caster< StringType, IsView >::load_raw(), npy_api::lookup(), make_default_metaclass(), make_new_python_type(), make_object_base_type(), make_static_property_type(), memoryview::memoryview(), str::operator std::string(), bytes::operator std::string(), object_api< Derived >::operator()(), precheck_interpreter(), register_structured_dtype(), error_fetch_and_normalize::restore(), slice::slice(), str::str(), tuple::tuple(), and loader_life_support::~loader_life_support().

◆ pybind11_fail() [2/2]

PYBIND11_NOINLINE void pybind11_fail ( const std::string &  reason)

Definition at line 995 of file common.h.

◆ silence_unused_warnings()

template<typename... Args>
void silence_unused_warnings ( Args &&  ...)
inline

Definition at line 1179 of file common.h.

◆ size_in_ptrs()

static constexpr size_t size_in_ptrs ( size_t  s)
inlinestaticconstexpr

Definition at line 528 of file common.h.

References log2().

Referenced by generic_type::initialize(), and instance_simple_holder_in_ptrs().

◆ ssize_t_cast()

template<typename IntType >
ssize_t ssize_t_cast ( const IntType &  val)
inline

◆ try_get_shared_from_this()

template<typename T >
static std::shared_ptr< T > try_get_shared_from_this ( std::enable_shared_from_this< T > *  holder_value_ptr)
inlinestatic

Definition at line 1157 of file common.h.

Variable Documentation

◆ const_

constexpr auto const_ = std::true_type{}
staticconstexpr

Const member function selector for overload_cast.

  • regular: static_cast<Return (Class::*)(Arg) const>(&Class::func)
  • sweet: overload_cast<Arg>(&Class::func, const_)

Definition at line 1095 of file common.h.