I have a class template Z that I would like specialize when passed a type that is an any instantiation of a particular template N:
struct L {
template <typename S> void foo(S &) {/*...*/}
};
template <class T>
struct M {
template <typename S> void foo(S &) {/*...*/}
};
template <class T>
struct N {
template <typename S> void foo(S &) {/*...*/}
};
// I'd like to specialize this for TY==N<anything>
template <typename TX, typename TY>
struct Z {
void bar(TX &tx) { /*...*/ ty->foo(tx); /*...*/ }
TY *ty;
};
Since Z<int, L> and Z<int, N<int>> and Z<int, M<int>> are all valid use cases, I can’t do anything along the lines of turning Z into a template template, and there is a compelling complexity reduction possible in Z<TX, TY>::bar(TX &) when TY is a class built from N. Is there a way to achieve this?
This should effect the specialization you desire:
Zgets specialized when the first parameter isTX, and the second parameter isN<ANY>. A quick illustration:Results in the output: