1
- #include < pybind11/smart_holder.h>
2
-
3
1
#include " pybind11_tests.h"
4
2
5
3
#include < memory>
9
7
namespace pybind11_tests {
10
8
namespace {
11
9
12
- const std::string fooNames[] = {" ShPtr_" , " SmHld_ " };
10
+ const std::string fooNames[] = {" ShPtr_" };
13
11
14
12
template <int SerNo>
15
13
struct Foo {
@@ -29,37 +27,26 @@ struct Foo {
29
27
};
30
28
31
29
using FooShPtr = Foo<0 >;
32
- using FooSmHld = Foo<1 >;
33
30
34
31
struct Outer {
35
32
std::shared_ptr<FooShPtr> ShPtr;
36
- std::shared_ptr<FooSmHld> SmHld;
37
- Outer ()
38
- : ShPtr(std::make_shared<FooShPtr>(" Outer" )), SmHld(std::make_shared<FooSmHld>(" Outer" )) {}
33
+ Outer () : ShPtr(std::make_shared<FooShPtr>(" Outer" )) {}
39
34
std::shared_ptr<FooShPtr> getShPtr () const { return ShPtr; }
40
- std::shared_ptr<FooSmHld> getSmHld () const { return SmHld; }
41
35
};
42
36
43
37
} // namespace
44
38
} // namespace pybind11_tests
45
39
46
- PYBIND11_TYPE_CASTER_BASE_HOLDER (pybind11_tests::FooShPtr,
47
- std::shared_ptr<pybind11_tests::FooShPtr>)
48
- PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::FooSmHld)
49
-
50
40
namespace pybind11_tests {
51
41
52
42
TEST_SUBMODULE (class_sh_shared_ptr_copy_move, m) {
53
43
namespace py = pybind11;
54
44
55
45
py::class_<FooShPtr, std::shared_ptr<FooShPtr>>(m, " FooShPtr" )
56
46
.def (" get_history" , &FooShPtr::get_history);
57
- py::classh<FooSmHld>(m, " FooSmHld" ).def (" get_history" , &FooSmHld::get_history);
58
47
59
48
auto outer = py::class_<Outer>(m, " Outer" ).def (py::init ());
60
- #define MAKE_PROP (PropTyp ) \
61
- MAKE_PROP_FOO (ShPtr, PropTyp) \
62
- MAKE_PROP_FOO (SmHld, PropTyp)
49
+ #define MAKE_PROP (PropTyp ) MAKE_PROP_FOO(ShPtr, PropTyp)
63
50
64
51
#define MAKE_PROP_FOO (FooTyp, PropTyp ) \
65
52
.def_ ##PropTyp (#FooTyp " _" #PropTyp " _default" , &Outer::FooTyp) \
@@ -88,25 +75,13 @@ TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) {
88
75
l.append (o);
89
76
return l;
90
77
});
91
- m.def (" test_SmHld_copy" , []() {
92
- auto o = std::make_shared<FooSmHld>(" copy" );
93
- auto l = py::list ();
94
- l.append (o);
95
- return l;
96
- });
97
78
98
79
m.def (" test_ShPtr_move" , []() {
99
80
auto o = std::make_shared<FooShPtr>(" move" );
100
81
auto l = py::list ();
101
82
l.append (std::move (o));
102
83
return l;
103
84
});
104
- m.def (" test_SmHld_move" , []() {
105
- auto o = std::make_shared<FooSmHld>(" move" );
106
- auto l = py::list ();
107
- l.append (std::move (o));
108
- return l;
109
- });
110
85
}
111
86
112
87
} // namespace pybind11_tests
0 commit comments