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-04 05:45:30
On February 2, 2016 9:20:11 PM EST, Noah <duneroadrunner_at_[hidden]> wrote:
> On 2/2/2016 1:40 AM, Rob Stewart wrote:
> using the garbage value might be dangerous in some contexts.
> Yeah, you're right. But how rare are those contexts? I mean it's not
> rare for an integer to be used as an index into an array.
> If you're saying that you agree with the decision to enforce mandatory
> default initialization of std::vectors, but uninitialized construction
> is ok for integers because the most catastrophic consequences would
> happen a lower percentage of the time, I dunno, it seems to me this
> argument is a judgement call that depends on how much lower that
> percentage is, and the magnitude of the real world benefits of
> foregoing default initialization.
It's a lot simpler than that: Trust the Programmer. That's been part of C and C++ from the start. By all means default construct with zero-initialization and provide a converting constructor from numeric types. That will provide the safety you're after. However, rather than prevent a not uncommon use case, just make that use case possible.
[snip example of latent bug using native integer]
> So ideally what I would like is for boost to provide a set of types
> when used in lieu of the regular C++ types, ensure that the code is
> deterministic. Or as deterministic as possible. Because being
> deterministic increases the value and effectiveness of testing.
> > Adding a separate class or policy just to have the
> > uninitialized case is heavy, but the overload may not apply to all
> > specializations of the template.
> Yeah, I'm not sure either. Separate classes does seem heavy. But at
> least it's compile-time heavy, not run-time.
I meant that users have to know about more types and how to select among them or infer a programmer's intent from their use.
> Anyway I wonder if this is all moot. Have you looked at all at the
> numerics" library proposed in this newsgroup? The post from Jan 20 has
> links. That library seems use a template to generate classes of "safe"
> integers or whatever.
I have. I alluded to those when I mentioned the idea that your classes should do more for conversions, etc.
(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