Boost logo

Boost :

Subject: [boost] [container] varray aka static_vector
From: Andrew Hundt (athundt_at_[hidden])
Date: 2013-02-11 11:57:05

As Adam mentioned in an earlier thread we have renamed static_vector
to varray to better represent how it works like an array with size
without requiring the values to be default constructible, and to better
distinguish it from hybrid_vector.

varray location:


One open question is if the 3rd strategy parameter should be public or
in the detail namespace. Based on some of the feedback we moved the
strategy from container to container_detail, and made the public
version varray<typename T, std::size_t N>. However, we wanted to get
others' thoughts on this change.

Additionally, should primitives be default initialized with the
contents of memory like an array or value initialized to 0 like a
standard container in the constructor, resize(), and emplace_back()?

Generally, built-in types are initialized when the constructor is
called explicitly. For example:

int a; // a has the value of underlying memory
int b = int(); // b has a value of 0

Right now the default behavior of our container is more like a vector
than an array when creating values using the default ctor. Default
constructable values are explicitly initialized in the varray ctor,
resize(), emplace() and emplace_back() functions, even when they are
trivially constructable. We find this behavior more intuitive and
therefore we have made it the default. If the performance needs to be
improved slightly the behavior may be changed or disabled in
container_detail::varray_traits<V, C, S>.

Here is an example demonstrating the current default behavior:

vector<int> vec(3);
varray<int, 3> varr(3);
array<int, 3> arr;

vec[0] == varr[0]


vec[0] != arr[0]

Any feedback is very much appreciated.

Andrew Hundt
Adam Wulkiewicz

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