]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/test/type/metafunction_class.cpp
import new upstream nautilus stable release 14.2.8
[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>
92f5a8d4 8#include <boost/hana/not.hpp>
7c673cae
FG
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 { };
17struct f { template <typename ...> struct apply { struct type; }; };
18
19template <typename F, typename ...T>
20constexpr auto valid_call(F f, T ...t) -> decltype(((void)f(t...)), true)
21{ return true; }
22constexpr auto valid_call(...)
23{ return false; }
24
25BOOST_HANA_CONSTANT_CHECK(hana::equal(
26 hana::metafunction_class<f>(),
27 hana::type_c<f::apply<>::type>
28));
29BOOST_HANA_CONSTANT_CHECK(hana::equal(
30 hana::metafunction_class<f>(hana::type_c<x1>),
31 hana::type_c<f::apply<x1>::type>
32));
33BOOST_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));
37BOOST_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
42using F = decltype(hana::metafunction_class<f>);
43static_assert(std::is_same<F::apply<>, f::apply<>>{}, "");
44static_assert(std::is_same<F::apply<x1>, f::apply<x1>>{}, "");
45static_assert(std::is_same<F::apply<x1, x2>, f::apply<x1, x2>>{}, "");
46static_assert(std::is_same<F::apply<x1, x2, x3>, f::apply<x1, x2, x3>>{}, "");
47
48// Make sure we're SFINAE-friendly
49struct no_type { template <typename ...> struct apply { }; };
50static_assert(!valid_call(hana::metafunction_class<no_type>), "");
51static_assert(!valid_call(hana::metafunction_class<no_type>, hana::type_c<x1>), "");
52
53// Make sure we model the Metafunction concept
54static_assert(hana::Metafunction<decltype(hana::metafunction_class<f>)>::value, "");
55static_assert(hana::Metafunction<decltype(hana::metafunction_class<f>)&>::value, "");
56
92f5a8d4
TL
57// Make sure metafunction_class is SFINAE-friendly
58struct not_a_mfc1 { template <typename ...> struct apply { }; };
59struct not_a_mfc2 { };
60BOOST_HANA_CONSTANT_CHECK(hana::not_(
61 hana::is_valid(hana::metafunction_class<not_a_mfc1>)(hana::type_c<void>)
62));
63BOOST_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
69int main() {
70 auto t = hana::type_c<x1>;
71 constexpr auto r = hana::metafunction_class<f>(t);
72 (void)r;
73}