test_copy_move.cpp
Go to the documentation of this file.
1 /*
2  tests/test_copy_move_policies.cpp -- 'copy' and 'move' return value policies
3  and related tests
4 
5  Copyright (c) 2016 Ben North <ben@redfrontdoor.org>
6 
7  All rights reserved. Use of this source code is governed by a
8  BSD-style license that can be found in the LICENSE file.
9 */
10 
11 #include <pybind11/stl.h>
12 
13 #include "constructor_stats.h"
14 #include "pybind11_tests.h"
15 
16 #include <type_traits>
17 
18 template <typename derived>
19 struct empty {
20  static const derived &get_one() { return instance_; }
21  static derived instance_;
22 };
23 
24 struct lacking_copy_ctor : public empty<lacking_copy_ctor> {
25  lacking_copy_ctor() = default;
26  lacking_copy_ctor(const lacking_copy_ctor &other) = delete;
27 };
28 
29 template <>
31 
32 struct lacking_move_ctor : public empty<lacking_move_ctor> {
33  lacking_move_ctor() = default;
34  lacking_move_ctor(const lacking_move_ctor &other) = delete;
36 };
37 
38 template <>
40 
41 /* Custom type caster move/copy test classes */
42 class MoveOnlyInt {
43 public:
45  explicit MoveOnlyInt(int v) : value{v} { print_created(this, value); }
46  MoveOnlyInt(MoveOnlyInt &&m) noexcept {
47  print_move_created(this, m.value);
48  std::swap(value, m.value);
49  }
51  print_move_assigned(this, m.value);
52  std::swap(value, m.value);
53  return *this;
54  }
55  MoveOnlyInt(const MoveOnlyInt &) = delete;
56  MoveOnlyInt &operator=(const MoveOnlyInt &) = delete;
58 
59  int value;
60 };
62 public:
64  explicit MoveOrCopyInt(int v) : value{v} { print_created(this, value); }
66  print_move_created(this, m.value);
67  std::swap(value, m.value);
68  }
70  print_move_assigned(this, m.value);
71  std::swap(value, m.value);
72  return *this;
73  }
75  print_copy_created(this, c.value);
76  // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
77  value = c.value;
78  }
80  print_copy_assigned(this, c.value);
81  value = c.value;
82  return *this;
83  }
85 
86  int value;
87 };
88 class CopyOnlyInt {
89 public:
91  explicit CopyOnlyInt(int v) : value{v} { print_created(this, value); }
93  print_copy_created(this, c.value);
94  // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
95  value = c.value;
96  }
98  print_copy_assigned(this, c.value);
99  value = c.value;
100  return *this;
101  }
103 
104  int value;
105 };
108 template <>
111  bool load(handle src, bool) {
112  value = MoveOnlyInt(src.cast<int>());
113  return true;
114  }
116  return pybind11::cast(m.value, r, p);
117  }
118 };
119 
120 template <>
122  PYBIND11_TYPE_CASTER(MoveOrCopyInt, const_name("MoveOrCopyInt"));
123  bool load(handle src, bool) {
124  value = MoveOrCopyInt(src.cast<int>());
125  return true;
126  }
128  return pybind11::cast(m.value, r, p);
129  }
130 };
131 
132 template <>
134 protected:
136 
137 public:
138  static constexpr auto name = const_name("CopyOnlyInt");
139  bool load(handle src, bool) {
140  value = CopyOnlyInt(src.cast<int>());
141  return true;
142  }
144  return pybind11::cast(m.value, r, p);
145  }
146  static handle cast(const CopyOnlyInt *src, return_value_policy policy, handle parent) {
147  if (!src) {
148  return none().release();
149  }
150  return cast(*src, policy, parent);
151  }
152  explicit operator CopyOnlyInt *() { return &value; }
153  explicit operator CopyOnlyInt &() { return value; }
154  template <typename T>
155  using cast_op_type = pybind11::detail::cast_op_type<T>;
156 };
159 
160 namespace {
161 
162 py::object CastUnusualOpRefConstRef(const UnusualOpRef &cref) { return py::cast(cref); }
163 py::object CastUnusualOpRefMovable(UnusualOpRef &&mvbl) { return py::cast(std::move(mvbl)); }
164 
165 } // namespace
166 
167 TEST_SUBMODULE(copy_move_policies, m) {
168  // test_lacking_copy_ctor
169  py::class_<lacking_copy_ctor>(m, "lacking_copy_ctor")
171  // test_lacking_move_ctor
172  py::class_<lacking_move_ctor>(m, "lacking_move_ctor")
174 
175  // test_move_and_copy_casts
176  // NOLINTNEXTLINE(performance-unnecessary-value-param)
177  m.def("move_and_copy_casts", [](const py::object &o) {
178  int r = 0;
179  r += py::cast<MoveOrCopyInt>(o).value; /* moves */
180  r += py::cast<MoveOnlyInt>(o).value; /* moves */
181  r += py::cast<CopyOnlyInt>(o).value; /* copies */
182  auto m1(py::cast<MoveOrCopyInt>(o)); /* moves */
183  auto m2(py::cast<MoveOnlyInt>(o)); /* moves */
184  auto m3(py::cast<CopyOnlyInt>(o)); /* copies */
185  r += m1.value + m2.value + m3.value;
186 
187  return r;
188  });
189 
190  // test_move_and_copy_loads
191  m.def("move_only", [](MoveOnlyInt m) { return m.value; });
192  // Changing this breaks the existing test: needs careful review.
193  // NOLINTNEXTLINE(performance-unnecessary-value-param)
194  m.def("move_or_copy", [](MoveOrCopyInt m) { return m.value; });
195  // Changing this breaks the existing test: needs careful review.
196  // NOLINTNEXTLINE(performance-unnecessary-value-param)
197  m.def("copy_only", [](CopyOnlyInt m) { return m.value; });
198  m.def("move_pair",
199  [](std::pair<MoveOnlyInt, MoveOrCopyInt> p) { return p.first.value + p.second.value; });
200  m.def("move_tuple", [](std::tuple<MoveOnlyInt, MoveOrCopyInt, MoveOnlyInt> t) {
201  return std::get<0>(t).value + std::get<1>(t).value + std::get<2>(t).value;
202  });
203  m.def("copy_tuple", [](std::tuple<CopyOnlyInt, CopyOnlyInt> t) {
204  return std::get<0>(t).value + std::get<1>(t).value;
205  });
206  m.def("move_copy_nested",
207  [](std::pair<MoveOnlyInt,
208  std::pair<std::tuple<MoveOrCopyInt, CopyOnlyInt, std::tuple<MoveOnlyInt>>,
209  MoveOrCopyInt>> x) {
210  return x.first.value + std::get<0>(x.second.first).value
211  + std::get<1>(x.second.first).value
212  + std::get<0>(std::get<2>(x.second.first)).value + x.second.second.value;
213  });
214  m.def("move_and_copy_cstats", []() {
216  // Reset counts to 0 so that previous tests don't affect later ones:
217  auto &mc = ConstructorStats::get<MoveOrCopyInt>();
218  mc.move_assignments = mc.move_constructions = mc.copy_assignments = mc.copy_constructions
219  = 0;
220  auto &mo = ConstructorStats::get<MoveOnlyInt>();
221  mo.move_assignments = mo.move_constructions = mo.copy_assignments = mo.copy_constructions
222  = 0;
223  auto &co = ConstructorStats::get<CopyOnlyInt>();
224  co.move_assignments = co.move_constructions = co.copy_assignments = co.copy_constructions
225  = 0;
226  py::dict d;
227  d["MoveOrCopyInt"] = py::cast(mc, py::return_value_policy::reference);
228  d["MoveOnlyInt"] = py::cast(mo, py::return_value_policy::reference);
229  d["CopyOnlyInt"] = py::cast(co, py::return_value_policy::reference);
230  return d;
231  });
232 #ifdef PYBIND11_HAS_OPTIONAL
233  // test_move_and_copy_load_optional
234  m.attr("has_optional") = true;
235  m.def("move_optional", [](std::optional<MoveOnlyInt> o) { return o->value; });
236  m.def("move_or_copy_optional", [](std::optional<MoveOrCopyInt> o) { return o->value; });
237  m.def("copy_optional", [](std::optional<CopyOnlyInt> o) { return o->value; });
238  m.def("move_optional_tuple",
239  [](std::optional<std::tuple<MoveOrCopyInt, MoveOnlyInt, CopyOnlyInt>> x) {
240  return std::get<0>(*x).value + std::get<1>(*x).value + std::get<2>(*x).value;
241  });
242 #else
243  m.attr("has_optional") = false;
244 #endif
245 
246  // #70 compilation issue if operator new is not public - simple body added
247  // but not needed on most compilers; MSVC and nvcc don't like a local
248  // struct not having a method defined when declared, since it can not be
249  // added later.
250  struct PrivateOpNew {
251  int value = 1;
252 
253  private:
254  void *operator new(size_t bytes) {
255  void *ptr = std::malloc(bytes);
256  if (ptr) {
257  return ptr;
258  }
259  throw std::bad_alloc{};
260  }
261  };
262  py::class_<PrivateOpNew>(m, "PrivateOpNew").def_readonly("value", &PrivateOpNew::value);
263  m.def("private_op_new_value", []() { return PrivateOpNew(); });
264  m.def(
265  "private_op_new_reference",
266  []() -> const PrivateOpNew & {
267  static PrivateOpNew x{};
268  return x;
269  },
270  py::return_value_policy::reference);
271 
272  // test_move_fallback
273  // #389: rvp::move should fall-through to copy on non-movable objects
274  struct MoveIssue1 {
275  int v;
276  explicit MoveIssue1(int v) : v{v} {}
277  MoveIssue1(const MoveIssue1 &c) = default;
278  MoveIssue1(MoveIssue1 &&) = delete;
279  };
280  py::class_<MoveIssue1>(m, "MoveIssue1")
281  .def(py::init<int>())
282  .def_readwrite("value", &MoveIssue1::v);
283 
284  struct MoveIssue2 {
285  int v;
286  explicit MoveIssue2(int v) : v{v} {}
287  MoveIssue2(MoveIssue2 &&) = default;
288  };
289  py::class_<MoveIssue2>(m, "MoveIssue2")
290  .def(py::init<int>())
291  .def_readwrite("value", &MoveIssue2::v);
292 
293  // #2742: Don't expect ownership of raw pointer to `new`ed object to be transferred with
294  // `py::return_value_policy::move`
295  m.def(
296  "get_moveissue1",
297  [](int i) { return std::unique_ptr<MoveIssue1>(new MoveIssue1(i)); },
299  m.def("get_moveissue2", [](int i) { return MoveIssue2(i); }, py::return_value_policy::move);
300 
301  // Make sure that cast from pytype rvalue to other pytype works
302  m.def("get_pytype_rvalue_castissue", [](double i) { return py::float_(i).cast<py::int_>(); });
303 
304  py::class_<UnusualOpRef>(m, "UnusualOpRef");
305  m.def("CallCastUnusualOpRefConstRef",
306  []() { return CastUnusualOpRefConstRef(UnusualOpRef()); });
307  m.def("CallCastUnusualOpRefMovable", []() { return CastUnusualOpRefMovable(UnusualOpRef()); });
308 }
309 
310 /*
311  * Rest of the file:
312  * static_assert based tests for pybind11 adaptations of
313  * std::is_move_constructible, std::is_copy_constructible and
314  * std::is_copy_assignable (no adaptation of std::is_move_assignable).
315  * Difference between pybind11 and std traits: pybind11 traits will also check
316  * the contained value_types.
317  */
318 
319 struct NotMovable {
320  NotMovable() = default;
321  NotMovable(NotMovable const &) = default;
322  NotMovable(NotMovable &&) = delete;
323  NotMovable &operator=(NotMovable const &) = default;
324  NotMovable &operator=(NotMovable &&) = delete;
325 };
327  "!std::is_move_constructible<NotMovable>::value");
329  "std::is_copy_constructible<NotMovable>::value");
331  "!pybind11::detail::is_move_constructible<NotMovable>::value");
333  "pybind11::detail::is_copy_constructible<NotMovable>::value");
335  "!std::is_move_assignable<NotMovable>::value");
337  "std::is_copy_assignable<NotMovable>::value");
338 // pybind11 does not have this
339 // static_assert(!pybind11::detail::is_move_assignable<NotMovable>::value,
340 // "!pybind11::detail::is_move_assignable<NotMovable>::value");
342  "pybind11::detail::is_copy_assignable<NotMovable>::value");
343 
344 struct NotCopyable {
345  NotCopyable() = default;
346  NotCopyable(NotCopyable const &) = delete;
347  NotCopyable(NotCopyable &&) = default;
348  NotCopyable &operator=(NotCopyable const &) = delete;
349  NotCopyable &operator=(NotCopyable &&) = default;
350 };
352  "std::is_move_constructible<NotCopyable>::value");
354  "!std::is_copy_constructible<NotCopyable>::value");
356  "pybind11::detail::is_move_constructible<NotCopyable>::value");
358  "!pybind11::detail::is_copy_constructible<NotCopyable>::value");
360  "std::is_move_assignable<NotCopyable>::value");
362  "!std::is_copy_assignable<NotCopyable>::value");
363 // pybind11 does not have this
364 // static_assert(!pybind11::detail::is_move_assignable<NotCopyable>::value,
365 // "!pybind11::detail::is_move_assignable<NotCopyable>::value");
367  "!pybind11::detail::is_copy_assignable<NotCopyable>::value");
368 
370  NotCopyableNotMovable() = default;
375 };
377  "!std::is_move_constructible<NotCopyableNotMovable>::value");
379  "!std::is_copy_constructible<NotCopyableNotMovable>::value");
381  "!pybind11::detail::is_move_constructible<NotCopyableNotMovable>::value");
383  "!pybind11::detail::is_copy_constructible<NotCopyableNotMovable>::value");
385  "!std::is_move_assignable<NotCopyableNotMovable>::value");
387  "!std::is_copy_assignable<NotCopyableNotMovable>::value");
388 // pybind11 does not have this
389 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableNotMovable>::value,
390 // "!pybind11::detail::is_move_assignable<NotCopyableNotMovable>::value");
392  "!pybind11::detail::is_copy_assignable<NotCopyableNotMovable>::value");
393 
394 struct NotMovableVector : std::vector<NotMovable> {};
396  "std::is_move_constructible<NotMovableVector>::value");
398  "std::is_copy_constructible<NotMovableVector>::value");
400  "!pybind11::detail::is_move_constructible<NotMovableVector>::value");
402  "pybind11::detail::is_copy_constructible<NotMovableVector>::value");
404  "std::is_move_assignable<NotMovableVector>::value");
406  "std::is_copy_assignable<NotMovableVector>::value");
407 // pybind11 does not have this
408 // static_assert(!pybind11::detail::is_move_assignable<NotMovableVector>::value,
409 // "!pybind11::detail::is_move_assignable<NotMovableVector>::value");
411  "pybind11::detail::is_copy_assignable<NotMovableVector>::value");
412 
413 struct NotCopyableVector : std::vector<NotCopyable> {};
415  "std::is_move_constructible<NotCopyableVector>::value");
417  "std::is_copy_constructible<NotCopyableVector>::value");
419  "pybind11::detail::is_move_constructible<NotCopyableVector>::value");
421  "!pybind11::detail::is_copy_constructible<NotCopyableVector>::value");
423  "std::is_move_assignable<NotCopyableVector>::value");
425  "std::is_copy_assignable<NotCopyableVector>::value");
426 // pybind11 does not have this
427 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableVector>::value,
428 // "!pybind11::detail::is_move_assignable<NotCopyableVector>::value");
430  "!pybind11::detail::is_copy_assignable<NotCopyableVector>::value");
431 
432 struct NotCopyableNotMovableVector : std::vector<NotCopyableNotMovable> {};
434  "std::is_move_constructible<NotCopyableNotMovableVector>::value");
436  "std::is_copy_constructible<NotCopyableNotMovableVector>::value");
438  "!pybind11::detail::is_move_constructible<NotCopyableNotMovableVector>::value");
440  "!pybind11::detail::is_copy_constructible<NotCopyableNotMovableVector>::value");
442  "std::is_move_assignable<NotCopyableNotMovableVector>::value");
444  "std::is_copy_assignable<NotCopyableNotMovableVector>::value");
445 // pybind11 does not have this
446 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableNotMovableVector>::value,
447 // "!pybind11::detail::is_move_assignable<NotCopyableNotMovableVector>::value");
449  "!pybind11::detail::is_copy_assignable<NotCopyableNotMovableVector>::value");
450 
451 struct NotMovableMap : std::map<int, NotMovable> {};
453  "std::is_move_constructible<NotMovableMap>::value");
455  "std::is_copy_constructible<NotMovableMap>::value");
457  "!pybind11::detail::is_move_constructible<NotMovableMap>::value");
459  "pybind11::detail::is_copy_constructible<NotMovableMap>::value");
461  "std::is_move_assignable<NotMovableMap>::value");
463  "std::is_copy_assignable<NotMovableMap>::value");
464 // pybind11 does not have this
465 // static_assert(!pybind11::detail::is_move_assignable<NotMovableMap>::value,
466 // "!pybind11::detail::is_move_assignable<NotMovableMap>::value");
468  "pybind11::detail::is_copy_assignable<NotMovableMap>::value");
469 
470 struct NotCopyableMap : std::map<int, NotCopyable> {};
472  "std::is_move_constructible<NotCopyableMap>::value");
474  "std::is_copy_constructible<NotCopyableMap>::value");
476  "pybind11::detail::is_move_constructible<NotCopyableMap>::value");
478  "!pybind11::detail::is_copy_constructible<NotCopyableMap>::value");
480  "std::is_move_assignable<NotCopyableMap>::value");
482  "std::is_copy_assignable<NotCopyableMap>::value");
483 // pybind11 does not have this
484 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableMap>::value,
485 // "!pybind11::detail::is_move_assignable<NotCopyableMap>::value");
487  "!pybind11::detail::is_copy_assignable<NotCopyableMap>::value");
488 
489 struct NotCopyableNotMovableMap : std::map<int, NotCopyableNotMovable> {};
491  "std::is_move_constructible<NotCopyableNotMovableMap>::value");
493  "std::is_copy_constructible<NotCopyableNotMovableMap>::value");
495  "!pybind11::detail::is_move_constructible<NotCopyableNotMovableMap>::value");
497  "!pybind11::detail::is_copy_constructible<NotCopyableNotMovableMap>::value");
499  "std::is_move_assignable<NotCopyableNotMovableMap>::value");
501  "std::is_copy_assignable<NotCopyableNotMovableMap>::value");
502 // pybind11 does not have this
503 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableNotMovableMap>::value,
504 // "!pybind11::detail::is_move_assignable<NotCopyableNotMovableMap>::value");
506  "!pybind11::detail::is_copy_assignable<NotCopyableNotMovableMap>::value");
507 
508 struct RecursiveVector : std::vector<RecursiveVector> {};
510  "std::is_move_constructible<RecursiveVector>::value");
512  "std::is_copy_constructible<RecursiveVector>::value");
514  "pybind11::detail::is_move_constructible<RecursiveVector>::value");
516  "pybind11::detail::is_copy_constructible<RecursiveVector>::value");
518  "std::is_move_assignable<RecursiveVector>::value");
520  "std::is_copy_assignable<RecursiveVector>::value");
521 // pybind11 does not have this
522 // static_assert(!pybind11::detail::is_move_assignable<RecursiveVector>::value,
523 // "!pybind11::detail::is_move_assignable<RecursiveVector>::value");
525  "pybind11::detail::is_copy_assignable<RecursiveVector>::value");
526 
527 struct RecursiveMap : std::map<int, RecursiveMap> {};
529  "std::is_move_constructible<RecursiveMap>::value");
531  "std::is_copy_constructible<RecursiveMap>::value");
533  "pybind11::detail::is_move_constructible<RecursiveMap>::value");
535  "pybind11::detail::is_copy_constructible<RecursiveMap>::value");
537  "std::is_move_assignable<RecursiveMap>::value");
539  "std::is_copy_assignable<RecursiveMap>::value");
540 // pybind11 does not have this
541 // static_assert(!pybind11::detail::is_move_assignable<RecursiveMap>::value,
542 // "!pybind11::detail::is_move_assignable<RecursiveMap>::value");
544  "pybind11::detail::is_copy_assignable<RecursiveMap>::value");
CopyOnlyInt::CopyOnlyInt
CopyOnlyInt(int v)
Definition: test_copy_move.cpp:91
name
Annotation for function names.
Definition: attr.h:51
CopyOnlyInt::value
int value
Definition: test_copy_move.cpp:104
type_caster< CopyOnlyInt >::cast
static handle cast(const CopyOnlyInt *src, return_value_policy policy, handle parent)
Definition: test_copy_move.cpp:146
CopyOnlyInt::~CopyOnlyInt
~CopyOnlyInt()
Definition: test_copy_move.cpp:102
bytes
Definition: pytypes.h:1662
type_caster< CopyOnlyInt >::cast
static handle cast(const CopyOnlyInt &m, return_value_policy r, handle p)
Definition: test_copy_move.cpp:143
MoveOnlyInt::MoveOnlyInt
MoveOnlyInt(int v)
Definition: test_copy_move.cpp:45
const_name
constexpr descr< N - 1 > const_name(char const (&text)[N])
Definition: descr.h:60
d
static const double d[K][N]
Definition: igam.h:11
return_value_policy
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Definition: wrap/pybind11/include/pybind11/detail/common.h:499
CopyOnlyInt
Definition: test_copy_move.cpp:88
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
type_caster_generic::value
void * value
Definition: type_caster_base.h:828
NotCopyable
Definition: test_copy_move.cpp:344
MoveOrCopyInt::value
int value
Definition: test_copy_move.cpp:86
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
NotCopyableNotMovableMap
Definition: test_copy_move.cpp:489
NotMovable::operator=
NotMovable & operator=(NotMovable const &)=default
stl.h
m1
Matrix3d m1
Definition: IOFormat.cpp:2
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:80
MoveOnlyInt
Definition: test_copy_move.cpp:42
copy
int EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:29
lacking_move_ctor
Definition: test_copy_move.cpp:32
detail
Definition: testSerializationNonlinear.cpp:70
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:76
NotCopyableVector
Definition: test_copy_move.cpp:413
type_caster< CopyOnlyInt >::cast_op_type
pybind11::detail::cast_op_type< T > cast_op_type
Definition: test_copy_move.cpp:155
NotMovable
Definition: test_copy_move.cpp:319
constructor_stats.h
NotCopyableMap
Definition: test_copy_move.cpp:470
MoveOrCopyInt
Definition: test_copy_move.cpp:61
NotCopyable::operator=
NotCopyable & operator=(NotCopyable const &)=delete
print_copy_created
void print_copy_created(T *inst, Values &&...values)
Definition: constructor_stats.h:282
print_default_created
void print_default_created(T *inst, Values &&...values)
Definition: constructor_stats.h:304
type_caster< CopyOnlyInt >::load
bool load(handle src, bool)
Definition: test_copy_move.cpp:139
type_caster_base::cast
static handle cast(const itype &src, return_value_policy policy, handle parent)
Definition: type_caster_base.h:1105
m2
MatrixType m2(n_dims)
handle
Definition: pytypes.h:226
type_caster< CopyOnlyInt >::value
CopyOnlyInt value
Definition: test_copy_move.cpp:135
type_caster
Definition: cast.h:38
NotCopyableNotMovable::operator=
NotCopyableNotMovable & operator=(NotCopyableNotMovable const &)=delete
MoveOrCopyInt::MoveOrCopyInt
MoveOrCopyInt(const MoveOrCopyInt &c)
Definition: test_copy_move.cpp:74
handle::cast
T cast() const
Definition: cast.h:1234
MoveOnlyInt::MoveOnlyInt
MoveOnlyInt()
Definition: test_copy_move.cpp:44
RecursiveMap
Definition: test_copy_move.cpp:527
object::release
handle release()
Definition: pytypes.h:385
print_copy_assigned
void print_copy_assigned(T *inst, Values &&...values)
Definition: constructor_stats.h:294
MoveOrCopyInt::MoveOrCopyInt
MoveOrCopyInt()
Definition: test_copy_move.cpp:63
MoveOnlyInt::value
int value
Definition: test_copy_move.cpp:59
lacking_move_ctor::lacking_move_ctor
lacking_move_ctor()=default
std::swap
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)
Definition: NearestNeighbor.hpp:827
NotMovable::NotMovable
NotMovable()=default
CopyOnlyInt::CopyOnlyInt
CopyOnlyInt(const CopyOnlyInt &c)
Definition: test_copy_move.cpp:92
MoveOrCopyInt::operator=
MoveOrCopyInt & operator=(const MoveOrCopyInt &c)
Definition: test_copy_move.cpp:79
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
MoveOrCopyInt::MoveOrCopyInt
MoveOrCopyInt(int v)
Definition: test_copy_move.cpp:64
TEST_SUBMODULE
TEST_SUBMODULE(copy_move_policies, m)
Definition: test_copy_move.cpp:167
UnusualOpRef
Definition: pybind11_tests.h:57
RecursiveVector
Definition: test_copy_move.cpp:508
lacking_copy_ctor
Definition: test_copy_move.cpp:24
empty::get_one
static const derived & get_one()
Definition: test_copy_move.cpp:20
PYBIND11_TYPE_CASTER
#define PYBIND11_TYPE_CASTER(type, py_name)
Definition: cast.h:87
m3
static const DiscreteKey m3(M(3), 2)
MoveOrCopyInt::~MoveOrCopyInt
~MoveOrCopyInt()
Definition: test_copy_move.cpp:84
move
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Definition: cast.h:1243
type_caster< MoveOrCopyInt >::cast
static handle cast(const MoveOrCopyInt &m, return_value_policy r, handle p)
Definition: test_copy_move.cpp:127
empty
Definition: test_copy_move.cpp:19
NotCopyableNotMovable
Definition: test_copy_move.cpp:369
MoveOnlyInt::operator=
MoveOnlyInt & operator=(MoveOnlyInt &&m) noexcept
Definition: test_copy_move.cpp:50
MoveOnlyInt::~MoveOnlyInt
~MoveOnlyInt()
Definition: test_copy_move.cpp:57
type_caster< MoveOnlyInt >::load
bool load(handle src, bool)
Definition: test_copy_move.cpp:111
print_move_created
void print_move_created(T *inst, Values &&...values)
Definition: constructor_stats.h:288
CopyOnlyInt::CopyOnlyInt
CopyOnlyInt()
Definition: test_copy_move.cpp:90
pybind11_tests.h
MoveOrCopyInt::MoveOrCopyInt
MoveOrCopyInt(MoveOrCopyInt &&m) noexcept
Definition: test_copy_move.cpp:65
print_destroyed
void print_destroyed(T *inst, Values &&...values)
Definition: constructor_stats.h:314
type_caster< MoveOnlyInt >::cast
static handle cast(const MoveOnlyInt &m, return_value_policy r, handle p)
Definition: test_copy_move.cpp:115
p
float * p
Definition: Tutorial_Map_using.cpp:9
NotCopyableNotMovable::NotCopyableNotMovable
NotCopyableNotMovable()=default
CopyOnlyInt::operator=
CopyOnlyInt & operator=(const CopyOnlyInt &c)
Definition: test_copy_move.cpp:97
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
NotMovableVector
Definition: test_copy_move.cpp:394
pybind11
Definition: wrap/pybind11/pybind11/__init__.py:1
NotMovableMap
Definition: test_copy_move.cpp:451
print_move_assigned
void print_move_assigned(T *inst, Values &&...values)
Definition: constructor_stats.h:299
lacking_copy_ctor::lacking_copy_ctor
lacking_copy_ctor()=default
NotCopyableNotMovableVector
Definition: test_copy_move.cpp:432
empty::instance_
static derived instance_
Definition: test_copy_move.cpp:21
none
Definition: pytypes.h:1786
type_caster< MoveOrCopyInt >::load
bool load(handle src, bool)
Definition: test_copy_move.cpp:123
align_3::t
Point2 t(10, 10)
ConstructorStats::gc
static void gc()
Definition: constructor_stats.h:113
test_callbacks.value
value
Definition: test_callbacks.py:160
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Eigen::internal::cast
EIGEN_DEVICE_FUNC NewType cast(const OldType &x)
Definition: Eigen/src/Core/MathFunctions.h:460
MoveOrCopyInt::operator=
MoveOrCopyInt & operator=(MoveOrCopyInt &&m) noexcept
Definition: test_copy_move.cpp:69
NotCopyable::NotCopyable
NotCopyable()=default
print_created
void print_created(T *inst, Values &&...values)
Definition: constructor_stats.h:309
MoveOnlyInt::MoveOnlyInt
MoveOnlyInt(MoveOnlyInt &&m) noexcept
Definition: test_copy_move.cpp:46


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:39:27