14 #if !defined(PYBIND11_OVERLOAD_CAST) 15 template <
typename... Args>
29 return "ExampleMandA[value=" + std::to_string(
value) +
"]";
82 int get()
const {
return value; }
83 void set(
int v) { value =
v; }
102 const UserType &
get1()
const {
return v1; }
103 const UserType &
get2()
const {
return v2; }
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; }
135 double ro_value = 1.25;
139 using UnregisteredBase::UnregisteredBase;
140 double sum()
const {
return rw_value + ro_value; }
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&>())
179 #if defined(PYBIND11_OVERLOAD_CAST) 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"));
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"));
224 emna.attr(
"add2b") = emna.attr(
"add2");
227 py::class_<TestProperties>(
m,
"TestProperties")
231 .def_property(
"def_writeonly",
nullptr,
236 .def_property(
"def_property_impossible",
nullptr,
nullptr)
239 .def_property_static(
"def_writeonly_static",
nullptr,
241 .def_property_readonly_static(
"def_property_readonly_static",
243 .def_property_static(
"def_property_writeonly_static",
nullptr,
245 .def_property_static(
"def_property_static",
248 .def_property_static(
"static_cls",
249 [](py::object cls) {
return cls; },
250 [](py::object cls, py::function
f) {
f(cls); });
252 py::class_<TestPropertiesOverride, TestProperties>(
m,
"TestPropertiesOverride")
257 auto static_get1 = [](py::object) ->
const UserType & {
return TestPropRVP::sv1; };
258 auto static_get2 = [](py::object) ->
const UserType & {
return TestPropRVP::sv2; };
264 py::class_<TestPropRVP>(
m,
"TestPropRVP")
268 .def_property_readonly(
"ro_func", py::cpp_function(&
TestPropRVP::get2, rvp_copy))
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)
280 .def_property_readonly_static(
"static_rvalue", [](py::object) {
return UserType(1); });
283 struct MetaclassOverride { };
284 py::class_<MetaclassOverride>(
m,
"MetaclassOverride", py::metaclass((PyObject *) &PyType_Type))
285 .def_property_readonly_static(
"readonly", [](py::object) {
return 1; });
287 #if !defined(PYPY_VERSION) 292 DynamicClass(
const DynamicClass&) =
delete;
295 py::class_<DynamicClass>(
m,
"DynamicClass", py::dynamic_attr())
298 class CppDerivedDynamicClass :
public DynamicClass { };
299 py::class_<CppDerivedDynamicClass, DynamicClass>(
m,
"CppDerivedDynamicClass")
306 m.attr(
"debug_enabled") =
true;
308 m.attr(
"debug_enabled") =
false;
310 m.def(
"bad_arg_def_named", []{
311 auto m = py::module::import(
"pybind11_tests");
314 m.def(
"bad_arg_def_unnamed", []{
315 auto m = py::module::import(
"pybind11_tests");
320 py::class_<NoneTester, std::shared_ptr<NoneTester>>(
m,
"NoneTester")
327 m.def(
"ok_none1", &
none1);
329 m.def(
"ok_none3", &
none3);
331 m.def(
"ok_none5", &
none5);
335 py::class_<StrIssue>(
m,
"StrIssue")
336 .def(py::init<int>())
338 .def(
"__str__", [](
const StrIssue &si) {
339 return "StrIssue[" + std::to_string(si.
val) +
"]"; }
348 py::class_<RegisteredDerived>(
m,
"RegisteredDerived")
367 py::class_<RefQualified>(
m,
"RefQualified")
py::str overloaded(float, int)
py::str overloaded(float, float) const
void print_destroyed(T *inst, Values &&...values)
void consume_str(std::string &&)
int constRefQualified(int other) const &
void print_copy_assigned(T *inst, Values &&...values)
void add10(const int *other)
void print_copy_created(T *inst, Values &&...values)
py::str overloaded(int, int)
void add4(ExampleMandA *other)
py::str overloaded(float, float)
Dummy type which is not exported anywhere – something to trigger a conversion error.
static constexpr auto const_
py::str overloaded(int, int) const
static void static_set(int v)
void print_default_created(T *inst, Values &&...values)
void add8(const int &other)
void print_move_assigned(T *inst, Values &&...values)
int none5(std::shared_ptr< NoneTester > obj)
const UserType & get2() const
ExampleMandA(ExampleMandA &&e)
py::str overloaded(float, int) const
const ExampleMandA & self3()
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static py::str overloaded(float)
double get_double() const
ExampleMandA(const ExampleMandA &e)
int none4(std::shared_ptr< NoneTester > *obj)
const UserType & get1() const
int none3(std::shared_ptr< NoneTester > &obj)
TEST_SUBMODULE(methods_and_attributes, m)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
pybind11::detail::overload_cast_impl< Args... > overload_cast_
void operator=(const ExampleMandA &e)
void operator=(ExampleMandA &&e)
py::str overloaded(int) const
void print_created(T *inst, Values &&...values)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
UserType get_rvalue() const
void refQualified(int other)&
void add2(ExampleMandA &other)
int none2(NoneTester *obj)
int EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
int none1(const NoneTester &obj)
void add3(const ExampleMandA &other)
py::str overloaded(int, float) const
void print_move_created(T *inst, Values &&...values)
py::str overloaded(int, float)
void add1(ExampleMandA other)
const ExampleMandA * self5()
ExampleMandA(std::string &&)
void add5(const ExampleMandA *other)