With C++20, is there a way to use class template argument deduction with an alias template that partially specializes a template class?
The following code shows what I'd like to achieve but fails to compile with g++12:
template <typename T, typename U> struct foo;
template <typename T> struct foo<T, int> {
const T t;
foo(T t) : t(t) {}
};
template <typename T> using foo_int = foo<T, int>;
int main() {
auto bar = foo_int(1.0); // FAILS
}
With this example, the defined constructor for foo<T, int>
is not considered when attempting to instantiate bar
.
If I use a derived class for foo_int
instead of a type alias, the same example works, but it's not really what I am trying to achieve. Similarly, I can make it work by replacing foo_int(1.0)
with foo_int<double>(1.0)
, but I would like to avoid that.