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