In this case, as you noticed, there are two possible ways of matching the signature with the template. The first pattern template<class T> T sqrt(T)can be matched. Having T, equal complex<double>, makes a function (specialized specialization) with a signature complex<double> sqrt(complex<double>).
The second pattern template<class T> complex<T> sqrt(complex<T>)can also be matched. In this case, setting Tto doubledoes specialization with the same signature as the specialization of the first template.
: , complex<T>. , T - : :
template<class T> T sqrt(T);
template<class U> complex<U> sqrt(complex<U>);
, , . complex<double> T U, .