|
Boost : |
Subject: Re: [boost] Interest in StaticVector - fixed capacity vector
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2011-10-14 20:27:23
On 14 October 2011 16:07, Peter Dimov <pdimov_at_[hidden]> wrote:
> Christian Holmquist wrote:
>
>> On 14 October 2011 12:55, Dave Abrahams <dave_at_[hidden]> wrote:
>> > Is throwing an exception going to turn an incorrect program into a
>> > correct one?
>>
>> I'm probably completely misunderstanding your point of view, or rather,
>> what is your point of view?
>>
>
> He's saying that if a program does a push_back when the capacity has been
> reached, this program has a logic error, and throwing an exception will not
> make the error go away.
To me this is like saying that if any exception is thrown, the program has a
logic error. It's not very helpful though. All code which does not deal with
global OS data (such as the heap, files, etc) can be written as no throw, if
enough details are exposed for the user. But I want code to throw so that I
don't need to worry and check all details everywhere.
How much juggling would I need to do to parse a comma separated text of
integers into a static_vector?
static_vector<int, 4> v;
spirit::parse("1, 2, 3, 4, 5", int_ % ',', space, v); // undefined
behaviour???
Sure, the above can be seen as having a 'logic error' because the grammar
says parse N but the capacity can only handle N < 5. But the the code can
never parse N anyways, because sooner or later even a std::vector runs out
of memory space.
I simply find it hard to accept that a predefined maximum capacity, being at
compile time or runtime, should run into undefined behaviour if that
capacity is exceeded. There's too much code in the world already that
doesn't check limits.. STL containers has helped tremendously in this
regard, I don't see why one would want to go in another direction.
- Christian
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk