test_vector_unique_ptr_member.cpp
Go to the documentation of this file.
1 #include "pybind11_tests.h"
2 
3 #include <cstddef>
4 #include <memory>
5 #include <vector>
6 
7 namespace pybind11_tests {
8 namespace vector_unique_ptr_member {
9 
10 struct DataType {};
11 
12 // Reduced from a use case in the wild.
13 struct VectorOwner {
14  static std::unique_ptr<VectorOwner> Create(std::size_t num_elems) {
15  return std::unique_ptr<VectorOwner>(
16  new VectorOwner(std::vector<std::unique_ptr<DataType>>(num_elems)));
17  }
18 
19  std::size_t data_size() const { return data_.size(); }
20 
21 private:
22  explicit VectorOwner(std::vector<std::unique_ptr<DataType>> data) : data_(std::move(data)) {}
23 
24  const std::vector<std::unique_ptr<DataType>> data_;
25 };
26 
27 } // namespace vector_unique_ptr_member
28 } // namespace pybind11_tests
29 
30 namespace pybind11 {
31 namespace detail {
32 
33 template <>
34 struct is_copy_constructible<pybind11_tests::vector_unique_ptr_member::VectorOwner>
35  : std::false_type {};
36 
37 template <>
38 struct is_move_constructible<pybind11_tests::vector_unique_ptr_member::VectorOwner>
39  : std::false_type {};
40 
41 } // namespace detail
42 } // namespace pybind11
43 
45 
46 py::object py_cast_VectorOwner_ptr(VectorOwner *ptr) { return py::cast(ptr); }
47 
48 TEST_SUBMODULE(vector_unique_ptr_member, m) {
49  py::class_<VectorOwner>(m, "VectorOwner")
50  .def_static("Create", &VectorOwner::Create)
51  .def("data_size", &VectorOwner::data_size);
52 
53  m.def("py_cast_VectorOwner_ptr", py_cast_VectorOwner_ptr);
54 }
detail
Definition: testSerializationNonlinear.cpp:70
is_move_constructible
Definition: type_caster_base.h:1005
pybind11_tests::vector_unique_ptr_member
Definition: test_vector_unique_ptr_member.cpp:8
pybind11_tests::vector_unique_ptr_member::VectorOwner::data_size
std::size_t data_size() const
Definition: test_vector_unique_ptr_member.cpp:19
data
int data[]
Definition: Map_placement_new.cpp:1
py_cast_VectorOwner_ptr
py::object py_cast_VectorOwner_ptr(VectorOwner *ptr)
Definition: test_vector_unique_ptr_member.cpp:46
pybind11_tests::vector_unique_ptr_member::VectorOwner::Create
static std::unique_ptr< VectorOwner > Create(std::size_t num_elems)
Definition: test_vector_unique_ptr_member.cpp:14
is_copy_constructible
Definition: type_caster_base.h:1024
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
pybind11_tests::vector_unique_ptr_member::VectorOwner::VectorOwner
VectorOwner(std::vector< std::unique_ptr< DataType >> data)
Definition: test_vector_unique_ptr_member.cpp:22
pybind11_tests::vector_unique_ptr_member::DataType
Definition: test_vector_unique_ptr_member.cpp:10
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
pybind11_tests
Definition: test_methods_and_attributes.cpp:180
move
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Definition: cast.h:1243
pybind11_tests.h
std
Definition: BFloat16.h:88
pybind11
Definition: wrap/pybind11/pybind11/__init__.py:1
TEST_SUBMODULE
TEST_SUBMODULE(vector_unique_ptr_member, m)
Definition: test_vector_unique_ptr_member.cpp:48
Eigen::internal::cast
EIGEN_DEVICE_FUNC NewType cast(const OldType &x)
Definition: Eigen/src/Core/MathFunctions.h:460
pybind11_tests::vector_unique_ptr_member::VectorOwner::data_
const std::vector< std::unique_ptr< DataType > > data_
Definition: test_vector_unique_ptr_member.cpp:24
pybind11_tests::vector_unique_ptr_member::VectorOwner
Definition: test_vector_unique_ptr_member.cpp:13


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:09