How do I define a Foo<n>
to be a Foo<X<n>>
for int n
?
template<int n> struct X{};
template<typename T> struct Foo{};
template<int n>
using Foo<n> = Foo<X<n>>;
int main(){
Foo<3> a; // same as Foo<X<3>>
Foo<X<3>> b;
}
I tried using
, type traits conditionals, default template arguments, renaming of Foo. I would know how to solve it with Foo<void,int>
by using a default argument in Foo and a conditional using statement; but I'd like to achieve a solution that requires no change of main
.
You can't.
The kind of template argument expect by Foo
according to your declaration template<typename T> struct Foo{};
is a type. You can't make it a non-type.
You also can't declare another class, class template, type alias or alias template with the same name in the same scope.
Even if you use different scopes, Foo
can only find one of these entities with the same name from the same scope. You can't see both of the at the same time. There is no "overload resolution" for class/alias templates.