/* @copyright Louis Dionne 2014 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #include #include #include using namespace boost::hana; struct x1; struct x2; struct x3; // metafunction namespace tc1 { template struct f { struct type; }; using F = decltype(metafunction); BOOST_HANA_CONSTANT_CHECK(metafunction() == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction(type) == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction(type, type) == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction(type, type, type) == type::type>); static_assert(std::is_same, f<>>::value, ""); static_assert(std::is_same, f>::value, ""); static_assert(std::is_same, f>::value, ""); static_assert(std::is_same, f>::value, ""); } // metafunction_class namespace tc2 { struct f { template struct apply { struct type; }; }; using F = decltype(metafunction_class); BOOST_HANA_CONSTANT_CHECK(metafunction_class() == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction_class(type) == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction_class(type, type) == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction_class(type, type, type) == type::type>); static_assert(std::is_same, f::apply<>>::value, ""); static_assert(std::is_same, f::apply>::value, ""); static_assert(std::is_same, f::apply>::value, ""); static_assert(std::is_same, f::apply>::value, ""); } // template_ namespace tc3 { template struct f; using F = decltype(template_); BOOST_HANA_CONSTANT_CHECK(template_() == type>); BOOST_HANA_CONSTANT_CHECK(template_(type) == type>); BOOST_HANA_CONSTANT_CHECK(template_(type, type) == type>); BOOST_HANA_CONSTANT_CHECK(template_(type, type, type) == type>); static_assert(std::is_same::type, f<>>::value, ""); static_assert(std::is_same::type, f>::value, ""); static_assert(std::is_same::type, f>::value, ""); static_assert(std::is_same::type, f>::value, ""); } // trait namespace tc4 { template struct f { }; // make sure `trait(...)` returns the right type static_assert(std::is_same()), f<>>{}, ""); static_assert(std::is_same(type)), f>{}, ""); static_assert(std::is_same(type, type)), f>{}, ""); static_assert(std::is_same(type, type, type)), f>{}, ""); // make sure we can perform the call; we already made sure the return type was correct constexpr auto a = trait(); constexpr auto b = trait(type); constexpr auto c = trait(type, type); constexpr auto d = trait(type, type, type); } // trait_ namespace tc5 { struct x1 { }; struct x2 { }; struct x3 { }; template struct f { }; // make sure `trait_(...)` returns the right type static_assert(std::is_same()), f<>>{}, ""); static_assert(std::is_same(x1{})), f>{}, ""); static_assert(std::is_same(x1{}, x2{})), f>{}, ""); static_assert(std::is_same(x1{}, x2{}, x3{})), f>{}, ""); // make sure we can perform the call; we already made sure the return type was correct constexpr auto a = trait_(); constexpr auto b = trait_(x1{}); constexpr auto c = trait_(x1{}, x2{}); constexpr auto d = trait_(x1{}, x2{}, x3{}); } int main() { }