From: Gabriel Dos Reis (Gabriel.Dos-Reis_at_[hidden])
Date: 2002-01-26 16:35:57
"David Abrahams" <david.abrahams_at_[hidden]> writes:
| > If std::complex was simply derived from boost::array<T, 2>,
| > portable conversions would be immediately possible, and you
| > could still provide iterators where they make sense.
| > To put it in more general terms: encapsulation is a great
| > idea, but can backfire if overused (as in std::complex, IMO).
I completely agree!
| I'm afraid that wouldn't work for you. Since complex<T> is a non-POD type
| for example, the compiler is not required to make it possible to portably
| convert it to/from a T* via reinterpret_cast
| What's needed here is a loosening of the restrictions on what constitutes a
I don't think that is sufficient in our case.
std::complex<> is overabstracted. Whereas the specification says that
it stores the Cartesian component, it doesn't say anything about the
precise layout. That is, even if the POD definition is weaken we
still have no guarantee about a std::complex<> layout. We need
additional restrictions -- such as those in C99, where a '_Complex T' is
said to have the same layout as an array of 2 Ts, slot 0 being the real
part and slot 1 being the imaginary part.
Furthermore, there ought to be an lvalue expression to access,
independently, each component of a std::complex<> -- something which is
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk