assign.convert_move.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/assert.hpp>
  5. #include <boost/hana/tuple.hpp>
  6. #include <memory>
  7. #include <utility>
  8. namespace hana = boost::hana;
  9. struct B {
  10. int id_;
  11. explicit B(int i = 0) : id_(i) {}
  12. virtual ~B() {}
  13. };
  14. struct D : B {
  15. explicit D(int i) : B(i) {}
  16. };
  17. int main() {
  18. {
  19. using T0 = hana::tuple<double>;
  20. using T1 = hana::tuple<int>;
  21. T0 t0(2.5);
  22. T1 t1;
  23. t1 = std::move(t0);
  24. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  25. }
  26. {
  27. using T0 = hana::tuple<double, char>;
  28. using T1 = hana::tuple<int, int>;
  29. T0 t0(2.5, 'a');
  30. T1 t1;
  31. t1 = std::move(t0);
  32. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  33. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  34. }
  35. {
  36. using T0 = hana::tuple<double, char, D>;
  37. using T1 = hana::tuple<int, int, B>;
  38. T0 t0(2.5, 'a', D(3));
  39. T1 t1;
  40. t1 = std::move(t0);
  41. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  42. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  43. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 3);
  44. }
  45. {
  46. D d(3);
  47. D d2(2);
  48. using T0 = hana::tuple<double, char, D&>;
  49. using T1 = hana::tuple<int, int, B&>;
  50. T0 t0(2.5, 'a', d2);
  51. T1 t1(1.5, 'b', d);
  52. t1 = std::move(t0);
  53. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  54. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  55. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 2);
  56. }
  57. {
  58. using T0 = hana::tuple<double, char, std::unique_ptr<D>>;
  59. using T1 = hana::tuple<int, int, std::unique_ptr<B>>;
  60. T0 t0(2.5, 'a', std::unique_ptr<D>(new D(3)));
  61. T1 t1;
  62. t1 = std::move(t0);
  63. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  64. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  65. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1)->id_ == 3);
  66. }
  67. }