Yes.
First, how to do it. Then why shouldn't you do it.
How to do it:
Write a rearrangement that takes a list of elements kN and groups it into N groups k alternating. Groups can be template<class...>struct types{}; .
Then write apply, which accepts the groups template<class...>class Z and a class... (aka types<...> ) and applies Z to the contents of each package, returning types<...> result.
Then collapse the contents of types<...> using template<class A, class B> struct and_types:std::integral_constant<bool, A{}&&B{}>{}; .
I would find this mostly meaningless, so I will not implement it. This should be easy with a decent metaprogramming library; most of the above operations are standard.
Why you shouldn't
But actually, given your example, just do the following:
template<class...Ts> struct and_types:std::true_type{}; template<class T0, class...Ts> struct and_types<T0,Ts...>:std::integral_constant<bool, T0{} && and_types<Ts...>{}>{};
Then:
std::enable_if_t<and_types<std::is_convertible<Args2, Args1>...>{}>
performs this work. All the shuffles are just noise.
With support for fold ... from C ++ 1z, we also get rid of and_types and just use && and ...
Yakk
source share