Scarab  2.8.1
Project 8 C++ Utility Library
pybind11_tests.h
Go to the documentation of this file.
1 #pragma once
2 #include <pybind11/pybind11.h>
3 
4 #if defined(_MSC_VER) && _MSC_VER < 1910
5 // We get some really long type names here which causes MSVC 2015 to emit warnings
6 # pragma warning(disable: 4503) // warning C4503: decorated name length exceeded, name was truncated
7 #endif
8 
9 namespace py = pybind11;
10 using namespace pybind11::literals;
11 
13  using Initializer = void (*)(py::module &);
14 
15 public:
17  test_initializer(const char *submodule_name, Initializer init);
18 };
19 
20 #define TEST_SUBMODULE(name, variable) \
21  void test_submodule_##name(py::module &); \
22  test_initializer name(#name, test_submodule_##name); \
23  void test_submodule_##name(py::module &variable)
24 
25 
27 struct UnregisteredType { };
28 
30 class UserType {
31 public:
32  UserType() = default;
33  UserType(int i) : i(i) { }
34 
35  int value() const { return i; }
36  void set(int set) { i = set; }
37 
38 private:
39  int i = -1;
40 };
41 
43 class IncType : public UserType {
44 public:
45  using UserType::UserType;
46  IncType() = default;
47  IncType(const IncType &other) : IncType(other.value() + 1) { }
48  IncType(IncType &&) = delete;
49  IncType &operator=(const IncType &) = delete;
50  IncType &operator=(IncType &&) = delete;
51 };
52 
55 struct RValueCaster {};
57 NAMESPACE_BEGIN(detail)
58 template<> class type_caster<RValueCaster> {
59 public:
60  PYBIND11_TYPE_CASTER(RValueCaster, _("RValueCaster"));
61  static handle cast(RValueCaster &&, return_value_policy, handle) { return py::str("rvalue").release(); }
62  static handle cast(const RValueCaster &, return_value_policy, handle) { return py::str("lvalue").release(); }
63 };
64 NAMESPACE_END(detail)
Dummy type which is not exported anywhere – something to trigger a conversion error.
glibc defines I as a macro which breaks things, e.g., boost template names
Definition: attr.h:15
constexpr descr< N - 1 > _(char const(&text)[N])
Definition: descr.h:54
int value() const
Wrapper for Python extension modules.
Definition: pybind11.h:789
IncType(const IncType &other)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
Definition: pybind11.h:1371
#define NAMESPACE_END(name)
Definition: detail/common.h:16
static handle cast(const RValueCaster &, return_value_policy, handle)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
UserType()=default
void(*)(py::module &) Initializer
IncType()=default
return os str()
#define NAMESPACE_BEGIN(name)
Definition: detail/common.h:13
static handle cast(RValueCaster &&, return_value_policy, handle)
UserType(int i)
#define PYBIND11_TYPE_CASTER(type, py_name)
Definition: cast.h:942