![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
Boost.Hana: MetafunctionBoost , ,
Variable Documentation
template<template< typename... > class F>
= [](basic_type<T>-or-T ...) { return hana::type_c<F<T...>>; } Поднимите шаблон к метафункции. При наличии класса шаблонов или псевдонимов шаблонов template_<f>(type_c<x>...) == type_c<f<x...>> decltype(template_<f>)::apply<x...>::type == f<x...>
Example// Copyright Louis Dionne 2013-2016 // 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 <boost/hana/assert.hpp> #include <boost/hana/equal.hpp> #include <boost/hana/type.hpp> #include <type_traits> namespace hana = boost::hana; template <typename ...> struct f; struct x; struct y; BOOST_HANA_CONSTANT_CHECK(hana::template_<f>() == hana::type_c<f<>>); BOOST_HANA_CONSTANT_CHECK(hana::template_<f>(hana::type_c<x>) == hana::type_c<f<x>>); BOOST_HANA_CONSTANT_CHECK(hana::template_<f>(hana::type_c<x>, hana::type_c<y>) == hana::type_c<f<x, y>>); static_assert(std::is_same< decltype(hana::template_<f>)::apply<x, y>::type, f<x, y> >::value, ""); int main() { }
template<template< typename... > class F>
= [](basic_type<T>-or-T ...) { return hana::type_c<typename F<T...>::type>; } Поднимите метафункцию в стиле MPL к метафункции. Учитывая метафункцию в стиле MPL, metafunction<f>(type_c<x>...) == type_c<f<x...>::type> decltype(metafunction<f>)::apply<x...>::type == f<x...>::type Example// Copyright Louis Dionne 2013-2016 // 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 <boost/hana/assert.hpp> #include <boost/hana/equal.hpp> #include <boost/hana/type.hpp> #include <type_traits> namespace hana = boost::hana; template <typename ...> struct f { struct type; }; struct x; struct y; BOOST_HANA_CONSTANT_CHECK(hana::metafunction<f>() == hana::type_c<f<>::type>); BOOST_HANA_CONSTANT_CHECK(hana::metafunction<f>(hana::type_c<x>) == hana::type_c<f<x>::type>); BOOST_HANA_CONSTANT_CHECK(hana::metafunction<f>(hana::type_c<x>, hana::type_c<y>) == hana::type_c<f<x, y>::type>); static_assert(std::is_same< decltype(hana::metafunction<f>)::apply<x, y>::type, f<x, y>::type >::value, ""); int main() { }
template<typename F >
= [](basic_type<T>-or-T ...) { } constexpr auto apply Invokes a Callable with the given arguments. Definition: apply.hpp:40 Поднимите класс метафункций в стиле MPL к метафункции. Учитывая класс метафункций в стиле MPL, metafunction_class<f>(type_c<x>...) == type_c<f::apply<x...>::type> Example// Copyright Louis Dionne 2013-2016 // 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 <boost/hana/assert.hpp> #include <boost/hana/equal.hpp> #include <boost/hana/type.hpp> #include <type_traits> namespace hana = boost::hana; struct x; struct y; BOOST_HANA_CONSTANT_CHECK(hana::metafunction_class<f>() == hana::type_c<f::apply<>::type>); BOOST_HANA_CONSTANT_CHECK(hana::metafunction_class<f>(hana::type_c<x>) == hana::type_c<f::apply<x>::type>); BOOST_HANA_CONSTANT_CHECK(hana::metafunction_class<f>(hana::type_c<x>, hana::type_c<y>) == hana::type_c<f::apply<x, y>::type>); static_assert(std::is_same< decltype(hana::metafunction_class<f>)::apply<x, y>::type, f::apply<x, y>::type >::value, ""); int main() { }
= [](auto f) { return [](basic_type<T>-or-T ...) { return decltype(f)::apply<T...>::type{}; }; } constexpr auto apply Invokes a Callable with the given arguments. Definition: apply.hpp:40 Превратите integral(f)(t...) == decltype(f(t...))::type{} Основным вариантом использования для
Example// Copyright Louis Dionne 2013-2016 // 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 <boost/hana/assert.hpp> #include <boost/hana/ext/std/integral_constant.hpp> #include <boost/hana/not.hpp> #include <boost/hana/type.hpp> #include <type_traits> namespace hana = boost::hana; constexpr auto is_void = hana::integral(hana::metafunction<std::is_void>); BOOST_HANA_CONSTANT_CHECK(is_void(hana::type_c<void>)); BOOST_HANA_CONSTANT_CHECK(hana::not_(is_void(hana::type_c<int>))); int main() { }
template<template< typename... > class F>
Отклонение от Example// Copyright Louis Dionne 2013-2016 // 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 <boost/hana/assert.hpp> #include <boost/hana/ext/std/integral_constant.hpp> #include <boost/hana/not.hpp> #include <boost/hana/type.hpp> #include <type_traits> namespace hana = boost::hana; BOOST_HANA_CONSTANT_CHECK(hana::trait<std::is_integral>(hana::type_c<int>)); BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::trait<std::is_integral>(hana::type_c<float>))); int main() { } Статья Boost.Hana: Metafunction раздела может быть полезна для разработчиков на c++ и boost. Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта. :: Главная :: ::
| ©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
| |