It would be very desirable to implement all conversion ctors generically so that both directions work: 1) std::complex<double> a{1.1, 2.2}; std::complex<int> b{a}; // works 2) std::complex<int> a{1, 2}; std::complex<double> b{a}; // doesn't work without explicit call std::complex<double> b{a.real(), a.imag()}; or std::complex<double> b{double(a.real()), double(a.imag())}; to prevent warnings. This is cumbersome, confusing and a source of errors. Am 08.02.21 um 19:04 schrieb John Maddock via Boost:
On 08/02/2021 17:30, Gero Peterhoff via Boost wrote:
That's the problem: the generic std::complex class has generic conversion ctors, the FP specializations don't. I don't understand why this is done.
Actually the generic template specification is redundant given that only float/double/long double specializations are allowed.
BTW the specializations do have converting constructors, but they are explicit when narrowing which is the right design IMO.