mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-29 16:37:13 +00:00
SH, shared_ptr copy/move, rename to 'history'
This commit is contained in:
parent
ef6907c1ae
commit
b735093fde
@ -13,11 +13,11 @@ const std::string fooNames[] = {"ShPtr_", "SmHld_"};
|
|||||||
|
|
||||||
template <int SerNo>
|
template <int SerNo>
|
||||||
struct Foo {
|
struct Foo {
|
||||||
std::string mtxt;
|
std::string hisotry;
|
||||||
Foo(const std::string &mtxt_) : mtxt(mtxt_) {}
|
Foo(const std::string &hisotry_) : hisotry(hisotry_) {}
|
||||||
Foo(const Foo &other) = delete;
|
Foo(const Foo &other) = delete;
|
||||||
Foo(Foo &&other) = delete;
|
Foo(Foo &&other) = delete;
|
||||||
std::string get_text() const { return "Foo" + fooNames[SerNo] + mtxt; }
|
std::string get_history() const { return "Foo" + fooNames[SerNo] + hisotry; }
|
||||||
};
|
};
|
||||||
|
|
||||||
using FooShPtr = Foo<0>;
|
using FooShPtr = Foo<0>;
|
||||||
@ -36,9 +36,9 @@ TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) {
|
|||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
|
|
||||||
py::class_<FooShPtr, std::shared_ptr<FooShPtr>>(m, "FooShPtr")
|
py::class_<FooShPtr, std::shared_ptr<FooShPtr>>(m, "FooShPtr")
|
||||||
.def("get_text", &FooShPtr::get_text);
|
.def("get_history", &FooShPtr::get_history);
|
||||||
py::classh<FooSmHld>(m, "FooSmHld")
|
py::classh<FooSmHld>(m, "FooSmHld")
|
||||||
.def("get_text", &FooSmHld::get_text);
|
.def("get_history", &FooSmHld::get_history);
|
||||||
|
|
||||||
m.def("test_ShPtr_copy", []() {
|
m.def("test_ShPtr_copy", []() {
|
||||||
auto o = std::make_shared<FooShPtr>("copy");
|
auto o = std::make_shared<FooShPtr>("copy");
|
||||||
|
@ -4,20 +4,20 @@ from pybind11_tests import class_sh_shared_ptr_copy_move as m
|
|||||||
|
|
||||||
|
|
||||||
def test_shptr_copy():
|
def test_shptr_copy():
|
||||||
txt = m.test_ShPtr_copy()[0].get_text()
|
txt = m.test_ShPtr_copy()[0].get_history()
|
||||||
assert txt == "FooShPtr_copy"
|
assert txt == "FooShPtr_copy"
|
||||||
|
|
||||||
|
|
||||||
def test_smhld_copy():
|
def test_smhld_copy():
|
||||||
txt = m.test_SmHld_copy()[0].get_text()
|
txt = m.test_SmHld_copy()[0].get_history()
|
||||||
assert txt == "FooSmHld_copy"
|
assert txt == "FooSmHld_copy"
|
||||||
|
|
||||||
|
|
||||||
def test_shptr_move():
|
def test_shptr_move():
|
||||||
txt = m.test_ShPtr_move()[0].get_text()
|
txt = m.test_ShPtr_move()[0].get_history()
|
||||||
assert txt == "FooShPtr_move"
|
assert txt == "FooShPtr_move"
|
||||||
|
|
||||||
|
|
||||||
def test_smhld_move():
|
def test_smhld_move():
|
||||||
txt = m.test_SmHld_move()[0].get_text()
|
txt = m.test_SmHld_move()[0].get_history()
|
||||||
assert txt == "FooSmHld_move"
|
assert txt == "FooSmHld_move"
|
||||||
|
Loading…
Reference in New Issue
Block a user