]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/pair/cnstr.default.cpp
f2519e011104136f76f197c8e41ce16426d9d0c0
1 // Copyright Louis Dionne 2013-2022
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)
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/first.hpp>
7 #include <boost/hana/pair.hpp>
8 #include <boost/hana/second.hpp>
10 #include <type_traits>
11 namespace hana
= boost::hana
;
16 explicit constexpr NoDefault(int) { }
19 struct NoDefault_nonempty
{
20 NoDefault_nonempty() = delete;
21 explicit constexpr NoDefault_nonempty(int k
) : i(k
) { }
26 DefaultOnly() = default;
27 DefaultOnly(DefaultOnly
const&) = delete;
28 DefaultOnly(DefaultOnly
&&) = delete;
31 struct NonConstexprDefault
{
32 NonConstexprDefault() { }
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);
42 // make sure it also works constexpr
44 constexpr hana::pair
<float, short*> p
;
45 static_assert(hana::first(p
) == 0.0f
, "");
46 static_assert(hana::second(p
) == nullptr, "");
49 // make sure the default constructor is not instantiated when the
50 // members of the pair are not default-constructible
52 using Pair1
= hana::pair
<NoDefault
, NoDefault
>;
53 Pair1 p1
{NoDefault
{1}, NoDefault
{2}}; (void)p1
;
54 static_assert(!std::is_default_constructible
<Pair1
>{}, "");
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
>{}, "");
61 // make sure it works when only the default constructor is defined
63 hana::pair
<DefaultOnly
, DefaultOnly
> p
;
68 hana::pair
<NonConstexprDefault
, NonConstexprDefault
> p
;