c++ - Handle partial type with Boost Hana -
what call partial type here that:
template < template <typename ...> typename skeleton, template <typename ...> typename wrappertype, typename ... pölicies > struct metastorage { template < typename ... ts > struct with_type { using type = skeleton<wrappertype<ts...>, policies...>; }; }; using partialtype = metastorage<sk, wt, p1, p2, p3>; using finaltype = partialtype::with_type<t1, t2>;
i don't think fits hana philosophy , it's not readable if want split type more this.
so efficient way of doing boost hana?
edit :
by mean, way allow user create final type in several steps. can use partial type generate every final type. usual syntax , hana::type
.
with boost.hana can lift types values hana::type
, same templates using hana::template_
. can following:
#include <boost/hana.hpp> namespace hana = boost::hana; template <typename ...x> struct skeleton_t { }; constexpr auto skeleton = hana::template_<skeleton_t>; template <typename ...x> struct wrapper_t { }; constexpr auto wrapper = hana::template_<wrapper_t>; template <int i> struct policy_t { }; template <int i> constexpr auto policy = hana::type_c<policy_t<i>>; template <int i> struct foo_t { }; template <int i> constexpr auto foo = hana::type_c<foo_t<i>>; int main() { auto meta_storage = [](auto s, auto w, auto ...policies) { return [=](auto ...ts) { return s(w(ts...), policies...); }; }; auto partial = meta_storage(skeleton, wrapper, policy<1>, policy<2>); auto final_ = partial(foo<1>, foo<2>); skeleton_t<wrapper_t<foo_t<1>, foo_t<2>>, policy_t<1>, policy_t<2>> check = typename decltype(final_)::type{}; }
personally prefer not bother hana::template_
in cases can use function. use macro create tag type along corresponding hana::type
value reduce of setup see above main function.
Comments
Post a Comment