mercredi 27 mai 2015

Folding over arbitrarily many variadic packs

I'm reading through Eric Niebler's post on his tiny metaprogramming library. In trying to implement the pieces that he omits / lists as challenges, I am left with the following implementation of transform:

template <typename F, typename... As>
using meta_apply = typename F::template apply<As...>;

template <typename... >
struct typelist_transform;

// unary
template <typename... T, typename F>
struct typelist_transform<typelist<T...>, F> 
{
    using type = typelist<meta_apply<F,T>...>;
};

// binary
template <typename... T, typename... U, typename F>
struct typelist_transform<typelist<T...>, typelist<U...>, F>
{
    using type = typelist<meta_apply<F,T,U>...>;
};

This works, but seems very unsatisfactory to me - I need a partial specialization of typelist_transform for every number of "arguments" into F. Is there a better way to implement this metafunction?

Aucun commentaire:

Enregistrer un commentaire