There was an important design tradeoff regarding the constructors: if the user implements the 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: 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 undetermined initial value, because the rule says that aggregates may have:
No user-declared constructors.
No private or protected non-static data members.
No base classes.
No virtual functions.
Nevertheless, The current implementation uses this approach.
Note:For standard conforming compilers it is possible to use fewer braces (according to 8.5.1 (11) of the Standard). That is, initialize an array as follows:
boost::array<int,4> a = { 1, 2, 3 };
The code is provided "as is" without expressed or implied warranty.
Copyright © 2001-2004 Nicolai M. Josuttis |
|