xtensor-stack / xtl

The x template library
BSD 3-Clause "New" or "Revised" License
207 stars 96 forks source link

Specialize xtl::xcomplex for non references #253

Open JohanMabille opened 3 years ago

JohanMabille commented 3 years ago

The current implementation of xtl::xcomplex prevents to reinterpret_cast it into an array of the underlying value_type, like one can do with std::complex (see http://eel.is/c++draft/complex.numbers.general). This is because xtl::complex stores the real and imaginay parts as two double. Even if this is almost always possible to reinterpret cast such a structure into an array, it is undefined behavior according to the standard.

A fix would be to specialize the implementation of xtl::xcomplex when its template parameters are not references. This would be a backward compatible change since only the storage of the data would change, not the APIs.

cc @serge-sans-paille