Boost logo

Boost :

Subject: Re: [boost] Interest in Boost.Array companion: StaticVector - A statically allocated fixed capacity vector
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2011-08-14 16:57:49


Andrew Hundt 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.

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 am wondering whether C++11's user string literal stuff could be used
to select a suitable max string size at compile time. For example:

auto s1( "Hello"S ); // S suffix creates a static_string<5> in this case
auto s2( "World"S );
auto s3 = s1 + ' ' + s2; // Result is static_string<11>

I could imagine very efficient short string expressions done like this.

Phil.


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