pair_interop.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright Louis Dionne 2013-2016
  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/first.hpp>
  6. #include <boost/hana/pair.hpp>
  7. #include <boost/hana/second.hpp>
  8. #include <boost/hana/tuple.hpp>
  9. namespace hana = boost::hana;
  10. // This test makes sure that tuples containing pairs behave properly. It is
  11. // useful to test this specific case because tuple and pair (may) share a lot
  12. // of implementation details (for EBO), and that can easily lead to subtle bugs.
  13. // For example, if both pair and tuple inherit from similar base classes for
  14. // EBO, accessing a tuple of pairs or a pair of tuples (which requires some
  15. // base class casting magic) can lead to ambiguous overloads.
  16. int main() {
  17. struct empty1 { };
  18. struct empty2 { };
  19. {
  20. hana::tuple<hana::pair<empty1, empty2>> t{};
  21. hana::first(hana::at_c<0>(t));
  22. hana::second(hana::at_c<0>(t));
  23. }
  24. {
  25. hana::tuple<hana::pair<int, empty2>> t{};
  26. hana::first(hana::at_c<0>(t));
  27. hana::second(hana::at_c<0>(t));
  28. }
  29. {
  30. hana::tuple<hana::pair<int, int>> t{};
  31. hana::first(hana::at_c<0>(t));
  32. hana::second(hana::at_c<0>(t));
  33. }
  34. {
  35. hana::tuple<hana::pair<empty1, int>> t{};
  36. hana::first(hana::at_c<0>(t));
  37. hana::second(hana::at_c<0>(t));
  38. }
  39. {
  40. hana::pair<hana::tuple<>, hana::tuple<>> p{};
  41. hana::first(p);
  42. hana::second(p);
  43. }
  44. {
  45. hana::pair<hana::tuple<int>, hana::tuple<int>> p{};
  46. hana::first(p);
  47. hana::second(p);
  48. }
  49. {
  50. hana::pair<hana::tuple<>, hana::tuple<int>> p{};
  51. hana::first(p);
  52. hana::second(p);
  53. }
  54. {
  55. hana::pair<hana::tuple<empty1>, hana::tuple<empty2>> p{};
  56. hana::first(p);
  57. hana::second(p);
  58. }
  59. {
  60. hana::pair<hana::tuple<empty1, empty2>, hana::tuple<empty2>> p{};
  61. hana::first(p);
  62. hana::second(p);
  63. }
  64. {
  65. hana::pair<hana::tuple<empty1, empty2>, hana::tuple<empty1, empty2>> p{};
  66. hana::first(p);
  67. hana::second(p);
  68. }
  69. }