Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2002-03-07 09:54:45


On Wednesday, March 6, 2002, at 10:55 PM, David Abrahams wrote:
>
> ----- Original Message -----
> From: "rwgk" <rwgk_at_[hidden]>
>
>> --- In boost_at_y..., Howard Hinnant <hinnant_at_t...> wrote:
>>> I can sympathize with that gripe. I'm sure I'll draw heat for this
>>> remark but it boils down to the decision that double() means zero
>>> initialize instead of uninitialized. Imho that one was big a
>> mistake,
>>> and I see no way of backing out of it completely.
>>
>> I could not agree more. As it stands, because of problems like
>> that, doing numerics with C++ feels like being imprisoned on
>> Alcatraz, in a cell with a direct view of the San Francisco
>> skyline. The good life is so close, but how can I get there?
>
> I disagree. Not that there isn't a problem, but I think you've
> misperceived its nature. The built-ins are not the problem: we have a
> way to create an uinitialized built-in, but I believe that
> http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/1999/n1191.pdf explains
> quite nicely why double() /must/ initialize its result.

Thanks for the link. It is a very nice write up that I was not aware
of. And I was very interested to learn some of the history which I was
ignorant of. But I think we'll just have to agree to disagree. I still
think the wrong decision was made. But it has been made, and I respect
that. There's no going back. And since there is no going back, I see
little reason to debate the decision with the benefit of 20/20
hindsight. Had I been in the position to contribute to this decision
when it was made, it is quite likely I would have made the same mistake.

I believe the way forward is to create new containers and elements that
take advantage of the flexibility in C++ and do not zero initialize.
It's not that much work.

template <class T>
struct cart_complex
{
      T real;
      T imag;
      cart_complex() {}
      cart_complex(const T& r, const T& i = T())
         : real(r), imag(i) {}
      ...
};
...
cart_complex<double>* vec = new cart_complex<double>[1000];

Maybe wrap it up in a smart pointer that handles arrays

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk