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/not.hpp>
9 #include <boost/hana/type.hpp>
11 #include <type_traits>
12 namespace hana
= boost::hana
;
15 struct x1
; struct x2
; struct x3
;
16 struct y1
{ }; struct y2
{ }; struct y3
{ };
18 template <typename
...> struct mf
{ struct type
{ }; };
19 struct mfc
{ template <typename
...> struct apply
{ struct type
{ }; }; };
20 template <typename
...> struct tpl
{ };
22 // make sure `integral(f)(...)` returns the right type
23 static_assert(std::is_same
<
24 decltype(hana::integral(hana::metafunction
<mf
>)()),
27 static_assert(std::is_same
<
28 decltype(hana::integral(hana::metafunction
<mf
>)(hana::type_c
<x1
>)),
31 static_assert(std::is_same
<
32 decltype(hana::integral(hana::metafunction
<mf
>)(hana::type_c
<x1
>, hana::type_c
<x2
>)),
36 static_assert(std::is_same
<
37 decltype(hana::integral(hana::template_
<tpl
>)()),
40 static_assert(std::is_same
<
41 decltype(hana::integral(hana::template_
<tpl
>)(hana::type_c
<x1
>)),
44 static_assert(std::is_same
<
45 decltype(hana::integral(hana::template_
<tpl
>)(hana::type_c
<x1
>, hana::type_c
<x2
>)),
49 static_assert(std::is_same
<
50 decltype(hana::integral(hana::metafunction_class
<mfc
>)()),
53 static_assert(std::is_same
<
54 decltype(hana::integral(hana::metafunction_class
<mfc
>)(hana::type_c
<x1
>)),
57 static_assert(std::is_same
<
58 decltype(hana::integral(hana::metafunction_class
<mfc
>)(hana::type_c
<x1
>, hana::type_c
<x2
>)),
59 mfc::apply
<x1
, x2
>::type
62 // Make sure integral is SFINAE-friendly
63 struct invalid_hana_metafunction
{
64 template <typename
...> struct apply
{ /* missing type alias */ };
66 auto invalid_integral
= hana::integral(invalid_hana_metafunction
{});
67 BOOST_HANA_CONSTANT_CHECK(hana::not_(
68 hana::is_valid(invalid_integral
)(hana::type_c
<void>, hana::type_c
<void>)
73 // Make sure we can perform the call; we already made sure the return type was correct
74 constexpr auto a
= hana::integral(hana::metafunction
<mf
>)(); (void)a
;
75 constexpr auto b
= hana::integral(hana::metafunction
<mf
>)(hana::type_c
<x1
>); (void)b
;
76 constexpr auto c
= hana::integral(hana::metafunction
<mf
>)(hana::type_c
<x1
>, hana::type_c
<x2
>); (void)c
;
77 constexpr auto d
= hana::integral(hana::metafunction
<mf
>)(hana::type_c
<x1
>, hana::type_c
<x2
>, hana::type_c
<x3
>); (void)d
;
79 // Make sure we don't read from a non-constexpr variable
80 auto t
= hana::type_c
<x1
>;
81 constexpr auto r
= hana::integral(hana::metafunction
<mf
>)(t
);