cnstr.convert_copy.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 A {
  8. int id_;
  9. constexpr A(int i) : id_(i) {}
  10. friend constexpr bool operator==(const A& x, const A& y)
  11. { return x.id_ == y.id_; }
  12. };
  13. struct B {
  14. int id_;
  15. explicit B(int i) : id_(i) {}
  16. };
  17. struct C {
  18. int id_;
  19. constexpr explicit C(int i) : id_(i) {}
  20. friend constexpr bool operator==(const C& x, const C& y)
  21. { return x.id_ == y.id_; }
  22. };
  23. struct D : B {
  24. explicit D(int i) : B(i) {}
  25. };
  26. int main() {
  27. {
  28. using T0 = hana::tuple<double>;
  29. using T1 = hana::tuple<int>;
  30. T0 t0(2.5);
  31. T1 t1 = t0;
  32. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  33. }
  34. {
  35. using T0 = hana::tuple<double>;
  36. using T1 = hana::tuple<A>;
  37. constexpr T0 t0(2.5);
  38. constexpr T1 t1 = t0;
  39. static_assert(hana::at_c<0>(t1) == 2, "");
  40. }
  41. {
  42. using T0 = hana::tuple<int>;
  43. using T1 = hana::tuple<C>;
  44. constexpr T0 t0(2);
  45. constexpr T1 t1{t0};
  46. static_assert(hana::at_c<0>(t1) == C(2), "");
  47. }
  48. {
  49. using T0 = hana::tuple<double, char>;
  50. using T1 = hana::tuple<int, int>;
  51. T0 t0(2.5, 'a');
  52. T1 t1 = 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. }
  56. {
  57. using T0 = hana::tuple<double, char, D>;
  58. using T1 = hana::tuple<int, int, B>;
  59. T0 t0(2.5, 'a', D(3));
  60. T1 t1 = t0;
  61. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  62. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  63. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 3);
  64. }
  65. {
  66. D d(3);
  67. using T0 = hana::tuple<double, char, D&>;
  68. using T1 = hana::tuple<int, int, B&>;
  69. T0 t0(2.5, 'a', d);
  70. T1 t1 = t0;
  71. d.id_ = 2;
  72. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  73. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  74. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 2);
  75. }
  76. {
  77. using T0 = hana::tuple<double, char, int>;
  78. using T1 = hana::tuple<int, int, B>;
  79. T0 t0(2.5, 'a', 3);
  80. T1 t1(t0);
  81. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
  82. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
  83. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 3);
  84. }
  85. }