Boost logo

Boost :

Subject: Re: [boost] Interest in StaticVector - fixed capacity vector
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-10-15 09:45:46

on Sat Oct 15 2011, "Peter Dimov" <> wrote:

> Dave Abrahams wrote:
>> on Fri Oct 14 2011, "Peter Dimov" <> wrote:
>> > try
>> > {
>> > do some push_backs into a static_vector; we don't know how many
>> > }
>> > catch( out_of_capacity& )
>> > {
>> > // ignore, what we gathered so far is good enough for gov't use
>> > }
>> Yes, it's possible, but highly unusual, for someone to use the class
>> that way.
> I'm not sure of that either. What makes you think so?

a. It's not an idiom typically used with C++

b. It's very inefficient in a context where we're surely
   trying to optimize (otherwise why use StaticVector?)

I also want to add that the above code would be broken and wrong if you
were using vector instead of static_vector, unless you know the number of
possible push_backs is bounded.

> What are the "proper" uses for it?

It sounds like you're asking me to prove something for which we both
know there's no proof. If you design the class to throw exceptions when
the fixed capacity is exceeded, your code above is perfectly "proper."
The problem is that once we get a step away from the call site, we can't
tell wether the usage was proper anymore.

If we can figure out how to get cars to bounce harmlessly out of
collisions we could decide to make it legal to ignore stop signs and
just count on the bounce to handle it. Should we? It would then be
impossible to yank the out-of-control drivers off the road, and if
people start taking advantage of this protection, it's going to slow
down traffic. If instead we can capture colliding drivers and send them
to driving school, isn't that better?

Dave Abrahams
BoostPro Computing

Boost list run by bdawes at, gregod at, cpdaniel at, john at