]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/map/cnstr.default.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / map / 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/bool.hpp>
6 #include <boost/hana/fwd/hash.hpp>
7 #include <boost/hana/map.hpp>
8 #include <boost/hana/pair.hpp>
9 #include <boost/hana/type.hpp>
10
11 #include <type_traits>
12 namespace hana = boost::hana;
13
14
15 struct NoDefault {
16 NoDefault() = delete;
17 NoDefault(NoDefault const&) = default;
18 constexpr explicit NoDefault(int) { }
19 };
20
21 auto operator==(NoDefault const&, NoDefault const&) { return hana::true_c; }
22 auto operator!=(NoDefault const&, NoDefault const&) { return hana::false_c; }
23
24 // Note: It is also useful to check with a non-empty class, because that
25 // triggers different instantiations due to EBO.
26 struct NoDefault_nonempty {
27 NoDefault_nonempty() = delete;
28 NoDefault_nonempty(NoDefault_nonempty const&) = default;
29 constexpr explicit NoDefault_nonempty(int k) : i(k) { }
30 int i;
31 };
32
33 auto operator==(NoDefault_nonempty const&, NoDefault_nonempty const&) { return hana::true_c; }
34 auto operator!=(NoDefault_nonempty const&, NoDefault_nonempty const&) { return hana::false_c; }
35
36 struct Default {
37 Default() = default;
38 Default(Default const&) = default;
39 constexpr explicit Default(int) { }
40 };
41
42 auto operator==(Default const&, Default const&) { return hana::true_c; }
43 auto operator!=(Default const&, Default const&) { return hana::false_c; }
44
45 namespace boost { namespace hana {
46 template <>
47 struct hash_impl<NoDefault> {
48 static constexpr auto apply(NoDefault const&)
49 { return hana::type_c<NoDefault>; };
50 };
51
52 template <>
53 struct hash_impl<NoDefault_nonempty> {
54 static constexpr auto apply(NoDefault_nonempty const&)
55 { return hana::type_c<NoDefault_nonempty>; };
56 };
57
58 template <>
59 struct hash_impl<Default> {
60 static constexpr auto apply(Default const&)
61 { return hana::type_c<Default>; };
62 };
63 }}
64
65 int main() {
66 auto map1 = hana::make_map(hana::make_pair(Default(1), Default(1)));
67 static_assert(std::is_default_constructible<decltype(map1)>::value, "");
68
69 auto map2 = hana::make_map(hana::make_pair(NoDefault(1), NoDefault(1)));
70 static_assert(!std::is_default_constructible<decltype(map2)>::value, "");
71
72 auto map3 = hana::make_map(hana::make_pair(NoDefault_nonempty(1), NoDefault_nonempty(1)));
73 static_assert(!std::is_default_constructible<decltype(map3)>::value, "");
74 }