Boost logo

Boost :

Subject: Re: [boost] Interest in StaticVector - fixed capacity vector
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-10-12 08:19:11

Olaf van der Spek wrote:
> On Wed, Oct 12, 2011 at 12:38 PM, Stewart, Robert
> <Robert.Stewart_at_[hidden]> wrote:
> >> I'd really like to see the interface be as close to C++11
> >> std::vector as possible (other than vector<bool>).
> >
> > Interface is one thing. That doesn't address the idea of
> > throwing exceptions when exceeding capacity. Many wanting to
> > use static_vector in embedded environments don't want
> > exceptions. The rest of us find them useful. Still,
> > BOOST_THROW_EXCEPTION provides a means to configure that, but
> > it affects all Boost code; localizing the effect may be
> > desirable. Matt called for a differently named container as
> > a means to provide the no-exception behavior. I think a
> > policy class, defaulted to the throwing behavior, is the
> > better approach, despite Jeff's thinking it an unnecessary
> > complication.
> Is it a logic error or a runtime error? IMO exceeding the
> capacity here is a logic error and should be handled with an
> assert by default.
> Isn't it comparable to doing a pop_back() on an empty vector?

It depends upon whether static_vector is modeled like std::vector or std::array and whether we're referring to the subscript operator or push_back(). For the subscript operator, it's a logic error in both std::vector and std::array. For push_back, it's a runtime error (std::bad_alloc) because a vector grows. std::array doesn't have push_back(), of course, but static_vector manages size and capacity separately, so it will. Therefore, it isn't a logic error if you follow std::vector's example.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP


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, gregod at, cpdaniel at, john at