SH, shared_ptr copy/move, rename to 'history'

This commit is contained in:
Jakob Lykke Andersen 2021-06-24 11:54:20 +02:00 committed by Ralf W. Grosse-Kunstleve
parent ef6907c1ae
commit b735093fde
2 changed files with 9 additions and 9 deletions

View File

@ -13,11 +13,11 @@ const std::string fooNames[] = {"ShPtr_", "SmHld_"};
template <int SerNo>
struct Foo {
std::string mtxt;
Foo(const std::string &mtxt_) : mtxt(mtxt_) {}
std::string hisotry;
Foo(const std::string &hisotry_) : hisotry(hisotry_) {}
Foo(const 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>;
@ -36,9 +36,9 @@ TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) {
namespace py = pybind11;
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")
.def("get_text", &FooSmHld::get_text);
.def("get_history", &FooSmHld::get_history);
m.def("test_ShPtr_copy", []() {
auto o = std::make_shared<FooShPtr>("copy");

View File

@ -4,20 +4,20 @@ from pybind11_tests import class_sh_shared_ptr_copy_move as m
def test_shptr_copy():
txt = m.test_ShPtr_copy()[0].get_text()
txt = m.test_ShPtr_copy()[0].get_history()
assert txt == "FooShPtr_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"
def test_shptr_move():
txt = m.test_ShPtr_move()[0].get_text()
txt = m.test_ShPtr_move()[0].get_history()
assert txt == "FooShPtr_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"