github_331.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/at.hpp>
  5. #include <boost/hana/bool.hpp>
  6. #include <boost/hana/first.hpp>
  7. #include <boost/hana/integral_constant.hpp>
  8. #include <boost/hana/pair.hpp>
  9. #include <boost/hana/second.hpp>
  10. #include <boost/hana/tuple.hpp>
  11. #include <type_traits>
  12. #include <utility>
  13. namespace hana = boost::hana;
  14. // In GitHub issue #331, we noticed that `first` and `second` could sometimes
  15. // return the wrong member in case of nested pairs. This is due to the way we
  16. // inherit from base classes to enable EBO. We also check for `basic_tuple`,
  17. // because both are implemented similarly.
  18. int main() {
  19. {
  20. using Nested = hana::pair<hana::int_<1>, hana::int_<2>>;
  21. using Pair = hana::pair<hana::int_<0>, Nested>;
  22. Pair pair{};
  23. auto a = hana::first(pair);
  24. static_assert(std::is_same<decltype(a), hana::int_<0>>{}, "");
  25. auto b = hana::second(pair);
  26. static_assert(std::is_same<decltype(b), Nested>{}, "");
  27. }
  28. {
  29. using Nested = hana::basic_tuple<hana::int_<1>, hana::int_<2>>;
  30. using Tuple = hana::basic_tuple<hana::int_<0>, Nested>;
  31. Tuple tuple{};
  32. auto a = hana::at_c<0>(tuple);
  33. static_assert(std::is_same<decltype(a), hana::int_<0>>{}, "");
  34. auto b = hana::at_c<1>(tuple);
  35. static_assert(std::is_same<decltype(b), Nested>{}, "");
  36. }
  37. // Original test case submitted by Vittorio Romeo
  38. {
  39. hana::pair<hana::int_<1>, hana::bool_<false>> p{};
  40. auto copy = hana::make_pair(hana::int_c<0>, p);
  41. auto move = hana::make_pair(hana::int_c<0>, std::move(p));
  42. copy = move; // copy assign
  43. copy = std::move(move); // move assign
  44. }
  45. }