|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-03-08 10:51:18
----- Original Message -----
From: "Gabriel Dos Reis" <Gabriel.Dos-Reis_at_[hidden]>
To: <boost_at_[hidden]>
Cc: "Ralf W. Grosse-Kunstleve" <rwgk_at_[hidden]>
Sent: Friday, March 08, 2002 12:05 PM
Subject: Re: [boost] Re: std::complex design (Was: N-Dimensional array
library submission...)
> "David Abrahams" <david.abrahams_at_[hidden]> writes:
>
> | ----- Original Message -----
> | From: "Ralf W. Grosse-Kunstleve" <rwgk_at_[hidden]>
> |
> | >
> | > IMO complex<double>() should behave like double().
> |
> | Agreed.
>
> I'm perfectly fine with having complex<> default initialised as
> currently done. If there are needs not to initialize a large array of
> complex<>s then, in my opinion, appropritae constructs should be used
> instead of making complex<> in general not default initialized.
>
And for this, class optional<> could be used:
typedef complex<long double> Complex ;
vector< optional<Complex> > v(100000) ;
// v constructor does initialize the 'optional' objects, but they in turn
bypass Complex default-constructor, so the total initialization time is
*considerably* smaller compared to
vector<Complex> u(100000) ;
Additionally, v[0] is well defined: it is an object with the semantics of
'Complex*' (with a NULL value initially) .
Unless you previously did: v[0] = optional<Complex>( Complex(r,i) ); it
throws an exception if you try: *v[0].
Unfortunately, I haven't ask for a formal review of the optional class
because it relies on aligned storage in order to bypass default
construction, which is still under development.
(you can look for 'class_optional' in the files section)
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk