cnstr.copy.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <string>
  7. namespace hana = boost::hana;
  8. struct Empty { };
  9. int main() {
  10. {
  11. using T = hana::tuple<>;
  12. T t0;
  13. T t_implicit = t0;
  14. T t_explicit(t0);
  15. (void)t_explicit;
  16. (void)t_implicit;
  17. }
  18. {
  19. using T = hana::tuple<int>;
  20. T t0(2);
  21. T t = t0;
  22. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == 2);
  23. }
  24. {
  25. using T = hana::tuple<int, char>;
  26. T t0(2, 'a');
  27. T t = t0;
  28. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == 2);
  29. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t) == 'a');
  30. }
  31. {
  32. using T = hana::tuple<int, char, std::string>;
  33. const T t0(2, 'a', "some text");
  34. T t = t0;
  35. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == 2);
  36. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t) == 'a');
  37. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t) == "some text");
  38. }
  39. {
  40. using T = hana::tuple<int>;
  41. constexpr T t0(2);
  42. constexpr T t = t0;
  43. static_assert(hana::at_c<0>(t) == 2, "");
  44. }
  45. {
  46. using T = hana::tuple<Empty>;
  47. constexpr T t0;
  48. constexpr T t = t0;
  49. constexpr Empty e = hana::at_c<0>(t); (void)e;
  50. }
  51. {
  52. struct T { };
  53. struct U { };
  54. constexpr hana::tuple<T, U> binary{};
  55. constexpr hana::tuple<T, U> copy_implicit = binary;
  56. constexpr hana::tuple<T, U> copy_explicit(binary);
  57. (void)copy_implicit;
  58. (void)copy_explicit;
  59. }
  60. }