• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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>
10 
11 #include <type_traits>
12 namespace hana = boost::hana;
13 
14 
15 struct x1; struct x2; struct x3;
16 struct y1 { }; struct y2 { }; struct y3 { };
17 
18 template <typename ...> struct mf { struct type { }; };
19 struct mfc { template <typename ...> struct apply { struct type { }; }; };
20 template <typename ...> struct tpl { };
21 
22 // make sure `integral(f)(...)` returns the right type
23 static_assert(std::is_same<
24     decltype(hana::integral(hana::metafunction<mf>)()),
25     mf<>::type
26 >{}, "");
27 static_assert(std::is_same<
28     decltype(hana::integral(hana::metafunction<mf>)(hana::type_c<x1>)),
29     mf<x1>::type
30 >{}, "");
31 static_assert(std::is_same<
32     decltype(hana::integral(hana::metafunction<mf>)(hana::type_c<x1>, hana::type_c<x2>)),
33     mf<x1, x2>::type
34 >{}, "");
35 
36 static_assert(std::is_same<
37     decltype(hana::integral(hana::template_<tpl>)()),
38     tpl<>
39 >{}, "");
40 static_assert(std::is_same<
41     decltype(hana::integral(hana::template_<tpl>)(hana::type_c<x1>)),
42     tpl<x1>
43 >{}, "");
44 static_assert(std::is_same<
45     decltype(hana::integral(hana::template_<tpl>)(hana::type_c<x1>, hana::type_c<x2>)),
46     tpl<x1, x2>
47 >{}, "");
48 
49 static_assert(std::is_same<
50     decltype(hana::integral(hana::metafunction_class<mfc>)()),
51     mfc::apply<>::type
52 >{}, "");
53 static_assert(std::is_same<
54     decltype(hana::integral(hana::metafunction_class<mfc>)(hana::type_c<x1>)),
55     mfc::apply<x1>::type
56 >{}, "");
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
60 >{}, "");
61 
62 // Make sure integral is SFINAE-friendly
63 struct invalid_hana_metafunction {
64     template <typename ...> struct apply { /* missing type alias */ };
65 };
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>)
69 ));
70 
71 
main()72 int main() {
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;
78 
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);
82     (void)r;
83 }
84