Boost logo

Boost :

From: Gero Peterhoff (g.peterhoff_at_[hidden])
Date: 2021-02-08 18:38:46

It would be very desirable to implement all conversion ctors generically so that both directions work:
std::complex<double> a{1.1, 2.2};
std::complex<int> b{a}; // works
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()};
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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at