/Src/Dependencies/Boost/doc/test/array2.xml

http://hadesmem.googlecode.com/ · XML · 82 lines · 70 code · 12 blank · 0 comment · 0 complexity · a4721f4b34352cd4af9ba68b544a77f0 MD5 · raw file

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