]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/type/metafunction.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)
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/concept/metafunction.hpp>
7 #include <boost/hana/equal.hpp>
8 #include <boost/hana/type.hpp>
10 #include <type_traits>
11 namespace hana
= boost::hana
;
14 struct x1
; struct x2
; struct x3
;
15 struct y1
{ }; struct y2
{ }; struct y3
{ };
16 template <typename
...> struct f
{ struct type
; };
18 template <typename F
, typename
...T
>
19 constexpr auto valid_call(F f
, T
...t
) -> decltype(((void)f(t
...)), true)
21 constexpr auto valid_call(...)
24 BOOST_HANA_CONSTANT_CHECK(hana::equal(
25 hana::metafunction
<f
>(),
26 hana::type_c
<f
<>::type
>
29 BOOST_HANA_CONSTANT_CHECK(hana::equal(
30 hana::metafunction
<f
>(hana::type_c
<x1
>),
31 hana::type_c
<f
<x1
>::type
>
34 BOOST_HANA_CONSTANT_CHECK(hana::equal(
35 hana::metafunction
<f
>(hana::type_c
<x1
>, hana::type_c
<x2
>),
36 hana::type_c
<f
<x1
, x2
>::type
>
39 BOOST_HANA_CONSTANT_CHECK(hana::equal(
40 hana::metafunction
<f
>(hana::type_c
<x1
>, hana::type_c
<x2
>, hana::type_c
<x3
>),
41 hana::type_c
<f
<x1
, x2
, x3
>::type
>
44 using F
= decltype(hana::metafunction
<f
>);
45 static_assert(std::is_same
<F::apply
<>, f
<>>::value
, "");
46 static_assert(std::is_same
<F::apply
<x1
>, f
<x1
>>::value
, "");
47 static_assert(std::is_same
<F::apply
<x1
, x2
>, f
<x1
, x2
>>::value
, "");
48 static_assert(std::is_same
<F::apply
<x1
, x2
, x3
>, f
<x1
, x2
, x3
>>::value
, "");
50 // Make sure we're SFINAE-friendly
51 template <typename
...T
> struct no_type
{ };
52 static_assert(!valid_call(hana::metafunction
<no_type
>), "");
53 static_assert(!valid_call(hana::metafunction
<no_type
>, hana::type_c
<x1
>), "");
55 // Make sure we model the Metafunction concept
56 static_assert(hana::Metafunction
<decltype(hana::metafunction
<f
>)>::value
, "");
57 static_assert(hana::Metafunction
<decltype(hana::metafunction
<f
>)&>::value
, "");
60 // Make sure we don't read from a non-constexpr variable
62 auto t
= hana::type_c
<x1
>;
63 constexpr auto r
= hana::metafunction
<f
>(t
);