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 TEST_SUBMODULE(copy_move_policies, m) {
161  // test_lacking_copy_ctor
162  py::class_<lacking_copy_ctor>(m, "lacking_copy_ctor")
164  // test_lacking_move_ctor
165  py::class_<lacking_move_ctor>(m, "lacking_move_ctor")
167 
168  // test_move_and_copy_casts
169  // NOLINTNEXTLINE(performance-unnecessary-value-param)
170  m.def("move_and_copy_casts", [](const py::object &o) {
171  int r = 0;
172  r += py::cast<MoveOrCopyInt>(o).value; /* moves */
173  r += py::cast<MoveOnlyInt>(o).value; /* moves */
174  r += py::cast<CopyOnlyInt>(o).value; /* copies */
175  auto m1(py::cast<MoveOrCopyInt>(o)); /* moves */
176  auto m2(py::cast<MoveOnlyInt>(o)); /* moves */
177  auto m3(py::cast<CopyOnlyInt>(o)); /* copies */
178  r += m1.value + m2.value + m3.value;
179 
180  return r;
181  });
182 
183  // test_move_and_copy_loads
184  m.def("move_only", [](MoveOnlyInt m) { return m.value; });
185  // Changing this breaks the existing test: needs careful review.
186  // NOLINTNEXTLINE(performance-unnecessary-value-param)
187  m.def("move_or_copy", [](MoveOrCopyInt m) { return m.value; });
188  // Changing this breaks the existing test: needs careful review.
189  // NOLINTNEXTLINE(performance-unnecessary-value-param)
190  m.def("copy_only", [](CopyOnlyInt m) { return m.value; });
191  m.def("move_pair",
192  [](std::pair<MoveOnlyInt, MoveOrCopyInt> p) { return p.first.value + p.second.value; });
193  m.def("move_tuple", [](std::tuple<MoveOnlyInt, MoveOrCopyInt, MoveOnlyInt> t) {
194  return std::get<0>(t).value + std::get<1>(t).value + std::get<2>(t).value;
195  });
196  m.def("copy_tuple", [](std::tuple<CopyOnlyInt, CopyOnlyInt> t) {
197  return std::get<0>(t).value + std::get<1>(t).value;
198  });
199  m.def("move_copy_nested",
200  [](std::pair<MoveOnlyInt,
201  std::pair<std::tuple<MoveOrCopyInt, CopyOnlyInt, std::tuple<MoveOnlyInt>>,
202  MoveOrCopyInt>> x) {
203  return x.first.value + std::get<0>(x.second.first).value
204  + std::get<1>(x.second.first).value
205  + std::get<0>(std::get<2>(x.second.first)).value + x.second.second.value;
206  });
207  m.def("move_and_copy_cstats", []() {
209  // Reset counts to 0 so that previous tests don't affect later ones:
210  auto &mc = ConstructorStats::get<MoveOrCopyInt>();
211  mc.move_assignments = mc.move_constructions = mc.copy_assignments = mc.copy_constructions
212  = 0;
213  auto &mo = ConstructorStats::get<MoveOnlyInt>();
214  mo.move_assignments = mo.move_constructions = mo.copy_assignments = mo.copy_constructions
215  = 0;
216  auto &co = ConstructorStats::get<CopyOnlyInt>();
217  co.move_assignments = co.move_constructions = co.copy_assignments = co.copy_constructions
218  = 0;
219  py::dict d;
220  d["MoveOrCopyInt"] = py::cast(mc, py::return_value_policy::reference);
221  d["MoveOnlyInt"] = py::cast(mo, py::return_value_policy::reference);
222  d["CopyOnlyInt"] = py::cast(co, py::return_value_policy::reference);
223  return d;
224  });
225 #ifdef PYBIND11_HAS_OPTIONAL
226  // test_move_and_copy_load_optional
227  m.attr("has_optional") = true;
228  m.def("move_optional", [](std::optional<MoveOnlyInt> o) { return o->value; });
229  m.def("move_or_copy_optional", [](std::optional<MoveOrCopyInt> o) { return o->value; });
230  m.def("copy_optional", [](std::optional<CopyOnlyInt> o) { return o->value; });
231  m.def("move_optional_tuple",
232  [](std::optional<std::tuple<MoveOrCopyInt, MoveOnlyInt, CopyOnlyInt>> x) {
233  return std::get<0>(*x).value + std::get<1>(*x).value + std::get<2>(*x).value;
234  });
235 #else
236  m.attr("has_optional") = false;
237 #endif
238 
239  // #70 compilation issue if operator new is not public - simple body added
240  // but not needed on most compilers; MSVC and nvcc don't like a local
241  // struct not having a method defined when declared, since it can not be
242  // added later.
243  struct PrivateOpNew {
244  int value = 1;
245 
246  private:
247  void *operator new(size_t bytes) {
248  void *ptr = std::malloc(bytes);
249  if (ptr) {
250  return ptr;
251  }
252  throw std::bad_alloc{};
253  }
254  };
255  py::class_<PrivateOpNew>(m, "PrivateOpNew").def_readonly("value", &PrivateOpNew::value);
256  m.def("private_op_new_value", []() { return PrivateOpNew(); });
257  m.def(
258  "private_op_new_reference",
259  []() -> const PrivateOpNew & {
260  static PrivateOpNew x{};
261  return x;
262  },
263  py::return_value_policy::reference);
264 
265  // test_move_fallback
266  // #389: rvp::move should fall-through to copy on non-movable objects
267  struct MoveIssue1 {
268  int v;
269  explicit MoveIssue1(int v) : v{v} {}
270  MoveIssue1(const MoveIssue1 &c) = default;
271  MoveIssue1(MoveIssue1 &&) = delete;
272  };
273  py::class_<MoveIssue1>(m, "MoveIssue1")
274  .def(py::init<int>())
275  .def_readwrite("value", &MoveIssue1::v);
276 
277  struct MoveIssue2 {
278  int v;
279  explicit MoveIssue2(int v) : v{v} {}
280  MoveIssue2(MoveIssue2 &&) = default;
281  };
282  py::class_<MoveIssue2>(m, "MoveIssue2")
283  .def(py::init<int>())
284  .def_readwrite("value", &MoveIssue2::v);
285 
286  // #2742: Don't expect ownership of raw pointer to `new`ed object to be transferred with
287  // `py::return_value_policy::move`
288  m.def(
289  "get_moveissue1",
290  [](int i) { return std::unique_ptr<MoveIssue1>(new MoveIssue1(i)); },
292  m.def(
293  "get_moveissue2", [](int i) { return MoveIssue2(i); }, py::return_value_policy::move);
294 
295  // Make sure that cast from pytype rvalue to other pytype works
296  m.def("get_pytype_rvalue_castissue", [](double i) { return py::float_(i).cast<py::int_>(); });
297 }
298 
299 /*
300  * Rest of the file:
301  * static_assert based tests for pybind11 adaptations of
302  * std::is_move_constructible, std::is_copy_constructible and
303  * std::is_copy_assignable (no adaptation of std::is_move_assignable).
304  * Difference between pybind11 and std traits: pybind11 traits will also check
305  * the contained value_types.
306  */
307 
308 struct NotMovable {
309  NotMovable() = default;
310  NotMovable(NotMovable const &) = default;
311  NotMovable(NotMovable &&) = delete;
312  NotMovable &operator=(NotMovable const &) = default;
313  NotMovable &operator=(NotMovable &&) = delete;
314 };
316  "!std::is_move_constructible<NotMovable>::value");
318  "std::is_copy_constructible<NotMovable>::value");
320  "!pybind11::detail::is_move_constructible<NotMovable>::value");
322  "pybind11::detail::is_copy_constructible<NotMovable>::value");
324  "!std::is_move_assignable<NotMovable>::value");
326  "std::is_copy_assignable<NotMovable>::value");
327 // pybind11 does not have this
328 // static_assert(!pybind11::detail::is_move_assignable<NotMovable>::value,
329 // "!pybind11::detail::is_move_assignable<NotMovable>::value");
331  "pybind11::detail::is_copy_assignable<NotMovable>::value");
332 
333 struct NotCopyable {
334  NotCopyable() = default;
335  NotCopyable(NotCopyable const &) = delete;
336  NotCopyable(NotCopyable &&) = default;
337  NotCopyable &operator=(NotCopyable const &) = delete;
338  NotCopyable &operator=(NotCopyable &&) = default;
339 };
341  "std::is_move_constructible<NotCopyable>::value");
343  "!std::is_copy_constructible<NotCopyable>::value");
345  "pybind11::detail::is_move_constructible<NotCopyable>::value");
347  "!pybind11::detail::is_copy_constructible<NotCopyable>::value");
349  "std::is_move_assignable<NotCopyable>::value");
351  "!std::is_copy_assignable<NotCopyable>::value");
352 // pybind11 does not have this
353 // static_assert(!pybind11::detail::is_move_assignable<NotCopyable>::value,
354 // "!pybind11::detail::is_move_assignable<NotCopyable>::value");
356  "!pybind11::detail::is_copy_assignable<NotCopyable>::value");
357 
359  NotCopyableNotMovable() = default;
364 };
366  "!std::is_move_constructible<NotCopyableNotMovable>::value");
368  "!std::is_copy_constructible<NotCopyableNotMovable>::value");
370  "!pybind11::detail::is_move_constructible<NotCopyableNotMovable>::value");
372  "!pybind11::detail::is_copy_constructible<NotCopyableNotMovable>::value");
374  "!std::is_move_assignable<NotCopyableNotMovable>::value");
376  "!std::is_copy_assignable<NotCopyableNotMovable>::value");
377 // pybind11 does not have this
378 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableNotMovable>::value,
379 // "!pybind11::detail::is_move_assignable<NotCopyableNotMovable>::value");
381  "!pybind11::detail::is_copy_assignable<NotCopyableNotMovable>::value");
382 
383 struct NotMovableVector : std::vector<NotMovable> {};
385  "std::is_move_constructible<NotMovableVector>::value");
387  "std::is_copy_constructible<NotMovableVector>::value");
389  "!pybind11::detail::is_move_constructible<NotMovableVector>::value");
391  "pybind11::detail::is_copy_constructible<NotMovableVector>::value");
393  "std::is_move_assignable<NotMovableVector>::value");
395  "std::is_copy_assignable<NotMovableVector>::value");
396 // pybind11 does not have this
397 // static_assert(!pybind11::detail::is_move_assignable<NotMovableVector>::value,
398 // "!pybind11::detail::is_move_assignable<NotMovableVector>::value");
400  "pybind11::detail::is_copy_assignable<NotMovableVector>::value");
401 
402 struct NotCopyableVector : std::vector<NotCopyable> {};
404  "std::is_move_constructible<NotCopyableVector>::value");
406  "std::is_copy_constructible<NotCopyableVector>::value");
408  "pybind11::detail::is_move_constructible<NotCopyableVector>::value");
410  "!pybind11::detail::is_copy_constructible<NotCopyableVector>::value");
412  "std::is_move_assignable<NotCopyableVector>::value");
414  "std::is_copy_assignable<NotCopyableVector>::value");
415 // pybind11 does not have this
416 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableVector>::value,
417 // "!pybind11::detail::is_move_assignable<NotCopyableVector>::value");
419  "!pybind11::detail::is_copy_assignable<NotCopyableVector>::value");
420 
421 struct NotCopyableNotMovableVector : std::vector<NotCopyableNotMovable> {};
423  "std::is_move_constructible<NotCopyableNotMovableVector>::value");
425  "std::is_copy_constructible<NotCopyableNotMovableVector>::value");
427  "!pybind11::detail::is_move_constructible<NotCopyableNotMovableVector>::value");
429  "!pybind11::detail::is_copy_constructible<NotCopyableNotMovableVector>::value");
431  "std::is_move_assignable<NotCopyableNotMovableVector>::value");
433  "std::is_copy_assignable<NotCopyableNotMovableVector>::value");
434 // pybind11 does not have this
435 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableNotMovableVector>::value,
436 // "!pybind11::detail::is_move_assignable<NotCopyableNotMovableVector>::value");
438  "!pybind11::detail::is_copy_assignable<NotCopyableNotMovableVector>::value");
439 
440 struct NotMovableMap : std::map<int, NotMovable> {};
442  "std::is_move_constructible<NotMovableMap>::value");
444  "std::is_copy_constructible<NotMovableMap>::value");
446  "!pybind11::detail::is_move_constructible<NotMovableMap>::value");
448  "pybind11::detail::is_copy_constructible<NotMovableMap>::value");
450  "std::is_move_assignable<NotMovableMap>::value");
452  "std::is_copy_assignable<NotMovableMap>::value");
453 // pybind11 does not have this
454 // static_assert(!pybind11::detail::is_move_assignable<NotMovableMap>::value,
455 // "!pybind11::detail::is_move_assignable<NotMovableMap>::value");
457  "pybind11::detail::is_copy_assignable<NotMovableMap>::value");
458 
459 struct NotCopyableMap : std::map<int, NotCopyable> {};
461  "std::is_move_constructible<NotCopyableMap>::value");
463  "std::is_copy_constructible<NotCopyableMap>::value");
465  "pybind11::detail::is_move_constructible<NotCopyableMap>::value");
467  "!pybind11::detail::is_copy_constructible<NotCopyableMap>::value");
469  "std::is_move_assignable<NotCopyableMap>::value");
471  "std::is_copy_assignable<NotCopyableMap>::value");
472 // pybind11 does not have this
473 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableMap>::value,
474 // "!pybind11::detail::is_move_assignable<NotCopyableMap>::value");
476  "!pybind11::detail::is_copy_assignable<NotCopyableMap>::value");
477 
478 struct NotCopyableNotMovableMap : std::map<int, NotCopyableNotMovable> {};
480  "std::is_move_constructible<NotCopyableNotMovableMap>::value");
482  "std::is_copy_constructible<NotCopyableNotMovableMap>::value");
484  "!pybind11::detail::is_move_constructible<NotCopyableNotMovableMap>::value");
486  "!pybind11::detail::is_copy_constructible<NotCopyableNotMovableMap>::value");
488  "std::is_move_assignable<NotCopyableNotMovableMap>::value");
490  "std::is_copy_assignable<NotCopyableNotMovableMap>::value");
491 // pybind11 does not have this
492 // static_assert(!pybind11::detail::is_move_assignable<NotCopyableNotMovableMap>::value,
493 // "!pybind11::detail::is_move_assignable<NotCopyableNotMovableMap>::value");
495  "!pybind11::detail::is_copy_assignable<NotCopyableNotMovableMap>::value");
496 
497 struct RecursiveVector : std::vector<RecursiveVector> {};
499  "std::is_move_constructible<RecursiveVector>::value");
501  "std::is_copy_constructible<RecursiveVector>::value");
503  "pybind11::detail::is_move_constructible<RecursiveVector>::value");
505  "pybind11::detail::is_copy_constructible<RecursiveVector>::value");
507  "std::is_move_assignable<RecursiveVector>::value");
509  "std::is_copy_assignable<RecursiveVector>::value");
510 // pybind11 does not have this
511 // static_assert(!pybind11::detail::is_move_assignable<RecursiveVector>::value,
512 // "!pybind11::detail::is_move_assignable<RecursiveVector>::value");
514  "pybind11::detail::is_copy_assignable<RecursiveVector>::value");
515 
516 struct RecursiveMap : std::map<int, RecursiveMap> {};
518  "std::is_move_constructible<RecursiveMap>::value");
520  "std::is_copy_constructible<RecursiveMap>::value");
522  "pybind11::detail::is_move_constructible<RecursiveMap>::value");
524  "pybind11::detail::is_copy_constructible<RecursiveMap>::value");
526  "std::is_move_assignable<RecursiveMap>::value");
528  "std::is_copy_assignable<RecursiveMap>::value");
529 // pybind11 does not have this
530 // static_assert(!pybind11::detail::is_move_assignable<RecursiveMap>::value,
531 // "!pybind11::detail::is_move_assignable<RecursiveMap>::value");
533  "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:1620
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:485
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:795
NotCopyable
Definition: test_copy_move.cpp:333
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:478
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:402
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:308
constructor_stats.h
NotCopyableMap
Definition: test_copy_move.cpp:459
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:1072
m2
MatrixType m2(n_dims)
handle
Definition: pytypes.h:217
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:1110
MoveOnlyInt::MoveOnlyInt
MoveOnlyInt()
Definition: test_copy_move.cpp:44
RecursiveMap
Definition: test_copy_move.cpp:516
object::release
handle release()
Definition: pytypes.h:368
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:160
RecursiveVector
Definition: test_copy_move.cpp:497
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:85
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:1119
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:358
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:383
pybind11
Definition: wrap/pybind11/pybind11/__init__.py:1
NotMovableMap
Definition: test_copy_move.cpp:440
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:421
empty::instance_
static derived instance_
Definition: test_copy_move.cpp:21
none
Definition: pytypes.h:1744
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:158
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 Tue Jun 25 2024 03:05:28