Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / hana / test / tuple / cnstr.convert_copy.cpp
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
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/tuple.hpp>
7 namespace hana = boost::hana;
8
9
10 struct A {
11     int id_;
12     constexpr A(int i) : id_(i) {}
13     friend constexpr bool operator==(const A& x, const A& y)
14     { return x.id_ == y.id_; }
15 };
16
17 struct B {
18     int id_;
19     explicit B(int i) : id_(i) {}
20 };
21
22 struct C {
23     int id_;
24     constexpr explicit C(int i) : id_(i) {}
25     friend constexpr bool operator==(const C& x, const C& y)
26     { return x.id_ == y.id_; }
27 };
28
29 struct D : B {
30     explicit D(int i) : B(i) {}
31 };
32
33
34 int main() {
35     {
36         using T0 = hana::tuple<double>;
37         using T1 = hana::tuple<int>;
38         T0 t0(2.5);
39         T1 t1 = t0;
40         BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
41     }
42     {
43         using T0 = hana::tuple<double>;
44         using T1 = hana::tuple<A>;
45         constexpr T0 t0(2.5);
46         constexpr T1 t1 = t0;
47         static_assert(hana::at_c<0>(t1) == 2, "");
48     }
49     {
50         using T0 = hana::tuple<int>;
51         using T1 = hana::tuple<C>;
52         constexpr T0 t0(2);
53         constexpr T1 t1{t0};
54         static_assert(hana::at_c<0>(t1) == C(2), "");
55     }
56     {
57         using T0 = hana::tuple<double, char>;
58         using T1 = hana::tuple<int, int>;
59         T0 t0(2.5, 'a');
60         T1 t1 = t0;
61         BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
62         BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
63     }
64     {
65         using T0 = hana::tuple<double, char, D>;
66         using T1 = hana::tuple<int, int, B>;
67         T0 t0(2.5, 'a', D(3));
68         T1 t1 = t0;
69         BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
70         BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
71         BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 3);
72     }
73     {
74         D d(3);
75         using T0 = hana::tuple<double, char, D&>;
76         using T1 = hana::tuple<int, int, B&>;
77         T0 t0(2.5, 'a', d);
78         T1 t1 = t0;
79         d.id_ = 2;
80         BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
81         BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
82         BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 2);
83     }
84     {
85         using T0 = hana::tuple<double, char, int>;
86         using T1 = hana::tuple<int, int, B>;
87         T0 t0(2.5, 'a', 3);
88         T1 t1(t0);
89         BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t1) == 2);
90         BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t1) == int('a'));
91         BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t1).id_ == 3);
92     }
93 }