cppyabm  1.0.17
An agent-based library to integrate C++ and Python
test_methods_and_attributes.cpp
Go to the documentation of this file.
1 /*
2  tests/test_methods_and_attributes.cpp -- constructors, deconstructors, attribute access,
3  __str__, argument and return value conventions
4 
5  Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
6 
7  All rights reserved. Use of this source code is governed by a
8  BSD-style license that can be found in the LICENSE file.
9 */
10 
11 #include "pybind11_tests.h"
12 #include "constructor_stats.h"
13 
14 #if !defined(PYBIND11_OVERLOAD_CAST)
15 template <typename... Args>
16 using overload_cast_ = pybind11::detail::overload_cast_impl<Args...>;
17 #endif
18 
19 class ExampleMandA {
20 public:
24  ExampleMandA(std::string&&) {}
27 
28  std::string toString() {
29  return "ExampleMandA[value=" + std::to_string(value) + "]";
30  }
31 
32  void operator=(const ExampleMandA &e) { print_copy_assigned(this); value = e.value; }
33  void operator=(ExampleMandA &&e) { print_move_assigned(this); value = e.value; }
34 
35  void add1(ExampleMandA other) { value += other.value; } // passing by value
36  void add2(ExampleMandA &other) { value += other.value; } // passing by reference
37  void add3(const ExampleMandA &other) { value += other.value; } // passing by const reference
38  void add4(ExampleMandA *other) { value += other->value; } // passing by pointer
39  void add5(const ExampleMandA *other) { value += other->value; } // passing by const pointer
40 
41  void add6(int other) { value += other; } // passing by value
42  void add7(int &other) { value += other; } // passing by reference
43  void add8(const int &other) { value += other; } // passing by const reference
44  void add9(int *other) { value += *other; } // passing by pointer
45  void add10(const int *other) { value += *other; } // passing by const pointer
46 
47  void consume_str(std::string&&) {}
48 
49  ExampleMandA self1() { return *this; } // return by value
50  ExampleMandA &self2() { return *this; } // return by reference
51  const ExampleMandA &self3() { return *this; } // return by const reference
52  ExampleMandA *self4() { return this; } // return by pointer
53  const ExampleMandA *self5() { return this; } // return by const pointer
54 
55  int internal1() { return value; } // return by value
56  int &internal2() { return value; } // return by reference
57  const int &internal3() { return value; } // return by const reference
58  int *internal4() { return &value; } // return by pointer
59  const int *internal5() { return &value; } // return by const pointer
60 
61  py::str overloaded() { return "()"; }
62  py::str overloaded(int) { return "(int)"; }
63  py::str overloaded(int, float) { return "(int, float)"; }
64  py::str overloaded(float, int) { return "(float, int)"; }
65  py::str overloaded(int, int) { return "(int, int)"; }
66  py::str overloaded(float, float) { return "(float, float)"; }
67  py::str overloaded(int) const { return "(int) const"; }
68  py::str overloaded(int, float) const { return "(int, float) const"; }
69  py::str overloaded(float, int) const { return "(float, int) const"; }
70  py::str overloaded(int, int) const { return "(int, int) const"; }
71  py::str overloaded(float, float) const { return "(float, float) const"; }
72 
73  static py::str overloaded(float) { return "static float"; }
74 
75  int value = 0;
76 };
77 
79  int value = 1;
80  static int static_value;
81 
82  int get() const { return value; }
83  void set(int v) { value = v; }
84 
85  static int static_get() { return static_value; }
86  static void static_set(int v) { static_value = v; }
87 };
89 
91  int value = 99;
92  static int static_value;
93 };
95 
96 struct TestPropRVP {
97  UserType v1{1};
98  UserType v2{1};
99  static UserType sv1;
100  static UserType sv2;
101 
102  const UserType &get1() const { return v1; }
103  const UserType &get2() const { return v2; }
104  UserType get_rvalue() const { return v2; }
105  void set1(int v) { v1.set(v); }
106  void set2(int v) { v2.set(v); }
107 };
108 UserType TestPropRVP::sv1(1);
109 UserType TestPropRVP::sv2(1);
110 
111 // Test None-allowed py::arg argument policy
112 class NoneTester { public: int answer = 42; };
113 int none1(const NoneTester &obj) { return obj.answer; }
114 int none2(NoneTester *obj) { return obj ? obj->answer : -1; }
115 int none3(std::shared_ptr<NoneTester> &obj) { return obj ? obj->answer : -1; }
116 int none4(std::shared_ptr<NoneTester> *obj) { return obj && *obj ? (*obj)->answer : -1; }
117 int none5(std::shared_ptr<NoneTester> obj) { return obj ? obj->answer : -1; }
118 
119 struct StrIssue {
120  int val = -1;
121 
122  StrIssue() = default;
123  StrIssue(int i) : val{i} {}
124 };
125 
126 // Issues #854, #910: incompatible function args when member function/pointer is in unregistered base class
128 public:
129  void do_nothing() const {}
130  void increase_value() { rw_value++; ro_value += 0.25; }
131  void set_int(int v) { rw_value = v; }
132  int get_int() const { return rw_value; }
133  double get_double() const { return ro_value; }
134  int rw_value = 42;
135  double ro_value = 1.25;
136 };
138 public:
139  using UnregisteredBase::UnregisteredBase;
140  double sum() const { return rw_value + ro_value; }
141 };
142 
143 // Test explicit lvalue ref-qualification
144 struct RefQualified {
145  int value = 0;
146 
147  void refQualified(int other) & { value += other; }
148  int constRefQualified(int other) const & { return value + other; }
149 };
150 
151 TEST_SUBMODULE(methods_and_attributes, m) {
152  // test_methods_and_attributes
153  py::class_<ExampleMandA> emna(m, "ExampleMandA");
154  emna.def(py::init<>())
155  .def(py::init<int>())
156  .def(py::init<std::string&&>())
157  .def(py::init<const ExampleMandA&>())
158  .def("add1", &ExampleMandA::add1)
159  .def("add2", &ExampleMandA::add2)
160  .def("add3", &ExampleMandA::add3)
161  .def("add4", &ExampleMandA::add4)
162  .def("add5", &ExampleMandA::add5)
163  .def("add6", &ExampleMandA::add6)
164  .def("add7", &ExampleMandA::add7)
165  .def("add8", &ExampleMandA::add8)
166  .def("add9", &ExampleMandA::add9)
167  .def("add10", &ExampleMandA::add10)
168  .def("consume_str", &ExampleMandA::consume_str)
169  .def("self1", &ExampleMandA::self1)
170  .def("self2", &ExampleMandA::self2)
171  .def("self3", &ExampleMandA::self3)
172  .def("self4", &ExampleMandA::self4)
173  .def("self5", &ExampleMandA::self5)
174  .def("internal1", &ExampleMandA::internal1)
175  .def("internal2", &ExampleMandA::internal2)
176  .def("internal3", &ExampleMandA::internal3)
177  .def("internal4", &ExampleMandA::internal4)
178  .def("internal5", &ExampleMandA::internal5)
179 #if defined(PYBIND11_OVERLOAD_CAST)
180  .def("overloaded", py::overload_cast<>(&ExampleMandA::overloaded))
181  .def("overloaded", py::overload_cast<int>(&ExampleMandA::overloaded))
182  .def("overloaded", py::overload_cast<int, float>(&ExampleMandA::overloaded))
183  .def("overloaded", py::overload_cast<float, int>(&ExampleMandA::overloaded))
184  .def("overloaded", py::overload_cast<int, int>(&ExampleMandA::overloaded))
185  .def("overloaded", py::overload_cast<float, float>(&ExampleMandA::overloaded))
186  .def("overloaded_float", py::overload_cast<float, float>(&ExampleMandA::overloaded))
187  .def("overloaded_const", py::overload_cast<int >(&ExampleMandA::overloaded, py::const_))
188  .def("overloaded_const", py::overload_cast<int, float>(&ExampleMandA::overloaded, py::const_))
189  .def("overloaded_const", py::overload_cast<float, int>(&ExampleMandA::overloaded, py::const_))
190  .def("overloaded_const", py::overload_cast<int, int>(&ExampleMandA::overloaded, py::const_))
191  .def("overloaded_const", py::overload_cast<float, float>(&ExampleMandA::overloaded, py::const_))
192 #else
193  // Use both the traditional static_cast method and the C++11 compatible overload_cast_
194  .def("overloaded", overload_cast_<>()(&ExampleMandA::overloaded))
195  .def("overloaded", overload_cast_<int>()(&ExampleMandA::overloaded))
197  .def("overloaded", static_cast<py::str (ExampleMandA::*)(float, int)>(&ExampleMandA::overloaded))
198  .def("overloaded", static_cast<py::str (ExampleMandA::*)(int, int)>(&ExampleMandA::overloaded))
199  .def("overloaded", static_cast<py::str (ExampleMandA::*)(float, float)>(&ExampleMandA::overloaded))
200  .def("overloaded_float", overload_cast_<float, float>()(&ExampleMandA::overloaded))
201  .def("overloaded_const", overload_cast_<int >()(&ExampleMandA::overloaded, py::const_))
202  .def("overloaded_const", overload_cast_<int, float>()(&ExampleMandA::overloaded, py::const_))
203  .def("overloaded_const", static_cast<py::str (ExampleMandA::*)(float, int) const>(&ExampleMandA::overloaded))
204  .def("overloaded_const", static_cast<py::str (ExampleMandA::*)(int, int) const>(&ExampleMandA::overloaded))
205  .def("overloaded_const", static_cast<py::str (ExampleMandA::*)(float, float) const>(&ExampleMandA::overloaded))
206 #endif
207  // test_no_mixed_overloads
208  // Raise error if trying to mix static/non-static overloads on the same name:
209  .def_static("add_mixed_overloads1", []() {
210  auto emna = py::reinterpret_borrow<py::class_<ExampleMandA>>(py::module_::import("pybind11_tests.methods_and_attributes").attr("ExampleMandA"));
211  emna.def ("overload_mixed1", static_cast<py::str (ExampleMandA::*)(int, int)>(&ExampleMandA::overloaded))
212  .def_static("overload_mixed1", static_cast<py::str ( *)(float )>(&ExampleMandA::overloaded));
213  })
214  .def_static("add_mixed_overloads2", []() {
215  auto emna = py::reinterpret_borrow<py::class_<ExampleMandA>>(py::module_::import("pybind11_tests.methods_and_attributes").attr("ExampleMandA"));
216  emna.def_static("overload_mixed2", static_cast<py::str ( *)(float )>(&ExampleMandA::overloaded))
217  .def ("overload_mixed2", static_cast<py::str (ExampleMandA::*)(int, int)>(&ExampleMandA::overloaded));
218  })
219  .def("__str__", &ExampleMandA::toString)
220  .def_readwrite("value", &ExampleMandA::value);
221 
222  // test_copy_method
223  // Issue #443: can't call copied methods in Python 3
224  emna.attr("add2b") = emna.attr("add2");
225 
226  // test_properties, test_static_properties, test_static_cls
227  py::class_<TestProperties>(m, "TestProperties")
228  .def(py::init<>())
229  .def_readonly("def_readonly", &TestProperties::value)
230  .def_readwrite("def_readwrite", &TestProperties::value)
231  .def_property("def_writeonly", nullptr,
232  [](TestProperties& s,int v) { s.value = v; } )
233  .def_property("def_property_writeonly", nullptr, &TestProperties::set)
234  .def_property_readonly("def_property_readonly", &TestProperties::get)
235  .def_property("def_property", &TestProperties::get, &TestProperties::set)
236  .def_property("def_property_impossible", nullptr, nullptr)
237  .def_readonly_static("def_readonly_static", &TestProperties::static_value)
238  .def_readwrite_static("def_readwrite_static", &TestProperties::static_value)
239  .def_property_static("def_writeonly_static", nullptr,
240  [](py::object, int v) { TestProperties::static_value = v; })
241  .def_property_readonly_static("def_property_readonly_static",
242  [](py::object) { return TestProperties::static_get(); })
243  .def_property_static("def_property_writeonly_static", nullptr,
244  [](py::object, int v) { return TestProperties::static_set(v); })
245  .def_property_static("def_property_static",
246  [](py::object) { return TestProperties::static_get(); },
247  [](py::object, int v) { TestProperties::static_set(v); })
248  .def_property_static("static_cls",
249  [](py::object cls) { return cls; },
250  [](py::object cls, py::function f) { f(cls); });
251 
252  py::class_<TestPropertiesOverride, TestProperties>(m, "TestPropertiesOverride")
253  .def(py::init<>())
254  .def_readonly("def_readonly", &TestPropertiesOverride::value)
255  .def_readonly_static("def_readonly_static", &TestPropertiesOverride::static_value);
256 
257  auto static_get1 = [](py::object) -> const UserType & { return TestPropRVP::sv1; };
258  auto static_get2 = [](py::object) -> const UserType & { return TestPropRVP::sv2; };
259  auto static_set1 = [](py::object, int v) { TestPropRVP::sv1.set(v); };
260  auto static_set2 = [](py::object, int v) { TestPropRVP::sv2.set(v); };
261  auto rvp_copy = py::return_value_policy::copy;
262 
263  // test_property_return_value_policies
264  py::class_<TestPropRVP>(m, "TestPropRVP")
265  .def(py::init<>())
266  .def_property_readonly("ro_ref", &TestPropRVP::get1)
267  .def_property_readonly("ro_copy", &TestPropRVP::get2, rvp_copy)
268  .def_property_readonly("ro_func", py::cpp_function(&TestPropRVP::get2, rvp_copy))
269  .def_property("rw_ref", &TestPropRVP::get1, &TestPropRVP::set1)
270  .def_property("rw_copy", &TestPropRVP::get2, &TestPropRVP::set2, rvp_copy)
271  .def_property("rw_func", py::cpp_function(&TestPropRVP::get2, rvp_copy), &TestPropRVP::set2)
272  .def_property_readonly_static("static_ro_ref", static_get1)
273  .def_property_readonly_static("static_ro_copy", static_get2, rvp_copy)
274  .def_property_readonly_static("static_ro_func", py::cpp_function(static_get2, rvp_copy))
275  .def_property_static("static_rw_ref", static_get1, static_set1)
276  .def_property_static("static_rw_copy", static_get2, static_set2, rvp_copy)
277  .def_property_static("static_rw_func", py::cpp_function(static_get2, rvp_copy), static_set2)
278  // test_property_rvalue_policy
279  .def_property_readonly("rvalue", &TestPropRVP::get_rvalue)
280  .def_property_readonly_static("static_rvalue", [](py::object) { return UserType(1); });
281 
282  // test_metaclass_override
283  struct MetaclassOverride { };
284  py::class_<MetaclassOverride>(m, "MetaclassOverride", py::metaclass((PyObject *) &PyType_Type))
285  .def_property_readonly_static("readonly", [](py::object) { return 1; });
286 
287  // test_overload_ordering
288  m.def("overload_order", [](std::string) { return 1; });
289  m.def("overload_order", [](std::string) { return 2; });
290  m.def("overload_order", [](int) { return 3; });
291  m.def("overload_order", [](int) { return 4; }, py::prepend{});
292 
293 #if !defined(PYPY_VERSION)
294  // test_dynamic_attributes
295  class DynamicClass {
296  public:
297  DynamicClass() { print_default_created(this); }
298  DynamicClass(const DynamicClass&) = delete;
299  ~DynamicClass() { print_destroyed(this); }
300  };
301  py::class_<DynamicClass>(m, "DynamicClass", py::dynamic_attr())
302  .def(py::init());
303 
304  class CppDerivedDynamicClass : public DynamicClass { };
305  py::class_<CppDerivedDynamicClass, DynamicClass>(m, "CppDerivedDynamicClass")
306  .def(py::init());
307 #endif
308 
309  // test_bad_arg_default
310  // Issue/PR #648: bad arg default debugging output
311 #if !defined(NDEBUG)
312  m.attr("debug_enabled") = true;
313 #else
314  m.attr("debug_enabled") = false;
315 #endif
316  m.def("bad_arg_def_named", []{
317  auto m = py::module_::import("pybind11_tests");
318  m.def("should_fail", [](int, UnregisteredType) {}, py::arg(), py::arg("a") = UnregisteredType());
319  });
320  m.def("bad_arg_def_unnamed", []{
321  auto m = py::module_::import("pybind11_tests");
322  m.def("should_fail", [](int, UnregisteredType) {}, py::arg(), py::arg() = UnregisteredType());
323  });
324 
325  // [workaround(intel)] ICC 20/21 breaks with py::arg().stuff, using py::arg{}.stuff works.
326 
327  // test_accepts_none
328  py::class_<NoneTester, std::shared_ptr<NoneTester>>(m, "NoneTester")
329  .def(py::init<>());
330  m.def("no_none1", &none1, py::arg{}.none(false));
331  m.def("no_none2", &none2, py::arg{}.none(false));
332  m.def("no_none3", &none3, py::arg{}.none(false));
333  m.def("no_none4", &none4, py::arg{}.none(false));
334  m.def("no_none5", &none5, py::arg{}.none(false));
335  m.def("ok_none1", &none1);
336  m.def("ok_none2", &none2, py::arg{}.none(true));
337  m.def("ok_none3", &none3);
338  m.def("ok_none4", &none4, py::arg{}.none(true));
339  m.def("ok_none5", &none5);
340 
341  m.def("no_none_kwarg", &none2, "a"_a.none(false));
342  m.def("no_none_kwarg_kw_only", &none2, py::kw_only(), "a"_a.none(false));
343 
344  // test_str_issue
345  // Issue #283: __str__ called on uninitialized instance when constructor arguments invalid
346  py::class_<StrIssue>(m, "StrIssue")
347  .def(py::init<int>())
348  .def(py::init<>())
349  .def("__str__", [](const StrIssue &si) {
350  return "StrIssue[" + std::to_string(si.val) + "]"; }
351  );
352 
353  // test_unregistered_base_implementations
354  //
355  // Issues #854/910: incompatible function args when member function/pointer is in unregistered
356  // base class The methods and member pointers below actually resolve to members/pointers in
357  // UnregisteredBase; before this test/fix they would be registered via lambda with a first
358  // argument of an unregistered type, and thus uncallable.
359  py::class_<RegisteredDerived>(m, "RegisteredDerived")
360  .def(py::init<>())
361  .def("do_nothing", &RegisteredDerived::do_nothing)
362  .def("increase_value", &RegisteredDerived::increase_value)
363  .def_readwrite("rw_value", &RegisteredDerived::rw_value)
364  .def_readonly("ro_value", &RegisteredDerived::ro_value)
365  // These should trigger a static_assert if uncommented
366  //.def_readwrite("fails", &UserType::value) // should trigger a static_assert if uncommented
367  //.def_readonly("fails", &UserType::value) // should trigger a static_assert if uncommented
368  .def_property("rw_value_prop", &RegisteredDerived::get_int, &RegisteredDerived::set_int)
369  .def_property_readonly("ro_value_prop", &RegisteredDerived::get_double)
370  // This one is in the registered class:
371  .def("sum", &RegisteredDerived::sum)
372  ;
373 
374  using Adapted = decltype(py::method_adaptor<RegisteredDerived>(&RegisteredDerived::do_nothing));
375  static_assert(std::is_same<Adapted, void (RegisteredDerived::*)() const>::value, "");
376 
377  // test_methods_and_attributes
378  py::class_<RefQualified>(m, "RefQualified")
379  .def(py::init<>())
380  .def_readonly("value", &RefQualified::value)
381  .def("refQualified", &RefQualified::refQualified)
382  .def("constRefQualified", &RefQualified::constRefQualified);
383 }
ExampleMandA::self1
ExampleMandA self1()
Definition: test_methods_and_attributes.cpp:49
RefQualified::refQualified
void refQualified(int other) &
Definition: test_methods_and_attributes.cpp:147
test_multiple_inheritance.i
i
Definition: test_multiple_inheritance.py:22
StrIssue::StrIssue
StrIssue()=default
ExampleMandA::overloaded
py::str overloaded(float, float)
Definition: test_methods_and_attributes.cpp:66
ExampleMandA::self3
const ExampleMandA & self3()
Definition: test_methods_and_attributes.cpp:51
TestPropertiesOverride::value
int value
Definition: test_methods_and_attributes.cpp:91
TestPropRVP::sv2
static UserType sv2
Definition: test_methods_and_attributes.cpp:100
ExampleMandA::ExampleMandA
ExampleMandA(std::string &&)
Definition: test_methods_and_attributes.cpp:24
ExampleMandA::internal4
int * internal4()
Definition: test_methods_and_attributes.cpp:58
ExampleMandA::overloaded
py::str overloaded(int)
Definition: test_methods_and_attributes.cpp:62
StrIssue
Definition: test_methods_and_attributes.cpp:119
ExampleMandA::overloaded
py::str overloaded(int, int) const
Definition: test_methods_and_attributes.cpp:70
ExampleMandA::add8
void add8(const int &other)
Definition: test_methods_and_attributes.cpp:43
TestProperties::static_set
static void static_set(int v)
Definition: test_methods_and_attributes.cpp:86
ExampleMandA::add4
void add4(ExampleMandA *other)
Definition: test_methods_and_attributes.cpp:38
TestPropRVP::v1
UserType v1
Definition: test_methods_and_attributes.cpp:97
StrIssue::StrIssue
StrIssue(int i)
Definition: test_methods_and_attributes.cpp:123
UnregisteredBase
Definition: test_methods_and_attributes.cpp:127
RegisteredDerived
Definition: test_methods_and_attributes.cpp:137
ExampleMandA::overloaded
py::str overloaded(int, float) const
Definition: test_methods_and_attributes.cpp:68
ExampleMandA::overloaded
py::str overloaded(int, float)
Definition: test_methods_and_attributes.cpp:63
ExampleMandA::ExampleMandA
ExampleMandA(ExampleMandA &&e)
Definition: test_methods_and_attributes.cpp:25
ExampleMandA::internal1
int internal1()
Definition: test_methods_and_attributes.cpp:55
def
int def()
Definition: test_ABM.cpp:4
none5
int none5(std::shared_ptr< NoneTester > obj)
Definition: test_methods_and_attributes.cpp:117
none3
int none3(std::shared_ptr< NoneTester > &obj)
Definition: test_methods_and_attributes.cpp:115
RefQualified
Definition: test_methods_and_attributes.cpp:144
ExampleMandA::consume_str
void consume_str(std::string &&)
Definition: test_methods_and_attributes.cpp:47
constructor_stats.h
TestPropRVP::get2
const UserType & get2() const
Definition: test_methods_and_attributes.cpp:103
ExampleMandA::overloaded
py::str overloaded(float, int) const
Definition: test_methods_and_attributes.cpp:69
ExampleMandA::toString
std::string toString()
Definition: test_methods_and_attributes.cpp:28
ExampleMandA::overloaded
py::str overloaded(int, int)
Definition: test_methods_and_attributes.cpp:65
ExampleMandA::operator=
void operator=(const ExampleMandA &e)
Definition: test_methods_and_attributes.cpp:32
TestPropRVP::set1
void set1(int v)
Definition: test_methods_and_attributes.cpp:105
ExampleMandA::self4
ExampleMandA * self4()
Definition: test_methods_and_attributes.cpp:52
ExampleMandA::self5
const ExampleMandA * self5()
Definition: test_methods_and_attributes.cpp:53
print_copy_created
void print_copy_created(T *inst, Values &&...values)
Definition: constructor_stats.h:244
ExampleMandA::internal5
const int * internal5()
Definition: test_methods_and_attributes.cpp:59
TestPropRVP::v2
UserType v2
Definition: test_methods_and_attributes.cpp:98
print_default_created
void print_default_created(T *inst, Values &&...values)
Definition: constructor_stats.h:260
TestProperties
Definition: test_methods_and_attributes.cpp:78
ExampleMandA::add5
void add5(const ExampleMandA *other)
Definition: test_methods_and_attributes.cpp:39
ExampleMandA::value
int value
Definition: test_methods_and_attributes.cpp:75
RefQualified::value
int value
Definition: test_methods_and_attributes.cpp:145
UnregisteredBase::do_nothing
void do_nothing() const
Definition: test_methods_and_attributes.cpp:129
ExampleMandA::add6
void add6(int other)
Definition: test_methods_and_attributes.cpp:41
TestPropRVP::get1
const UserType & get1() const
Definition: test_methods_and_attributes.cpp:102
ExampleMandA::ExampleMandA
ExampleMandA()
Definition: test_methods_and_attributes.cpp:21
ExampleMandA
Definition: test_methods_and_attributes.cpp:19
ExampleMandA::overloaded
static py::str overloaded(float)
Definition: test_methods_and_attributes.cpp:73
UnregisteredType
Dummy type which is not exported anywhere – something to trigger a conversion error.
Definition: pybind11_tests.h:28
ExampleMandA::internal2
int & internal2()
Definition: test_methods_and_attributes.cpp:56
print_copy_assigned
void print_copy_assigned(T *inst, Values &&...values)
Definition: constructor_stats.h:252
UnregisteredBase::get_int
int get_int() const
Definition: test_methods_and_attributes.cpp:132
ExampleMandA::add2
void add2(ExampleMandA &other)
Definition: test_methods_and_attributes.cpp:36
TestPropertiesOverride::static_value
static int static_value
Definition: test_methods_and_attributes.cpp:92
TestProperties::get
int get() const
Definition: test_methods_and_attributes.cpp:82
none2
int none2(NoneTester *obj)
Definition: test_methods_and_attributes.cpp:114
TestProperties::value
int value
Definition: test_methods_and_attributes.cpp:79
ExampleMandA::overloaded
py::str overloaded(int) const
Definition: test_methods_and_attributes.cpp:67
StrIssue::val
int val
Definition: test_methods_and_attributes.cpp:120
init
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
Definition: pybind11.h:1587
UnregisteredBase::increase_value
void increase_value()
Definition: test_methods_and_attributes.cpp:130
NoneTester
Definition: test_methods_and_attributes.cpp:112
TestProperties::set
void set(int v)
Definition: test_methods_and_attributes.cpp:83
TestPropertiesOverride
Definition: test_methods_and_attributes.cpp:90
ExampleMandA::self2
ExampleMandA & self2()
Definition: test_methods_and_attributes.cpp:50
NoneTester::answer
int answer
Definition: test_methods_and_attributes.cpp:112
TestProperties::static_value
static int static_value
Definition: test_methods_and_attributes.cpp:80
TestPropRVP::sv1
static UserType sv1
Definition: test_methods_and_attributes.cpp:99
ExampleMandA::overloaded
py::str overloaded(float, float) const
Definition: test_methods_and_attributes.cpp:71
UnregisteredBase::ro_value
double ro_value
Definition: test_methods_and_attributes.cpp:135
print_move_created
void print_move_created(T *inst, Values &&...values)
Definition: constructor_stats.h:248
TEST_SUBMODULE
TEST_SUBMODULE(methods_and_attributes, m)
Definition: test_methods_and_attributes.cpp:151
ExampleMandA::ExampleMandA
ExampleMandA(const ExampleMandA &e)
Definition: test_methods_and_attributes.cpp:23
pybind11_tests.h
ExampleMandA::ExampleMandA
ExampleMandA(int value)
Definition: test_methods_and_attributes.cpp:22
none1
int none1(const NoneTester &obj)
Definition: test_methods_and_attributes.cpp:113
print_destroyed
void print_destroyed(T *inst, Values &&...values)
Definition: constructor_stats.h:268
ExampleMandA::overloaded
py::str overloaded(float, int)
Definition: test_methods_and_attributes.cpp:64
ExampleMandA::add10
void add10(const int *other)
Definition: test_methods_and_attributes.cpp:45
RegisteredDerived::sum
double sum() const
Definition: test_methods_and_attributes.cpp:140
ExampleMandA::~ExampleMandA
~ExampleMandA()
Definition: test_methods_and_attributes.cpp:26
none4
int none4(std::shared_ptr< NoneTester > *obj)
Definition: test_methods_and_attributes.cpp:116
ExampleMandA::add7
void add7(int &other)
Definition: test_methods_and_attributes.cpp:42
TestPropRVP::get_rvalue
UserType get_rvalue() const
Definition: test_methods_and_attributes.cpp:104
print_move_assigned
void print_move_assigned(T *inst, Values &&...values)
Definition: constructor_stats.h:256
ExampleMandA::add9
void add9(int *other)
Definition: test_methods_and_attributes.cpp:44
ExampleMandA::add1
void add1(ExampleMandA other)
Definition: test_methods_and_attributes.cpp:35
UnregisteredBase::get_double
double get_double() const
Definition: test_methods_and_attributes.cpp:133
TestPropRVP::set2
void set2(int v)
Definition: test_methods_and_attributes.cpp:106
UnregisteredBase::rw_value
int rw_value
Definition: test_methods_and_attributes.cpp:134
test_async.m
m
Definition: test_async.py:5
ExampleMandA::add3
void add3(const ExampleMandA &other)
Definition: test_methods_and_attributes.cpp:37
UnregisteredBase::set_int
void set_int(int v)
Definition: test_methods_and_attributes.cpp:131
ExampleMandA::operator=
void operator=(ExampleMandA &&e)
Definition: test_methods_and_attributes.cpp:33
test_callbacks.value
value
Definition: test_callbacks.py:126
ExampleMandA::internal3
const int & internal3()
Definition: test_methods_and_attributes.cpp:57
print_created
void print_created(T *inst, Values &&...values)
Definition: constructor_stats.h:264
ExampleMandA::overloaded
py::str overloaded()
Definition: test_methods_and_attributes.cpp:61
TestProperties::static_get
static int static_get()
Definition: test_methods_and_attributes.cpp:85
RefQualified::constRefQualified
int constRefQualified(int other) const &
Definition: test_methods_and_attributes.cpp:148
TestPropRVP
Definition: test_methods_and_attributes.cpp:96
overload_cast_
pybind11::detail::overload_cast_impl< Args... > overload_cast_
Definition: test_methods_and_attributes.cpp:16