Boost logo

Boost :

Subject: Re: [boost] Interest in Boost.Array companion: StaticVector - A statically allocated fixed capacity vector
From: Andrew Hundt (athundt_at_[hidden])
Date: 2011-10-06 02:39:21


On Sun, Aug 14, 2011 at 5:35 PM, Jeffrey Lee Hellrung, Jr. <
jeffrey.hellrung_at_[hidden]> wrote:

> [rearranging; note that bottom- or inline-posting is preferred, see
> http://www.boost.org/community/policy.html#quoting]
>
> On Sun, Aug 14, 2011 at 10:09 AM, Andrew Hundt <athundt_at_[hidden]> wrote:
>
> > On Sun, Aug 14, 2011 at 5:59 AM, Joel falcou <joel.falcou_at_[hidden]>
> > wrote:
> >
> > > On 14/08/11 11:55, Andrew Hundt wrote:
> > >
> > >> Sample Code:
> > >> StaticVector<std::size_t,3> three;
> > >> three.push_back(5);
> > >> three.push_back(2); // size: 2 capacity: 3
> > >> three.push_back(3);
> > >>
> > >> three.push_back(1); // throws std::out_of_range exception indicating
> > the
> > >> capacity has been exceeded
> > >>
> > >
> > > Can't this just be done using Boost.Container or any stateful allcoator
> > > aware container implementation with a stateful allocator holding the
> > static
> > > allocated block of memory ?
> >
>
> True, but then the type would be syntactically uglier, you'd like have 3
> extra pointers (begin, end_size, end_capacity, right?) or so of overhead,
> and there may be missed optimization opportunities if the compiler can't
> determine that, e.g., this and begin always point to the same byte in
> memory
> (this is just speculation).
>
> It seems I missed the container review, it does look like that would
> > suffice. The simplicity of the StaticVector implementation may still make
> > it
> > useful for cases where all you really need are a simple array and a size,
> > in
> > the same way that boost.array is useful for an array alone. However, its
> > entirely possible that StaticVector is now redundant, and that's why I'm
> > asking if there is any interest. :-)
> >
> > I've also tried to come up with a better name for it, but that is the
> best
> > I
> > could think of. Any better naming suggestions around?
> >
>
> I've used a similar object that I called bounded_vector, so I think there
> are definitely use cases for this.
>
> - Jeff
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

I tend to agree with Jeff here. My goal with StaticVector was to match
Boost.Array as closely as possible while providing the additional service of
tracking the number of elements in the array for simplicity and ease of use.

Cheers!
Andrew Hundt


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk