assign.convert_copy.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. namespace hana = boost::hana;
  7. struct B {
  8. int id_;
  9. explicit B(int i = 0) : id_(i) { }
  10. };
  11. struct D : B {
  12. explicit D(int i = 0) : B(i) { }
  13. };
  14. int main() {
  15. {
  16. using T0 = hana::tuple<double>;
  17. using T1 = hana::tuple<int>;
  18. T0 t0(2.5);
  19. T1 t1;
  20. t1 = t0;
  21. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  22. }
  23. {
  24. using T0 = hana::tuple<double, char>;
  25. using T1 = hana::tuple<int, int>;
  26. T0 t0(2.5, 'a');
  27. T1 t1;
  28. t1 = t0;
  29. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  30. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  31. }
  32. {
  33. using T0 = hana::tuple<double, char, D>;
  34. using T1 = hana::tuple<int, int, B>;
  35. T0 t0(2.5, 'a', D(3));
  36. T1 t1;
  37. t1 = t0;
  38. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  39. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  40. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 3);
  41. }
  42. {
  43. D d(3);
  44. D d2(2);
  45. using T0 = hana::tuple<double, char, D&>;
  46. using T1 = hana::tuple<int, int, B&>;
  47. T0 t0(2.5, 'a', d2);
  48. T1 t1(1.5, 'b', d);
  49. t1 = t0;
  50. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  51. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  52. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 2);
  53. }
  54. }