The code is very simple and concise (YATC means yet another template class :))
template<typename T1, typename T2>
class YATC; /*declaration*/
template<typename T1>
class YATC<T1,T1> {};
template<typename T1, typename T2, typename T3>
class YATC<T1, YATC<T2, T3>> {};
int main()
{
YATC<int, YATC<int, double>> yatc;
return 0;
}
This black magic looks very disturbing for me.
I declared the class as a template class with two template arguments
T1,T2;I've expected that I can make specializations for
YATCclass based on idea that I can specificate definition of the class on two template arguments only;I've found out that actually I can make specialization using infinite template arguments like
typename T1, typename T2, typename T3but with some interesting restrictions:I cannot use
std::common_type_t<T1, T2>as second parameter forYATCspecialization. The compiler throws an error thatT2isn't used forYATC's specialization;However, I can use them for using specialization with instance of some template class that receives these arguments (as
YATC<T2, T3>);But! I still cannot instantiate the class with
YATC<int, int, double>, onlyYATC<int, YATC<int, double>>;
Why the such declaration is still valid but why I cannot instantiate the class with YATC<int, int, double>?