move_only.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/at.hpp>
  5. #include <boost/hana/back.hpp>
  6. #include <boost/hana/front.hpp>
  7. #include <boost/hana/tuple.hpp>
  8. #include <utility>
  9. namespace hana = boost::hana;
  10. // This test checks for move-only friendliness and reference semantics.
  11. struct MoveOnly {
  12. MoveOnly() = default;
  13. MoveOnly(MoveOnly&&) = default;
  14. MoveOnly& operator=(MoveOnly&&) = default;
  15. MoveOnly(MoveOnly const&) = delete;
  16. MoveOnly& operator=(MoveOnly const&) = delete;
  17. };
  18. int main() {
  19. {
  20. auto xs = hana::make_tuple(MoveOnly{});
  21. auto by_val = [](auto) { };
  22. by_val(std::move(xs));
  23. by_val(hana::front(std::move(xs)));
  24. by_val(hana::at_c<0>(std::move(xs)));
  25. by_val(hana::back(std::move(xs)));
  26. }
  27. {
  28. auto const& xs = hana::make_tuple(MoveOnly{});
  29. auto by_const_ref = [](auto const&) { };
  30. by_const_ref(xs);
  31. by_const_ref(hana::front(xs));
  32. by_const_ref(hana::at_c<0>(xs));
  33. by_const_ref(hana::back(xs));
  34. }
  35. {
  36. auto xs = hana::make_tuple(MoveOnly{});
  37. auto by_ref = [](auto&) { };
  38. by_ref(xs);
  39. by_ref(hana::front(xs));
  40. by_ref(hana::at_c<0>(xs));
  41. by_ref(hana::back(xs));
  42. }
  43. }