Is there a class in boost similar to array which is a POD-like type with an array but provides for a variable number of items in the container. That is, I want to say the array has at most 10 items, but may contain from 0 to 10 items at any given moment.
boost::array
unfortunately fixes size()
to the constant N
, so it can't work as a drop in replacement for a vector. In particular I'd like the readers of the structure not to know it is a static array, they can use begin()
and end()
like any other container.
Obviously push_back()
would have to through an exception if it would grow beyond the capacity.
Something already in boost
would be preferred.
NOTE: it must be a POD-like data type. For clarity, the entire array-like object, included the contents (which will themselves by POD-like types) must be POD-like. This is for serialization/copying reasons (and for performance related to that serialization/copying).
By POD-like I mean:
- has compile-time constant size
- can be safely memcpy'd
For those who say it can't work or isn't possible. There is nothing ingenious about this. The boost::array
is a POD-like type. All it would take is adding one extra field, for the current size, to make that into what I want. I'm looking for an implementation that already exists (and is thus properly tested/maintained).