I want to specialize templates based on their inner arguments. I am using non-strict evaluation which makes things difficult.
The specializations should be based off of the least nested pattern match. For instance:
template<typename T>
struct data1;
template<typename T>
struct fun1 {
using type = data1<T>;
};
template<typename T>
struct fun2;
template<typename T>
struct fun2<data1<T>> {
using type = data1<T>;
};
fun2<data1<int>> x1; // this works as expected, T=int
fun2<data1<fun1<int>>>::type x2; // this works as expected, T=fun1<int>
fun2<fun1<int>>::type x3; // this should be specialized as fun2<data1<int>>, T=int
fun2<fun2<fun1<int>>>::type x4; // this should be specialized as fun2<data1<int>>, T=int
How can I do this?
You can just use a template template parameter:
Tests:
Live example on Ideone (with using-aliases changed to typedefs).