]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/type/template.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / hana / test / type / template.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)
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 template <typename ...> struct f;
18
19 BOOST_HANA_CONSTANT_CHECK(hana::equal(
20 hana::template_<f>(),
21 hana::type_c<f<>>
22 ));
23 BOOST_HANA_CONSTANT_CHECK(hana::equal(
24 hana::template_<f>(hana::type_c<x1>),
25 hana::type_c<f<x1>>
26 ));
27 BOOST_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 ));
31 BOOST_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
36 using F = decltype(hana::template_<f>);
37 static_assert(std::is_same<F::apply<>::type, f<>>{}, "");
38 static_assert(std::is_same<F::apply<x1>::type, f<x1>>{}, "");
39 static_assert(std::is_same<F::apply<x1, x2>::type, f<x1, x2>>{}, "");
40 static_assert(std::is_same<F::apply<x1, x2, x3>::type, f<x1, x2, x3>>{}, "");
41
42 // Make sure we model the Metafunction concept
43 static_assert(hana::Metafunction<decltype(hana::template_<f>)>::value, "");
44 static_assert(hana::Metafunction<decltype(hana::template_<f>)&>::value, "");
45
46 // Make sure we can use aliases
47 template <typename T> using alias = T;
48 static_assert(hana::template_<alias>(hana::type_c<x1>) == hana::type_c<x1>, "");
49
50 // Make sure template_ is SFINAE-friendly
51 template <typename T> struct unary;
52 BOOST_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
57 int main() {
58 auto t = hana::type_c<x1>;
59 constexpr auto r = hana::template_<f>(t);
60 (void)r;
61 }