1// Copyright Louis Dionne 2013-2022
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>
12namespace hana = boost::hana;
13
14
15struct x1; struct x2; struct x3;
16struct y1 { }; struct y2 { }; struct y3 { };
17template <typename ...> struct f;
18
19BOOST_HANA_CONSTANT_CHECK(hana::equal(
20 hana::template_<f>(),
21 hana::type_c<f<>>
22));
23BOOST_HANA_CONSTANT_CHECK(hana::equal(
24 hana::template_<f>(hana::type_c<x1>),
25 hana::type_c<f<x1>>
26));
27BOOST_HANA_CONSTANT_CHECK(hana::equal(
28 hana::template_<f>(hana::type_c<x1>, hana::type_c<x2>),
29 hana::type_c<f<x1, x2>>
30));
31BOOST_HANA_CONSTANT_CHECK(hana::equal(
32 hana::template_<f>(hana::type_c<x1>, hana::type_c<x2>, hana::type_c<x3>),
33 hana::type_c<f<x1, x2, x3>>
34));
35
36using F = decltype(hana::template_<f>);
37static_assert(std::is_same<F::apply<>::type, f<>>{}, "");
38static_assert(std::is_same<F::apply<x1>::type, f<x1>>{}, "");
39static_assert(std::is_same<F::apply<x1, x2>::type, f<x1, x2>>{}, "");
40static_assert(std::is_same<F::apply<x1, x2, x3>::type, f<x1, x2, x3>>{}, "");
41
42// Make sure we model the Metafunction concept
43static_assert(hana::Metafunction<decltype(hana::template_<f>)>::value, "");
44static_assert(hana::Metafunction<decltype(hana::template_<f>)&>::value, "");
45
46// Make sure we can use aliases
47template <typename T> using alias = T;
48static_assert(hana::template_<alias>(hana::type_c<x1>) == hana::type_c<x1>, "");
49
50// Make sure template_ is SFINAE-friendly
51template <typename T> struct unary;
52BOOST_HANA_CONSTANT_CHECK(hana::not_(
53 hana::is_valid(hana::template_<unary>)(hana::type_c<void>, hana::type_c<void>)
54));
55
56// Make sure we don't read from a non-constexpr variable
57int main() {
58 auto t = hana::type_c<x1>;
59 constexpr auto r = hana::template_<f>(t);
60 (void)r;
61}
62

source code of boost/libs/hana/test/type/template.cpp