|
Boost : |
From: rwgk (rwgk_at_[hidden])
Date: 2001-12-21 18:36:43
--- In boost_at_y..., "rwgk" <rwgk_at_y...> wrote:
> > 2) subviews with other value_type
> > Apparantly, when creating a sub-view, the value_type is
> automatically
> > the same as the value_type of the original matrix. Is it possible
to
> > take e.g. a double-view on a complex matrix ?
>
> Is there a type-safe, portable way of obtaining a double* view of
an
> individual std::complex<double>?
>
> Would this work?
>
> std::complex<double> c;
> double* a = &c.real();
To answer my own question: it does not. std::complex<T>::real is
defined as:
T real() const { return re; }
The value is passed as a temporary.
Wonderful.
In the "C++ Programming Language" p.680 Bjarne Stroustrup writes:
"One could - barely - imagine a standard library complex that used a
different representation."
I guess he wrote this before boost::array was invented.
What about:
template <class T> class complex : public boost::array<T, 2> {
//...
};
complex<double> c;
double* a = c.elems;
IMHO this makes a lot more sense. Right now I cannot see how to do
this with std::complex without using reinterpret_cast<double*>. If
the standard does not provide a guarantee for the storage order of
the real and the imaginary part, this is not portable. -- Please let
me know if this view is not correct.
Ralf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk