]>
Commit | Line | Data |
---|---|---|
b32b8144 | 1 | // Copyright Louis Dionne 2013-2017 |
7c673cae FG |
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> | |
92f5a8d4 | 8 | #include <boost/hana/not.hpp> |
7c673cae FG |
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 | struct f { template <typename ...> struct apply { struct type; }; }; | |
18 | ||
19 | template <typename F, typename ...T> | |
20 | constexpr auto valid_call(F f, T ...t) -> decltype(((void)f(t...)), true) | |
21 | { return true; } | |
22 | constexpr auto valid_call(...) | |
23 | { return false; } | |
24 | ||
25 | BOOST_HANA_CONSTANT_CHECK(hana::equal( | |
26 | hana::metafunction_class<f>(), | |
27 | hana::type_c<f::apply<>::type> | |
28 | )); | |
29 | BOOST_HANA_CONSTANT_CHECK(hana::equal( | |
30 | hana::metafunction_class<f>(hana::type_c<x1>), | |
31 | hana::type_c<f::apply<x1>::type> | |
32 | )); | |
33 | BOOST_HANA_CONSTANT_CHECK(hana::equal( | |
34 | hana::metafunction_class<f>(hana::type_c<x1>, hana::type_c<x2>), | |
35 | hana::type_c<f::apply<x1, x2>::type> | |
36 | )); | |
37 | BOOST_HANA_CONSTANT_CHECK(hana::equal( | |
38 | hana::metafunction_class<f>(hana::type_c<x1>, hana::type_c<x2>, hana::type_c<x3>), | |
39 | hana::type_c<f::apply<x1, x2, x3>::type> | |
40 | )); | |
41 | ||
42 | using F = decltype(hana::metafunction_class<f>); | |
43 | static_assert(std::is_same<F::apply<>, f::apply<>>{}, ""); | |
44 | static_assert(std::is_same<F::apply<x1>, f::apply<x1>>{}, ""); | |
45 | static_assert(std::is_same<F::apply<x1, x2>, f::apply<x1, x2>>{}, ""); | |
46 | static_assert(std::is_same<F::apply<x1, x2, x3>, f::apply<x1, x2, x3>>{}, ""); | |
47 | ||
48 | // Make sure we're SFINAE-friendly | |
49 | struct no_type { template <typename ...> struct apply { }; }; | |
50 | static_assert(!valid_call(hana::metafunction_class<no_type>), ""); | |
51 | static_assert(!valid_call(hana::metafunction_class<no_type>, hana::type_c<x1>), ""); | |
52 | ||
53 | // Make sure we model the Metafunction concept | |
54 | static_assert(hana::Metafunction<decltype(hana::metafunction_class<f>)>::value, ""); | |
55 | static_assert(hana::Metafunction<decltype(hana::metafunction_class<f>)&>::value, ""); | |
56 | ||
92f5a8d4 TL |
57 | // Make sure metafunction_class is SFINAE-friendly |
58 | struct not_a_mfc1 { template <typename ...> struct apply { }; }; | |
59 | struct not_a_mfc2 { }; | |
60 | BOOST_HANA_CONSTANT_CHECK(hana::not_( | |
61 | hana::is_valid(hana::metafunction_class<not_a_mfc1>)(hana::type_c<void>) | |
62 | )); | |
63 | BOOST_HANA_CONSTANT_CHECK(hana::not_( | |
64 | hana::is_valid(hana::metafunction_class<not_a_mfc2>)(hana::type_c<void>) | |
65 | )); | |
66 | ||
7c673cae FG |
67 | |
68 | // Make sure we don't read from a non-constexpr variable | |
69 | int main() { | |
70 | auto t = hana::type_c<x1>; | |
71 | constexpr auto r = hana::metafunction_class<f>(t); | |
72 | (void)r; | |
73 | } |