cnstr.copy.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/at.hpp>
  6. #include <boost/hana/basic_tuple.hpp>
  7. #include <laws/base.hpp>
  8. #include <string>
  9. namespace hana = boost::hana;
  10. struct Empty { };
  11. int main() {
  12. {
  13. using T = hana::basic_tuple<>;
  14. T t0;
  15. T t_implicit = t0;
  16. T t_explicit(t0);
  17. (void)t_explicit;
  18. (void)t_implicit;
  19. }
  20. {
  21. using T = hana::basic_tuple<int>;
  22. T t0(2);
  23. T t = t0;
  24. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == 2);
  25. }
  26. {
  27. using T = hana::basic_tuple<int, char>;
  28. T t0(2, 'a');
  29. T t = t0;
  30. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == 2);
  31. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t) == 'a');
  32. }
  33. {
  34. using T = hana::basic_tuple<int, char, std::string>;
  35. const T t0(2, 'a', "some text");
  36. T t = t0;
  37. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == 2);
  38. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t) == 'a');
  39. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t) == "some text");
  40. }
  41. {
  42. using T = hana::basic_tuple<int>;
  43. constexpr T t0(2);
  44. constexpr T t = t0;
  45. static_assert(hana::at_c<0>(t) == 2, "");
  46. }
  47. {
  48. using T = hana::basic_tuple<Empty>;
  49. constexpr T t0{};
  50. constexpr T t = t0;
  51. constexpr Empty e = hana::at_c<0>(t); (void)e;
  52. }
  53. {
  54. struct T { };
  55. struct U { };
  56. constexpr hana::basic_tuple<T, U> binary{};
  57. constexpr hana::basic_tuple<T, U> copy_implicit = binary;
  58. constexpr hana::basic_tuple<T, U> copy_explicit(binary);
  59. (void)copy_implicit;
  60. (void)copy_explicit;
  61. }
  62. // This used to fail
  63. {
  64. hana::basic_tuple<
  65. hana::test::ct_eq<0>,
  66. hana::test::ct_eq<2>,
  67. hana::test::ct_eq<4>
  68. > tuple{};
  69. hana::basic_tuple<
  70. hana::test::ct_eq<0>,
  71. hana::test::ct_eq<2>,
  72. hana::test::ct_eq<4>
  73. > copy(tuple);
  74. }
  75. }