Suppose you have something like
template <typename, typename, int, typename, int, typename...> struct P
and you want to reverse the typename... part only. Now you've already written the generic reverse transformation:
// Reverse<Pack<Types...>>::type is Pack<Types'...>, where Types'... is Types... reversed.
template <typename, typename> struct ReverseHelper;
template <template <typename...> class P, typename Pack>
struct ReverseHelper<P<>, Pack> {
using type = Pack;
};
template <template <typename...> class P, typename First, typename... Rest, typename... Types>
struct ReverseHelper<P<First, Rest...>, P<Types...>> : ReverseHelper<P<Rest...>, P<First, Types...>> {};
template <typename> struct Reverse;
template <template <typename...> class P, typename... Types>
struct Reverse<P<Types...>> : ReverseHelper<P<Types...>, P<>> {};
Of course, we could rewrite the above with template <typename, typename, int, typename, int, typename...> class P instead, but then we would have to do so again and again for other template signatures if we want to do the same thing. So how to make the approach by using Reverse itself?
For example, let's suppose we have
template <typename> struct Foo;
template <typename> struct Bar;
template <template <typename, typename, int, typename, int, typename...> class P, typename U, typename V,
int M, typename W, int N, typename... Args>
struct Foo> {};
Let's have Foo<P<U,V,M,W,N, Args...>> derive from Bar<P<U,V,M,W,N, ArgsReversed...>>'. How to accomplish this using the definedReverse` from above?
Aucun commentaire:
Enregistrer un commentaire