]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/type/decltype.cpp
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)
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/equal.hpp>
7 #include <boost/hana/type.hpp>
8 namespace hana
= boost::hana
;
11 using Function
= void();
19 BOOST_HANA_CONSTANT_CHECK(hana::equal(
24 BOOST_HANA_CONSTANT_CHECK(hana::equal(
30 // [cv-qualified] reference types
35 BOOST_HANA_CONSTANT_CHECK(hana::equal(
36 hana::decltype_(static_cast<T
&>(t
)),
40 BOOST_HANA_CONSTANT_CHECK(hana::equal(
41 hana::decltype_(static_cast<T
const&>(t
)),
45 BOOST_HANA_CONSTANT_CHECK(hana::equal(
46 hana::decltype_(static_cast<T
volatile&>(t
)),
47 hana::type_c
<T
volatile>
50 BOOST_HANA_CONSTANT_CHECK(hana::equal(
51 hana::decltype_(static_cast<T
const volatile&>(t
)),
52 hana::type_c
<T
const volatile>
56 // [cv-qualified] rvalue reference types
61 BOOST_HANA_CONSTANT_CHECK(hana::equal(
62 hana::decltype_(static_cast<T
&&>(t
)),
66 BOOST_HANA_CONSTANT_CHECK(hana::equal(
67 hana::decltype_(static_cast<T
const &&>(t
)),
71 BOOST_HANA_CONSTANT_CHECK(hana::equal(
72 hana::decltype_(static_cast<T
volatile&&>(t
)),
73 hana::type_c
<T
volatile>
76 BOOST_HANA_CONSTANT_CHECK(hana::equal(
77 hana::decltype_(static_cast<T
const volatile&&>(t
)),
78 hana::type_c
<T
const volatile>
82 // decltype_(type_c<T>) is the identity function
85 auto const type_const
= hana::type_c
<T
>;
86 auto const& type_const_ref
= hana::type_c
<T
>;
87 auto& type_ref
= hana::type_c
<T
>;
88 auto&& type_ref_ref
= static_cast<decltype(type_ref
)&&>(type_ref
);
90 BOOST_HANA_CONSTANT_CHECK(hana::equal(
91 hana::decltype_(hana::type_c
<T
>),
95 BOOST_HANA_CONSTANT_CHECK(hana::equal(
96 hana::decltype_(type_const
),
100 BOOST_HANA_CONSTANT_CHECK(hana::equal(
101 hana::decltype_(type_const_ref
),
105 BOOST_HANA_CONSTANT_CHECK(hana::equal(
106 hana::decltype_(type_ref
),
110 BOOST_HANA_CONSTANT_CHECK(hana::equal(
111 hana::decltype_(type_ref_ref
),
116 // make sure we don't read from non-constexpr variables
119 auto t
= hana::type_c
<T
>;
121 constexpr auto r1
= hana::decltype_(t
); (void)r1
;
122 constexpr auto r2
= hana::decltype_(x
); (void)r2
;
125 // decltype_ with builtin arrays, function pointers and other weirdos
131 A
const& a_const_ref
= a
;
133 BOOST_HANA_CONSTANT_CHECK(hana::equal(
138 BOOST_HANA_CONSTANT_CHECK(hana::equal(
139 hana::decltype_(a_ref
),
143 BOOST_HANA_CONSTANT_CHECK(hana::equal(
144 hana::decltype_(a_const_ref
),
145 hana::type_c
<A
const>
149 using Fptr
= int(*)();
152 Fptr
const& f_const_ref
= f
;
154 BOOST_HANA_CONSTANT_CHECK(hana::equal(
159 BOOST_HANA_CONSTANT_CHECK(hana::equal(
160 hana::decltype_(f_ref
),
164 BOOST_HANA_CONSTANT_CHECK(hana::equal(
165 hana::decltype_(f_const_ref
),
166 hana::type_c
<Fptr
const>
170 Function
& function_ref
= function
;
172 BOOST_HANA_CONSTANT_CHECK(hana::equal(
173 hana::decltype_(function
),
174 hana::type_c
<Function
>
177 BOOST_HANA_CONSTANT_CHECK(hana::equal(
178 hana::decltype_(function_ref
),
179 hana::type_c
<Function
>