I tried using CTAD with SFINAE in partial specializations, but it doesn't compile unless I add a seemingly useless deduction guide. What's the reason/limitation behind?
template<typename T, typename Enable = void>
struct A;
template<typename T>
struct A< T, std::enable_if_t<std::is_arithmetic_v<T>>>
{
A(T) { std::cout << "Numerical"; }
};
template<typename T>
struct A<T, std::enable_if_t<!std::is_arithmetic_v<T>>>
{
A(T) { std::cout << "Other"; }
};
template<typename T>
A(T)->A<T>; //Need to have this, otherwise doesn't compile
int main()
{
A a{ 1 };
}
Implicitly generated deduction guides mirror the constructors of the primary template only, not of the specializations.
It will work if you get rid of one of the specializations, and move code from it into the primary template: