test_class.cpp
Go to the documentation of this file.
1 /*
2  tests/test_class.cpp -- test py::class_ definitions and basic functionality
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 #if defined(__INTEL_COMPILER) && __cplusplus >= 201703L
11 // Intel compiler requires a separate header file to support aligned new operators
12 // and does not set the __cpp_aligned_new feature macro.
13 // This header needs to be included before pybind11.
14 # include <aligned_new>
15 #endif
16 
17 #include <pybind11/stl.h>
18 
19 #include "constructor_stats.h"
20 #include "local_bindings.h"
21 #include "pybind11_tests.h"
22 
23 #include <utility>
24 
25 #if defined(_MSC_VER)
26 # pragma warning(disable : 4324)
27 // warning C4324: structure was padded due to alignment specifier
28 #endif
29 
30 // test_brace_initialization
32  explicit NoBraceInitialization(std::vector<int> v) : vec{std::move(v)} {}
33  template <typename T>
34  NoBraceInitialization(std::initializer_list<T> l) : vec(l) {}
35 
36  std::vector<int> vec;
37 };
38 
39 TEST_SUBMODULE(class_, m) {
40  // test_instance
41  struct NoConstructor {
42  NoConstructor() = default;
43  NoConstructor(const NoConstructor &) = default;
44  NoConstructor(NoConstructor &&) = default;
45  static NoConstructor *new_instance() {
46  auto *ptr = new NoConstructor();
47  print_created(ptr, "via new_instance");
48  return ptr;
49  }
50  ~NoConstructor() { print_destroyed(this); }
51  };
52  struct NoConstructorNew {
53  NoConstructorNew() = default;
54  NoConstructorNew(const NoConstructorNew &) = default;
55  NoConstructorNew(NoConstructorNew &&) = default;
56  static NoConstructorNew *new_instance() {
57  auto *ptr = new NoConstructorNew();
58  print_created(ptr, "via new_instance");
59  return ptr;
60  }
61  ~NoConstructorNew() { print_destroyed(this); }
62  };
63 
64  py::class_<NoConstructor>(m, "NoConstructor")
65  .def_static("new_instance", &NoConstructor::new_instance, "Return an instance");
66 
67  py::class_<NoConstructorNew>(m, "NoConstructorNew")
68  .def(py::init([](const NoConstructorNew &self) { return self; })) // Need a NOOP __init__
69  .def_static("__new__",
70  [](const py::object &) { return NoConstructorNew::new_instance(); });
71 
72  // test_inheritance
73  class Pet {
74  public:
75  Pet(const std::string &name, const std::string &species)
76  : m_name(name), m_species(species) {}
77  std::string name() const { return m_name; }
78  std::string species() const { return m_species; }
79 
80  private:
81  std::string m_name;
82  std::string m_species;
83  };
84 
85  class Dog : public Pet {
86  public:
87  explicit Dog(const std::string &name) : Pet(name, "dog") {}
88  std::string bark() const { return "Woof!"; }
89  };
90 
91  class Rabbit : public Pet {
92  public:
93  explicit Rabbit(const std::string &name) : Pet(name, "parrot") {}
94  };
95 
96  class Hamster : public Pet {
97  public:
98  explicit Hamster(const std::string &name) : Pet(name, "rodent") {}
99  };
100 
101  class Chimera : public Pet {
102  Chimera() : Pet("Kimmy", "chimera") {}
103  };
104 
105  py::class_<Pet> pet_class(m, "Pet");
106  pet_class.def(py::init<std::string, std::string>())
107  .def("name", &Pet::name)
108  .def("species", &Pet::species);
109 
110  /* One way of declaring a subclass relationship: reference parent's class_ object */
111  py::class_<Dog>(m, "Dog", pet_class).def(py::init<std::string>());
112 
113  /* Another way of declaring a subclass relationship: reference parent's C++ type */
114  py::class_<Rabbit, Pet>(m, "Rabbit").def(py::init<std::string>());
115 
116  /* And another: list parent in class template arguments */
117  py::class_<Hamster, Pet>(m, "Hamster").def(py::init<std::string>());
118 
119  /* Constructors are not inherited by default */
120  py::class_<Chimera, Pet>(m, "Chimera");
121 
122  m.def("pet_name_species",
123  [](const Pet &pet) { return pet.name() + " is a " + pet.species(); });
124  m.def("dog_bark", [](const Dog &dog) { return dog.bark(); });
125 
126  // test_automatic_upcasting
127  struct BaseClass {
128  BaseClass() = default;
129  BaseClass(const BaseClass &) = default;
130  BaseClass(BaseClass &&) = default;
131  virtual ~BaseClass() = default;
132  };
133  struct DerivedClass1 : BaseClass {};
134  struct DerivedClass2 : BaseClass {};
135 
136  py::class_<BaseClass>(m, "BaseClass").def(py::init<>());
137  py::class_<DerivedClass1>(m, "DerivedClass1").def(py::init<>());
138  py::class_<DerivedClass2>(m, "DerivedClass2").def(py::init<>());
139 
140  m.def("return_class_1", []() -> BaseClass * { return new DerivedClass1(); });
141  m.def("return_class_2", []() -> BaseClass * { return new DerivedClass2(); });
142  m.def("return_class_n", [](int n) -> BaseClass * {
143  if (n == 1) {
144  return new DerivedClass1();
145  }
146  if (n == 2) {
147  return new DerivedClass2();
148  }
149  return new BaseClass();
150  });
151  m.def("return_none", []() -> BaseClass * { return nullptr; });
152 
153  // test_isinstance
154  m.def("check_instances", [](const py::list &l) {
155  return py::make_tuple(py::isinstance<py::tuple>(l[0]),
156  py::isinstance<py::dict>(l[1]),
157  py::isinstance<Pet>(l[2]),
158  py::isinstance<Pet>(l[3]),
159  py::isinstance<Dog>(l[4]),
160  py::isinstance<Rabbit>(l[5]),
161  py::isinstance<UnregisteredType>(l[6]));
162  });
163 
164  struct Invalid {};
165 
166  // test_type
167  m.def("check_type", [](int category) {
168  // Currently not supported (via a fail at compile time)
169  // See https://github.com/pybind/pybind11/issues/2486
170  // if (category == 2)
171  // return py::type::of<int>();
172  if (category == 1) {
173  return py::type::of<DerivedClass1>();
174  }
175  return py::type::of<Invalid>();
176  });
177 
178  m.def("get_type_of", [](py::object ob) { return py::type::of(std::move(ob)); });
179 
180  m.def("get_type_classic", [](py::handle h) { return h.get_type(); });
181 
182  m.def("as_type", [](const py::object &ob) { return py::type(ob); });
183 
184  // test_mismatched_holder
185  struct MismatchBase1 {};
186  struct MismatchDerived1 : MismatchBase1 {};
187 
188  struct MismatchBase2 {};
189  struct MismatchDerived2 : MismatchBase2 {};
190 
191  m.def("mismatched_holder_1", []() {
192  auto mod = py::module_::import("__main__");
193  py::class_<MismatchBase1, std::shared_ptr<MismatchBase1>>(mod, "MismatchBase1");
194  py::class_<MismatchDerived1, MismatchBase1>(mod, "MismatchDerived1");
195  });
196  m.def("mismatched_holder_2", []() {
197  auto mod = py::module_::import("__main__");
198  py::class_<MismatchBase2>(mod, "MismatchBase2");
199  py::class_<MismatchDerived2, std::shared_ptr<MismatchDerived2>, MismatchBase2>(
200  mod, "MismatchDerived2");
201  });
202 
203  // test_override_static
204  // #511: problem with inheritance + overwritten def_static
205  struct MyBase {
206  static std::unique_ptr<MyBase> make() { return std::unique_ptr<MyBase>(new MyBase()); }
207  };
208 
209  struct MyDerived : MyBase {
210  static std::unique_ptr<MyDerived> make() {
211  return std::unique_ptr<MyDerived>(new MyDerived());
212  }
213  };
214 
215  py::class_<MyBase>(m, "MyBase").def_static("make", &MyBase::make);
216 
217  py::class_<MyDerived, MyBase>(m, "MyDerived")
218  .def_static("make", &MyDerived::make)
219  .def_static("make2", &MyDerived::make);
220 
221  // test_implicit_conversion_life_support
222  struct ConvertibleFromUserType {
223  int i;
224 
225  explicit ConvertibleFromUserType(UserType u) : i(u.value()) {}
226  };
227 
228  py::class_<ConvertibleFromUserType>(m, "AcceptsUserType").def(py::init<UserType>());
229  py::implicitly_convertible<UserType, ConvertibleFromUserType>();
230 
231  m.def("implicitly_convert_argument", [](const ConvertibleFromUserType &r) { return r.i; });
232  m.def("implicitly_convert_variable", [](const py::object &o) {
233  // `o` is `UserType` and `r` is a reference to a temporary created by implicit
234  // conversion. This is valid when called inside a bound function because the temp
235  // object is attached to the same life support system as the arguments.
236  const auto &r = o.cast<const ConvertibleFromUserType &>();
237  return r.i;
238  });
239  m.add_object("implicitly_convert_variable_fail", [&] {
240  auto f = [](PyObject *, PyObject *args) -> PyObject * {
241  auto o = py::reinterpret_borrow<py::tuple>(args)[0];
242  try { // It should fail here because there is no life support.
243  o.cast<const ConvertibleFromUserType &>();
244  } catch (const py::cast_error &e) {
245  return py::str(e.what()).release().ptr();
246  }
247  return py::str().release().ptr();
248  };
249 
250  auto *def = new PyMethodDef{"f", f, METH_VARARGS, nullptr};
251  py::capsule def_capsule(def,
252  [](void *ptr) { delete reinterpret_cast<PyMethodDef *>(ptr); });
253  return py::reinterpret_steal<py::object>(
254  PyCFunction_NewEx(def, def_capsule.ptr(), m.ptr()));
255  }());
256 
257  // test_operator_new_delete
258  struct HasOpNewDel {
260  static void *operator new(size_t s) {
261  py::print("A new", s);
262  return ::operator new(s);
263  }
264  static void *operator new(size_t s, void *ptr) {
265  py::print("A placement-new", s);
266  return ptr;
267  }
268  static void operator delete(void *p) {
269  py::print("A delete");
270  return ::operator delete(p);
271  }
272  };
273  struct HasOpNewDelSize {
275  static void *operator new(size_t s) {
276  py::print("B new", s);
277  return ::operator new(s);
278  }
279  static void *operator new(size_t s, void *ptr) {
280  py::print("B placement-new", s);
281  return ptr;
282  }
283  static void operator delete(void *p, size_t s) {
284  py::print("B delete", s);
285  return ::operator delete(p);
286  }
287  };
288  struct AliasedHasOpNewDelSize {
290  static void *operator new(size_t s) {
291  py::print("C new", s);
292  return ::operator new(s);
293  }
294  static void *operator new(size_t s, void *ptr) {
295  py::print("C placement-new", s);
296  return ptr;
297  }
298  static void operator delete(void *p, size_t s) {
299  py::print("C delete", s);
300  return ::operator delete(p);
301  }
302  virtual ~AliasedHasOpNewDelSize() = default;
303  AliasedHasOpNewDelSize() = default;
304  AliasedHasOpNewDelSize(const AliasedHasOpNewDelSize &) = delete;
305  };
306  struct PyAliasedHasOpNewDelSize : AliasedHasOpNewDelSize {
307  PyAliasedHasOpNewDelSize() = default;
308  explicit PyAliasedHasOpNewDelSize(int) {}
310  };
311  struct HasOpNewDelBoth {
312  std::uint32_t i[8];
313  static void *operator new(size_t s) {
314  py::print("D new", s);
315  return ::operator new(s);
316  }
317  static void *operator new(size_t s, void *ptr) {
318  py::print("D placement-new", s);
319  return ptr;
320  }
321  static void operator delete(void *p) {
322  py::print("D delete");
323  return ::operator delete(p);
324  }
325  static void operator delete(void *p, size_t s) {
326  py::print("D wrong delete", s);
327  return ::operator delete(p);
328  }
329  };
330  py::class_<HasOpNewDel>(m, "HasOpNewDel").def(py::init<>());
331  py::class_<HasOpNewDelSize>(m, "HasOpNewDelSize").def(py::init<>());
332  py::class_<HasOpNewDelBoth>(m, "HasOpNewDelBoth").def(py::init<>());
333  py::class_<AliasedHasOpNewDelSize, PyAliasedHasOpNewDelSize> aliased(m,
334  "AliasedHasOpNewDelSize");
335  aliased.def(py::init<>());
336  aliased.attr("size_noalias") = py::int_(sizeof(AliasedHasOpNewDelSize));
337  aliased.attr("size_alias") = py::int_(sizeof(PyAliasedHasOpNewDelSize));
338 
339  // This test is actually part of test_local_bindings (test_duplicate_local), but we need a
340  // definition in a different compilation unit within the same module:
341  bind_local<LocalExternal, 17>(m, "LocalExternal", py::module_local());
342 
343  // test_bind_protected_functions
344  class ProtectedA {
345  protected:
346  int foo() const { return value; }
347 
348  private:
349  int value = 42;
350  };
351 
352  class PublicistA : public ProtectedA {
353  public:
354  using ProtectedA::foo;
355  };
356 
357  py::class_<ProtectedA>(m, "ProtectedA").def(py::init<>()).def("foo", &PublicistA::foo);
358 
359  class ProtectedB {
360  public:
361  virtual ~ProtectedB() = default;
362  ProtectedB() = default;
363  ProtectedB(const ProtectedB &) = delete;
364 
365  protected:
366  virtual int foo() const { return value; }
367 
368  private:
369  int value = 42;
370  };
371 
372  class TrampolineB : public ProtectedB {
373  public:
374  int foo() const override { PYBIND11_OVERRIDE(int, ProtectedB, foo, ); }
375  };
376 
377  class PublicistB : public ProtectedB {
378  public:
379  // [workaround(intel)] = default does not work here
380  // Removing or defaulting this destructor results in linking errors with the Intel compiler
381  // (in Debug builds only, tested with icpc (ICC) 2021.1 Beta 20200827)
382  ~PublicistB() override{}; // NOLINT(modernize-use-equals-default)
383  using ProtectedB::foo;
384  };
385 
386  py::class_<ProtectedB, TrampolineB>(m, "ProtectedB")
387  .def(py::init<>())
388  .def("foo", &PublicistB::foo);
389 
390  // test_brace_initialization
391  struct BraceInitialization {
392  int field1;
393  std::string field2;
394  };
395 
396  py::class_<BraceInitialization>(m, "BraceInitialization")
397  .def(py::init<int, const std::string &>())
398  .def_readwrite("field1", &BraceInitialization::field1)
399  .def_readwrite("field2", &BraceInitialization::field2);
400  // We *don't* want to construct using braces when the given constructor argument maps to a
401  // constructor, because brace initialization could go to the wrong place (in particular when
402  // there is also an `initializer_list<T>`-accept constructor):
403  py::class_<NoBraceInitialization>(m, "NoBraceInitialization")
404  .def(py::init<std::vector<int>>())
405  .def_readonly("vec", &NoBraceInitialization::vec);
406 
407  // test_reentrant_implicit_conversion_failure
408  // #1035: issue with runaway reentrant implicit conversion
409  struct BogusImplicitConversion {
410  BogusImplicitConversion(const BogusImplicitConversion &) = default;
411  };
412 
413  py::class_<BogusImplicitConversion>(m, "BogusImplicitConversion")
414  .def(py::init<const BogusImplicitConversion &>());
415 
416  py::implicitly_convertible<int, BogusImplicitConversion>();
417 
418  // test_qualname
419  // #1166: nested class docstring doesn't show nested name
420  // Also related: tests that __qualname__ is set properly
421  struct NestBase {};
422  struct Nested {};
423  py::class_<NestBase> base(m, "NestBase");
424  base.def(py::init<>());
425  py::class_<Nested>(base, "Nested")
426  .def(py::init<>())
427  .def("fn", [](Nested &, int, NestBase &, Nested &) {})
428  .def(
429  "fa", [](Nested &, int, NestBase &, Nested &) {}, "a"_a, "b"_a, "c"_a);
430  base.def("g", [](NestBase &, Nested &) {});
431  base.def("h", []() { return NestBase(); });
432 
433  // test_error_after_conversion
434  // The second-pass path through dispatcher() previously didn't
435  // remember which overload was used, and would crash trying to
436  // generate a useful error message
437 
438  struct NotRegistered {};
439  struct StringWrapper {
440  std::string str;
441  };
442  m.def("test_error_after_conversions", [](int) {});
443  m.def("test_error_after_conversions",
444  [](const StringWrapper &) -> NotRegistered { return {}; });
445  py::class_<StringWrapper>(m, "StringWrapper").def(py::init<std::string>());
446  py::implicitly_convertible<std::string, StringWrapper>();
447 
448 #if defined(PYBIND11_CPP17)
449  struct alignas(1024) Aligned {
450  std::uintptr_t ptr() const { return (uintptr_t) this; }
451  };
452  py::class_<Aligned>(m, "Aligned").def(py::init<>()).def("ptr", &Aligned::ptr);
453 #endif
454 
455  // test_final
456  struct IsFinal final {};
457  py::class_<IsFinal>(m, "IsFinal", py::is_final());
458 
459  // test_non_final_final
460  struct IsNonFinalFinal {};
461  py::class_<IsNonFinalFinal>(m, "IsNonFinalFinal", py::is_final());
462 
463  // test_exception_rvalue_abort
464  struct PyPrintDestructor {
465  PyPrintDestructor() = default;
466  ~PyPrintDestructor() { py::print("Print from destructor"); }
467  void throw_something() { throw std::runtime_error("error"); }
468  };
469  py::class_<PyPrintDestructor>(m, "PyPrintDestructor")
470  .def(py::init<>())
471  .def("throw_something", &PyPrintDestructor::throw_something);
472 
473  // test_multiple_instances_with_same_pointer
474  struct SamePointer {};
475  static SamePointer samePointer;
476  py::class_<SamePointer, std::unique_ptr<SamePointer, py::nodelete>>(m, "SamePointer")
477  .def(py::init([]() { return &samePointer; }));
478 
479  struct Empty {};
480  py::class_<Empty>(m, "Empty").def(py::init<>());
481 
482  // test_base_and_derived_nested_scope
483  struct BaseWithNested {
484  struct Nested {};
485  };
486 
487  struct DerivedWithNested : BaseWithNested {
488  struct Nested {};
489  };
490 
491  py::class_<BaseWithNested> baseWithNested_class(m, "BaseWithNested");
492  py::class_<DerivedWithNested, BaseWithNested> derivedWithNested_class(m, "DerivedWithNested");
493  py::class_<BaseWithNested::Nested>(baseWithNested_class, "Nested")
494  .def_static("get_name", []() { return "BaseWithNested::Nested"; });
495  py::class_<DerivedWithNested::Nested>(derivedWithNested_class, "Nested")
496  .def_static("get_name", []() { return "DerivedWithNested::Nested"; });
497 
498  // test_register_duplicate_class
499  struct Duplicate {};
500  struct OtherDuplicate {};
501  struct DuplicateNested {};
502  struct OtherDuplicateNested {};
503 
504  m.def("register_duplicate_class_name", [](const py::module_ &m) {
505  py::class_<Duplicate>(m, "Duplicate");
506  py::class_<OtherDuplicate>(m, "Duplicate");
507  });
508  m.def("register_duplicate_class_type", [](const py::module_ &m) {
509  py::class_<OtherDuplicate>(m, "OtherDuplicate");
510  py::class_<OtherDuplicate>(m, "YetAnotherDuplicate");
511  });
512  m.def("register_duplicate_nested_class_name", [](const py::object &gt) {
513  py::class_<DuplicateNested>(gt, "DuplicateNested");
514  py::class_<OtherDuplicateNested>(gt, "DuplicateNested");
515  });
516  m.def("register_duplicate_nested_class_type", [](const py::object &gt) {
517  py::class_<OtherDuplicateNested>(gt, "OtherDuplicateNested");
518  py::class_<OtherDuplicateNested>(gt, "YetAnotherDuplicateNested");
519  });
520 }
521 
522 template <int N>
523 class BreaksBase {
524 public:
525  virtual ~BreaksBase() = default;
526  BreaksBase() = default;
527  BreaksBase(const BreaksBase &) = delete;
528 };
529 template <int N>
530 class BreaksTramp : public BreaksBase<N> {};
531 // These should all compile just fine:
532 using DoesntBreak1 = py::class_<BreaksBase<1>, std::unique_ptr<BreaksBase<1>>, BreaksTramp<1>>;
533 using DoesntBreak2 = py::class_<BreaksBase<2>, BreaksTramp<2>, std::unique_ptr<BreaksBase<2>>>;
534 using DoesntBreak3 = py::class_<BreaksBase<3>, std::unique_ptr<BreaksBase<3>>>;
535 using DoesntBreak4 = py::class_<BreaksBase<4>, BreaksTramp<4>>;
536 using DoesntBreak5 = py::class_<BreaksBase<5>>;
537 using DoesntBreak6 = py::class_<BreaksBase<6>, std::shared_ptr<BreaksBase<6>>, BreaksTramp<6>>;
538 using DoesntBreak7 = py::class_<BreaksBase<7>, BreaksTramp<7>, std::shared_ptr<BreaksBase<7>>>;
539 using DoesntBreak8 = py::class_<BreaksBase<8>, std::shared_ptr<BreaksBase<8>>>;
540 #define CHECK_BASE(N) \
541  static_assert(std::is_same<typename DoesntBreak##N::type, BreaksBase<(N)>>::value, \
542  "DoesntBreak" #N " has wrong type!")
543 CHECK_BASE(1);
544 CHECK_BASE(2);
545 CHECK_BASE(3);
546 CHECK_BASE(4);
547 CHECK_BASE(5);
548 CHECK_BASE(6);
549 CHECK_BASE(7);
550 CHECK_BASE(8);
551 #define CHECK_ALIAS(N) \
552  static_assert( \
553  DoesntBreak##N::has_alias \
554  && std::is_same<typename DoesntBreak##N::type_alias, BreaksTramp<(N)>>::value, \
555  "DoesntBreak" #N " has wrong type_alias!")
556 #define CHECK_NOALIAS(N) \
557  static_assert(!DoesntBreak##N::has_alias \
558  && std::is_void<typename DoesntBreak##N::type_alias>::value, \
559  "DoesntBreak" #N " has type alias, but shouldn't!")
560 CHECK_ALIAS(1);
561 CHECK_ALIAS(2);
562 CHECK_NOALIAS(3);
563 CHECK_ALIAS(4);
564 CHECK_NOALIAS(5);
565 CHECK_ALIAS(6);
566 CHECK_ALIAS(7);
567 CHECK_NOALIAS(8);
568 #define CHECK_HOLDER(N, TYPE) \
569  static_assert(std::is_same<typename DoesntBreak##N::holder_type, \
570  std::TYPE##_ptr<BreaksBase<(N)>>>::value, \
571  "DoesntBreak" #N " has wrong holder_type!")
572 CHECK_HOLDER(1, unique);
573 CHECK_HOLDER(2, unique);
574 CHECK_HOLDER(3, unique);
575 CHECK_HOLDER(4, unique);
576 CHECK_HOLDER(5, unique);
577 CHECK_HOLDER(6, shared);
578 CHECK_HOLDER(7, shared);
579 CHECK_HOLDER(8, shared);
580 
581 // There's no nice way to test that these fail because they fail to compile; leave them here,
582 // though, so that they can be manually tested by uncommenting them (and seeing that compilation
583 // failures occurs).
584 
585 // We have to actually look into the type: the typedef alone isn't enough to instantiate the type:
586 #define CHECK_BROKEN(N) \
587  static_assert(std::is_same<typename Breaks##N::type, BreaksBase<-(N)>>::value, \
588  "Breaks1 has wrong type!");
589 
590 #ifdef PYBIND11_NEVER_DEFINED_EVER
591 // Two holder classes:
592 typedef py::
593  class_<BreaksBase<-1>, std::unique_ptr<BreaksBase<-1>>, std::unique_ptr<BreaksBase<-1>>>
594  Breaks1;
595 CHECK_BROKEN(1);
596 // Two aliases:
597 typedef py::class_<BreaksBase<-2>, BreaksTramp<-2>, BreaksTramp<-2>> Breaks2;
598 CHECK_BROKEN(2);
599 // Holder + 2 aliases
600 typedef py::
601  class_<BreaksBase<-3>, std::unique_ptr<BreaksBase<-3>>, BreaksTramp<-3>, BreaksTramp<-3>>
602  Breaks3;
603 CHECK_BROKEN(3);
604 // Alias + 2 holders
605 typedef py::class_<BreaksBase<-4>,
606  std::unique_ptr<BreaksBase<-4>>,
607  BreaksTramp<-4>,
608  std::shared_ptr<BreaksBase<-4>>>
609  Breaks4;
610 CHECK_BROKEN(4);
611 // Invalid option (not a subclass or holder)
612 typedef py::class_<BreaksBase<-5>, BreaksTramp<-4>> Breaks5;
613 CHECK_BROKEN(5);
614 // Invalid option: multiple inheritance not supported:
615 template <>
616 struct BreaksBase<-8> : BreaksBase<-6>, BreaksBase<-7> {};
617 typedef py::class_<BreaksBase<-8>, BreaksBase<-6>, BreaksBase<-7>> Breaks8;
618 CHECK_BROKEN(8);
619 #endif
Matrix3f m
NoBraceInitialization(std::initializer_list< T > l)
Definition: test_class.cpp:34
static LabeledSymbol make(gtsam::Key key)
#define CHECK_NOALIAS(N)
Definition: test_class.cpp:556
tuple make_tuple()
Definition: cast.h:1209
#define CHECK_BASE(N)
Definition: test_class.cpp:540
NoBraceInitialization(std::vector< int > v)
Definition: test_class.cpp:32
py::class_< BreaksBase< 2 >, BreaksTramp< 2 >, std::unique_ptr< BreaksBase< 2 > >> DoesntBreak2
Definition: test_class.cpp:533
int n
void print_destroyed(T *inst, Values &&...values)
TEST_SUBMODULE(class_, m)
Definition: test_class.cpp:39
std::vector< int > vec
Definition: test_class.cpp:36
py::class_< BreaksBase< 3 >, std::unique_ptr< BreaksBase< 3 > >> DoesntBreak3
Definition: test_class.cpp:534
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
py::class_< BreaksBase< 8 >, std::shared_ptr< BreaksBase< 8 > >> DoesntBreak8
Definition: test_class.cpp:539
std::string bark() const
py::class_< BreaksBase< 5 > > DoesntBreak5
Definition: test_class.cpp:536
#define CHECK_ALIAS(N)
Definition: test_class.cpp:551
void foo(CV_QUALIFIER Matrix3d &m)
static const Line3 l(Rot3(), 1, 1)
py::class_< BreaksBase< 7 >, BreaksTramp< 7 >, std::shared_ptr< BreaksBase< 7 > >> DoesntBreak7
Definition: test_class.cpp:538
Array< int, Dynamic, 1 > v
unsigned int uint32_t
Definition: ms_stdint.h:85
unsigned __int64 uint64_t
Definition: ms_stdint.h:95
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
py::class_< BreaksBase< 4 >, BreaksTramp< 4 > > DoesntBreak4
Definition: test_class.cpp:535
#define PYBIND11_OVERRIDE(ret_type, cname, fn,...)
Definition: pybind11.h:2824
_W64 unsigned int uintptr_t
Definition: ms_stdint.h:124
const double h
void print_created(T *inst, Values &&...values)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
Definition: pybind11.h:1882
#define CHECK_HOLDER(N, TYPE)
Definition: test_class.cpp:568
float * p
Annotation for function names.
Definition: attr.h:48
Annotation indicating that a class derives from another given type.
Definition: attr.h:61
#define CHECK_BROKEN(N)
Definition: test_class.cpp:586
py::class_< BreaksBase< 6 >, std::shared_ptr< BreaksBase< 6 > >, BreaksTramp< 6 > > DoesntBreak6
Definition: test_class.cpp:537
std::ptrdiff_t j
py::class_< BreaksBase< 1 >, std::unique_ptr< BreaksBase< 1 > >, BreaksTramp< 1 > > DoesntBreak1
Definition: test_class.cpp:532


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:37:45