Subject: Re: [boost] Interest in StaticVector - fixed capacity vector
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-10-14 07:03:33
Andrew Hundt wrote:
> On Thu, Oct 13, 2011 at 10:36 PM, Nevin Liber
> <nevin_at_[hidden]> wrote:
> > On 13 October 2011 18:08, Andrew Hundt <athundt_at_[hidden]>
> >> After comments by Nate Ridge, Dave Abrahams, and others, I
> >> have become convinced that push_back should be unchecked
> >> and exceeding the bounds should be undefined, with an option
> >> to turn on checking.
> > While I really disagree with this (as there are both use
> > cases for it and, more importantly, it is no longer a drop in
> > replacement for vector because your push_back will now behave
> > differently),
> While I wish it could be a drop in replacement, I think it
> would be unreasonable to throw bad_alloc, since no allocations
> even happen at all. Thus, it couldn't be a truly drop in
> replacement anyway.
That's a weak argument. An exception on exceeding capacity would be a point of consistency. The exception isn't the same in each case, of course, but both could be std::exception derivates, which could still be useful.
> Additionally, I found that since the behavior of accessing
> vector.begin()-1 is undefined, that makes an undeniably
> compelling argument that the correct behavior for accessing
> StaticVector.end()+1 should also be undefined.
*v.end() and v.end() + 1 are undefined, so of course *(v.end() + 1) is undefined. However, that doesn't advance your point. It is always undefined behavior to try to access beyond the size. That has nothing to do with capacity, which is the point under discussion.
I'm not necessarily arguing for an exception on exceeding the capacity. I'm just trying to flag argumentation issues.
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk