assign.copy.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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/config.hpp>
  6. #include <boost/hana/first.hpp>
  7. #include <boost/hana/pair.hpp>
  8. #include <boost/hana/second.hpp>
  9. namespace hana = boost::hana;
  10. constexpr auto in_constexpr_context(int a, short b) {
  11. hana::pair<int, short> p1(a, b);
  12. hana::pair<int, short> p2;
  13. hana::pair<double, long> p3;
  14. p2 = p1;
  15. p3 = p2;
  16. return p3;
  17. }
  18. int main() {
  19. {
  20. hana::pair<int, short> p1(3, 4);
  21. hana::pair<double, long> p2;
  22. p2 = p1;
  23. BOOST_HANA_RUNTIME_CHECK(hana::first(p2) == 3);
  24. BOOST_HANA_RUNTIME_CHECK(hana::second(p2) == 4);
  25. }
  26. // make sure that also works in a constexpr context
  27. // (test fails under GCC <= 6 due to buggy constexpr)
  28. #if BOOST_HANA_CONFIG_GCC >= BOOST_HANA_CONFIG_VERSION(7, 0, 0)
  29. {
  30. constexpr auto p = in_constexpr_context(3, 4);
  31. static_assert(hana::first(p) == 3, "");
  32. static_assert(hana::second(p) == 4, "");
  33. }
  34. #endif
  35. }