]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <section id="array.rationale"> |
2 | <title>Design Rationale</title> | |
3 | ||
4 | <para> | |
5 | There was an important design tradeoff regarding the | |
6 | constructors: We could implement array as an "aggregate" (see | |
7 | Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would | |
8 | mean: | |
9 | <itemizedlist> | |
10 | <listitem> | |
11 | <simpara> | |
12 | An array can be initialized with a | |
13 | brace-enclosing, comma-separated list of initializers for the | |
14 | elements of the container, written in increasing subscript | |
15 | order: | |
16 | </simpara> | |
17 | ||
18 | <programlisting> | |
19 | <classname>boost::array</classname><int,4> a = { { 1, 2, 3 } }; | |
20 | </programlisting> | |
21 | ||
22 | <simpara> | |
23 | Note that if there are fewer elements in the | |
24 | initializer list, then each remaining element gets | |
25 | default-initialized (thus, it has a defined value). | |
26 | </simpara> | |
27 | </listitem> | |
28 | </itemizedlist> | |
29 | </para> | |
30 | ||
31 | <para> | |
32 | However, this approach has its drawbacks: <emphasis | |
33 | role="bold"> | |
34 | passing no initializer list means that the elements | |
35 | have an indetermined initial value | |
36 | </emphasis>, because the rule says | |
37 | that aggregates may have: | |
38 | <itemizedlist> | |
39 | <listitem> | |
40 | <simpara>No user-declared constructors.</simpara> | |
41 | </listitem> | |
42 | <listitem> | |
43 | <simpara>No private or protected non-static data members.</simpara> | |
44 | </listitem> | |
45 | <listitem> | |
46 | <simpara>No base classes.</simpara> | |
47 | </listitem> | |
48 | <listitem> | |
49 | <simpara>No virtual functions.</simpara> | |
50 | </listitem> | |
51 | </itemizedlist> | |
52 | </para> | |
53 | ||
54 | <para>Nevertheless, The current implementation uses this approach.</para> | |
55 | ||
56 | <para> | |
57 | Note that for standard conforming compilers it is possible to | |
58 | use fewer braces (according to 8.5.1 (11) of the Standard). That is, | |
59 | you can initialize an array as follows: | |
60 | </para> | |
61 | ||
62 | <programlisting> | |
63 | <classname>boost::array</classname><int,4> a = { 1, 2, 3 }; | |
64 | </programlisting> | |
65 | ||
66 | <para> | |
67 | I'd appreciate any constructive feedback. <emphasis | |
68 | role="bold"> | |
69 | Please note: I don't have time to read all boost | |
70 | mails. Thus, to make sure that feedback arrives to me, please send | |
71 | me a copy of each mail regarding this class. | |
72 | </emphasis> | |
73 | </para> | |
74 | ||
75 | <para> | |
76 | The code is provided "as is" without expressed or implied | |
77 | warranty. | |
78 | </para> | |
79 | ||
80 | </section> | |
81 | ||
82 |