Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] Interest in the missing smart pointer (that can target the stack)
From: Rob Stewart (rob.stewart_at_[hidden])
Date: 2016-02-01 20:47:45


On January 31, 2016 3:59:35 PM EST, Noah <duneroadrunner_at_[hidden]> wrote:
> On 1/30/2016 11:16 AM, Steven Watanabe wrote:
> > It's not just about optimization. Initializing
> > a variable with a bogus value is no more correct
> > than leaving it uninitialized, and also prevents
> > tools like valgrind from detecting any real problems.
>
> Good point.
>
> I wonder though, does the same argument apply to say, std::vector?

It would if vector offered a constructor that was overloaded with a type that signaled the desire for no initialization.

> I mean, is the default initialization of std::vector to the empty state
> no
> more correct than leaving it uninitialized? Should we require
> programmers to explicitly set the vector state, even if they want to
> start off with an empty vector?

That's not what I asked you about. I asked if you provided a way to construct your types without initializing the data. I thought it was obvious that I was asking about a constructor overload taking an instance of, say, uninitialized_t as the mechanism. That is, one would create an instance from an argument named, say, "uninitialized."

> Or is the empty state somehow
> intrinsically valid, but the zero value for integers is not?

Zero may be a valid value with semantics different than "not set." An empty vector doesn't have a magic value that means it's actually empty.

___
Rob

(Sent from my portable computation engine)


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