You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.4 KiB

8 years ago
  1. /*
  2. tests/test_copy_move_policies.cpp -- 'copy' and 'move'
  3. return value policies
  4. Copyright (c) 2016 Ben North <ben@redfrontdoor.org>
  5. All rights reserved. Use of this source code is governed by a
  6. BSD-style license that can be found in the LICENSE file.
  7. */
  8. #include "pybind11_tests.h"
  9. template <typename derived>
  10. struct empty {
  11. static const derived& get_one() { return instance_; }
  12. static derived instance_;
  13. };
  14. struct lacking_copy_ctor : public empty<lacking_copy_ctor> {
  15. lacking_copy_ctor() {}
  16. lacking_copy_ctor(const lacking_copy_ctor& other) = delete;
  17. };
  18. template <> lacking_copy_ctor empty<lacking_copy_ctor>::instance_ = {};
  19. struct lacking_move_ctor : public empty<lacking_move_ctor> {
  20. lacking_move_ctor() {}
  21. lacking_move_ctor(const lacking_move_ctor& other) = delete;
  22. lacking_move_ctor(lacking_move_ctor&& other) = delete;
  23. };
  24. template <> lacking_move_ctor empty<lacking_move_ctor>::instance_ = {};
  25. test_initializer copy_move_policies([](py::module &m) {
  26. py::class_<lacking_copy_ctor>(m, "lacking_copy_ctor")
  27. .def_static("get_one", &lacking_copy_ctor::get_one,
  28. py::return_value_policy::copy);
  29. py::class_<lacking_move_ctor>(m, "lacking_move_ctor")
  30. .def_static("get_one", &lacking_move_ctor::get_one,
  31. py::return_value_policy::move);
  32. });