]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/pair/cnstr.default.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / hana / test / pair / cnstr.default.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/first.hpp>
7 #include <boost/hana/pair.hpp>
8 #include <boost/hana/second.hpp>
9
10 #include <type_traits>
11 namespace hana = boost::hana;
12
13
14 struct NoDefault {
15 NoDefault() = delete;
16 explicit constexpr NoDefault(int) { }
17 };
18
19 struct NoDefault_nonempty {
20 NoDefault_nonempty() = delete;
21 explicit constexpr NoDefault_nonempty(int k) : i(k) { }
22 int i;
23 };
24
25 struct DefaultOnly {
26 DefaultOnly() = default;
27 DefaultOnly(DefaultOnly const&) = delete;
28 DefaultOnly(DefaultOnly&&) = delete;
29 };
30
31 struct NonConstexprDefault {
32 NonConstexprDefault() { }
33 };
34
35 int main() {
36 {
37 hana::pair<float, short*> p;
38 BOOST_HANA_RUNTIME_CHECK(hana::first(p) == 0.0f);
39 BOOST_HANA_RUNTIME_CHECK(hana::second(p) == nullptr);
40 }
41
42 // make sure it also works constexpr
43 {
44 constexpr hana::pair<float, short*> p;
45 static_assert(hana::first(p) == 0.0f, "");
46 static_assert(hana::second(p) == nullptr, "");
47 }
48
49 // make sure the default constructor is not instantiated when the
50 // members of the pair are not default-constructible
51 {
52 using Pair1 = hana::pair<NoDefault, NoDefault>;
53 Pair1 p1{NoDefault{1}, NoDefault{2}}; (void)p1;
54 static_assert(!std::is_default_constructible<Pair1>{}, "");
55
56 using Pair2 = hana::pair<NoDefault_nonempty, NoDefault_nonempty>;
57 Pair2 p2{NoDefault_nonempty{1}, NoDefault_nonempty{2}}; (void)p2;
58 static_assert(!std::is_default_constructible<Pair2>{}, "");
59 }
60
61 // make sure it works when only the default constructor is defined
62 {
63 hana::pair<DefaultOnly, DefaultOnly> p;
64 (void)p;
65 }
66
67 {
68 hana::pair<NonConstexprDefault, NonConstexprDefault> p;
69 (void)p;
70 }
71 }