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:36:13

On Sun, Aug 14, 2011 at 5:55 AM, Andrew Hundt <athundt_at_[hidden]> wrote:

> I've implemented a small companion class to boost.array that functions like
> a stack allocated vector with fixed capacity. The motivation for this class
> came when I was using boost.array in an interprocess library, when I
> realized that I actually desired an adjustable size boost.array, without the
> complexity of the vector class in the interprocess library. The result is
> StaticVector, which is boost.array directly modified with a size in front of
> the array, and added facilities to match std::vector.
> The Implementation is available at:
> 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
> So here is the big question:
> Is there any interest in the class?
> Cheers!
> Andrew Hundt
On Mon, Aug 15, 2011 at 5:20 PM, Nevin Liber <nevin_at_[hidden]> wrote:

> On 15 August 2011 16:05, Andrew Hundt <athundt_at_[hidden]> wrote:
> > Good point. I've modified elems to be a char array, and I now
> > reinterpret_cast to the class T as necessary. Elements should only be
> > constructed when they are added now.
> >
> What are you doing about alignment? Take a look at Synyhesizing Types with
> Specific Alignments in the Type Traits library for a start.
> --
> Nevin ":-)" Liber <mailto:nevin_at_[hidden]> (847) 691-1404
> _______________________________________________
> Unsubscribe & other changes:

Phil Endecott wrote:

> In the case of StativVector<char,N> where N<256, you should consider using
> uint8_t to store the size - and similar variations. Boost.Integer makes it
> possible to select a suitable type.

I know its been a while since I sent my first emails regarding StaticVector,
but I haven't had a good chance to fix the issues people brought up until
now. The solutions seem to be much easier than I expected.

 - I believe I've resolved the StaticVector alignment using type_traits'
 - I've also added the use of Boost.Integer to select the smallest possible
type for the internal size value.

Any thoughts?

Andrew Hundt

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