mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-12 17:26:13 +00:00
SH, update shared_ptr copy tests
This commit is contained in:
committed by
Ralf W. Grosse-Kunstleve
parent
1f98d74761
commit
fc548c067f
51
tests/test_class_sh_shared_ptr_copy.cpp
Normal file
51
tests/test_class_sh_shared_ptr_copy.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "pybind11_tests.h"
|
||||
|
||||
#include <pybind11/smart_holder.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace pybind11_tests {
|
||||
namespace class_sh_shared_ptr_copy {
|
||||
|
||||
template<int SerNo>
|
||||
struct Foo {
|
||||
std::string mtxt;
|
||||
Foo() : mtxt("DefaultConstructor") {}
|
||||
Foo(const std::string &mtxt_) : mtxt(mtxt_) {}
|
||||
Foo(const Foo &other) { mtxt = other.mtxt + "_CpCtor"; }
|
||||
Foo(Foo &&other) { mtxt = other.mtxt + "_MvCtor"; }
|
||||
};
|
||||
|
||||
using FooAVL = Foo<0>;
|
||||
using FooDEF = Foo<1>;
|
||||
|
||||
} // namespace class_sh_shared_ptr_copy
|
||||
} // namespace pybind11_tests
|
||||
|
||||
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_shared_ptr_copy::FooAVL)
|
||||
|
||||
namespace pybind11_tests {
|
||||
namespace class_sh_shared_ptr_copy {
|
||||
|
||||
TEST_SUBMODULE(class_sh_shared_ptr_copy, m) {
|
||||
namespace py = pybind11;
|
||||
|
||||
py::class_<FooAVL, PYBIND11_SH_AVL(FooAVL)>(m, "FooAVL");
|
||||
py::class_<FooDEF, std::shared_ptr<FooDEF>>(m, "FooDEF");
|
||||
|
||||
m.def("test_avl", []() {
|
||||
auto o = std::make_shared<FooAVL>("AVL");
|
||||
auto l = py::list();
|
||||
l.append(o);
|
||||
});
|
||||
m.def("test_def", []() {
|
||||
auto o = std::make_shared<FooDEF>("DEF");
|
||||
auto l = py::list();
|
||||
l.append(o);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace class_sh_shared_ptr_copy
|
||||
} // namespace pybind11_tests
|
||||
Reference in New Issue
Block a user