rationale.html 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  4. <title>Design Rationale</title>
  5. <link rel="stylesheet" href="../boostbook.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
  7. <link rel="start" href="../index.html" title="The Boost C++ Libraries">
  8. <link rel="up" href="../array.html" title="Chapter 2. Boost.Array">
  9. <link rel="prev" href="../boost/array.html" title="Class template array">
  10. <link rel="next" href="more/info.html" title="For more information...">
  11. </head>
  12. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  13. <table cellpadding="2" width="100%">
  14. <td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td>
  15. <td align="center"><a href="../../../index.htm">Home</a></td>
  16. <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
  17. <td align="center"><a href="../../../people/people.htm">People</a></td>
  18. <td align="center"><a href="../../../more/faq.htm">FAQ</a></td>
  19. <td align="center"><a href="../../../more/index.htm">More</a></td>
  20. </table>
  21. <hr>
  22. <div class="spirit-nav">
  23. <a accesskey="p" href="../boost/array.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../array.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="more/info.html"><img src="../images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section" lang="en">
  26. <div class="titlepage"><div><div><h3 class="title">
  27. <a name="array.rationale"></a>Design Rationale</h3></div></div></div>
  28. <p>There was an important design tradeoff regarding the
  29. constructors: We could implement array as an "aggregate" (see
  30. Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would
  31. mean:
  32. </p>
  33. <div class="itemizedlist"><ul type="disc"><li>
  34. <p>An array can be initialized with a
  35. brace-enclosing, comma-separated list of initializers for the
  36. elements of the container, written in increasing subscript
  37. order:</p>
  38. <pre class="programlisting"><code class="computeroutput"><a href="../boost/array.html" title="Class template array">boost::array</a></code>&lt;int,4&gt; a = { { 1, 2, 3 } };</pre>
  39. <p>Note that if there are fewer elements in the
  40. initializer list, then each remaining element gets
  41. default-initialized (thus, it has a defined value).</p>
  42. </li></ul></div>
  43. <p>However, this approach has its drawbacks: <span class="bold"><strong> passing no initializer list means that the elements
  44. have an indetermined initial value</strong></span>, because the rule says
  45. that aggregates may have:
  46. </p>
  47. <div class="itemizedlist"><ul type="disc">
  48. <li>No user-declared constructors.</li>
  49. <li>No private or protected non-static data members.</li>
  50. <li>No base classes.</li>
  51. <li>No virtual functions.</li>
  52. </ul></div>
  53. <p>Nevertheless, The current implementation uses this approach.</p>
  54. <p>Note that for standard conforming compilers it is possible to
  55. use fewer braces (according to 8.5.1 (11) of the Standard). That is,
  56. you can initialize an array as follows:</p>
  57. <pre class="programlisting"><code class="computeroutput"><a href="../boost/array.html" title="Class template array">boost::array</a></code>&lt;int,4&gt; a = { 1, 2, 3 };
  58. </pre>
  59. <p>I'd appreciate any constructive feedback. <span class="bold"><strong>Please note: I don't have time to read all boost
  60. mails. Thus, to make sure that feedback arrives to me, please send
  61. me a copy of each mail regarding this class.</strong></span></p>
  62. <p>The code is provided "as is" without expressed or implied
  63. warranty.</p>
  64. </div>
  65. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  66. <td align="left"></td>
  67. <td align="right"><small>Copyright © 2001-2004 Nicolai M. Josuttis</small></td>
  68. </tr></table>
  69. <hr>
  70. <div class="spirit-nav">
  71. <a accesskey="p" href="../boost/array.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../array.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="more/info.html"><img src="../images/next.png" alt="Next"></a>
  72. </div>
  73. </body>
  74. </html>
粤ICP备19079148号