Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Design Rationale

There was an important design tradeoff regarding the constructors: We could implement array as an "aggregate" (see Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would mean:

An array can be initialized with a brace-enclosing, comma-separated list of initializers for the elements of the container, written in increasing subscript order:

boost::array<int,4> a = { { 1, 2, 3 } };

Note that if there are fewer elements in the initializer list, then each remaining element gets default-initialized. Thus, it has a defined value.

However, this approach has its drawbacks: passing no initializer list means that the elements have an indeterminate initial value, because the rule says that aggregates may have:

Nevertheless, the current implementation uses this approach.

Note that for standard conforming compilers it is possible to use fewer braces (according to 8.5.1 (11) of the Standard). That is, you can initialize an array as follows:

boost::array<int,4> a = { 1, 2, 3 };

I would appreciate any constructive feedback. Please note: I do not have time to read all boost mails. Thus, to make sure that feedback arrives to me, please send me a copy of each mail regarding this class.

The code is provided "as is" without expressed or implied warranty.


PrevUpHomeNext