]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/test/type/metafunction_class.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / type / metafunction_class.cpp
CommitLineData
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>
8#include <boost/hana/type.hpp>
9
10#include <type_traits>
11namespace hana = boost::hana;
12
13
14struct x1; struct x2; struct x3;
15struct y1 { }; struct y2 { }; struct y3 { };
16struct f { template <typename ...> struct apply { struct type; }; };
17
18template <typename F, typename ...T>
19constexpr auto valid_call(F f, T ...t) -> decltype(((void)f(t...)), true)
20{ return true; }
21constexpr auto valid_call(...)
22{ return false; }
23
24BOOST_HANA_CONSTANT_CHECK(hana::equal(
25 hana::metafunction_class<f>(),
26 hana::type_c<f::apply<>::type>
27));
28BOOST_HANA_CONSTANT_CHECK(hana::equal(
29 hana::metafunction_class<f>(hana::type_c<x1>),
30 hana::type_c<f::apply<x1>::type>
31));
32BOOST_HANA_CONSTANT_CHECK(hana::equal(
33 hana::metafunction_class<f>(hana::type_c<x1>, hana::type_c<x2>),
34 hana::type_c<f::apply<x1, x2>::type>
35));
36BOOST_HANA_CONSTANT_CHECK(hana::equal(
37 hana::metafunction_class<f>(hana::type_c<x1>, hana::type_c<x2>, hana::type_c<x3>),
38 hana::type_c<f::apply<x1, x2, x3>::type>
39));
40
41using F = decltype(hana::metafunction_class<f>);
42static_assert(std::is_same<F::apply<>, f::apply<>>{}, "");
43static_assert(std::is_same<F::apply<x1>, f::apply<x1>>{}, "");
44static_assert(std::is_same<F::apply<x1, x2>, f::apply<x1, x2>>{}, "");
45static_assert(std::is_same<F::apply<x1, x2, x3>, f::apply<x1, x2, x3>>{}, "");
46
47// Make sure we're SFINAE-friendly
48struct no_type { template <typename ...> struct apply { }; };
49static_assert(!valid_call(hana::metafunction_class<no_type>), "");
50static_assert(!valid_call(hana::metafunction_class<no_type>, hana::type_c<x1>), "");
51
52// Make sure we model the Metafunction concept
53static_assert(hana::Metafunction<decltype(hana::metafunction_class<f>)>::value, "");
54static_assert(hana::Metafunction<decltype(hana::metafunction_class<f>)&>::value, "");
55
56
57// Make sure we don't read from a non-constexpr variable
58int main() {
59 auto t = hana::type_c<x1>;
60 constexpr auto r = hana::metafunction_class<f>(t);
61 (void)r;
62}