Blame view

3rdparty/boost_1_81_0/doc/html/array/rationale.html 5 KB
0b6a182c   Hu Chunming   添加无鉴权注册和注销
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Design Rationale</title>
  <link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
  <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
  <link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
  <link rel="up" href="../array.html" title="Chapter 5. Boost.Array">
  <link rel="prev" href="../boost/array.html" title="Class template array">
  <link rel="next" href="more/info.html" title="For more information...">
  </head>
  <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  <table cellpadding="2" width="100%"><tr>
  <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
  <td align="center"><a href="../../../index.html">Home</a></td>
  <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
  <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
  <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
  <td align="center"><a href="../../../more/index.htm">More</a></td>
  </tr></table>
  <hr>
  <div class="spirit-nav">
  <a accesskey="p" href="../boost/array.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../array.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="more/info.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
  </div>
  <div class="section">
  <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  <a name="array.rationale"></a>Design Rationale</h2></div></div></div>
  <p>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:
      </p>
  <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
  <p class="simpara">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:</p>
  <pre class="programlisting"><code class="computeroutput"><a class="link" href="../boost/array.html" title="Class template array">boost::array</a></code>&lt;int,4&gt; a = { { 1, 2, 3 } };</pre>
  <p class="simpara">Note that if there are fewer elements in the
        initializer list, then each remaining element gets
        default-initialized (thus, it has a defined value).</p>
  </li></ul></div>
  <p>However, this approach has its drawbacks: <span class="bold"><strong> passing no initializer list means that the elements
    have an indetermined initial value</strong></span>, because the rule says
    that aggregates may have:
      </p>
  <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  <li class="listitem">No user-declared constructors.</li>
  <li class="listitem">No private or protected non-static data members.</li>
  <li class="listitem">No base classes.</li>
  <li class="listitem">No virtual functions.</li>
  </ul></div>
  <p>
    </p>
  <p>Nevertheless, The current implementation uses this approach.</p>
  <p>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:</p>
  <pre class="programlisting">
  <code class="computeroutput"><a class="link" href="../boost/array.html" title="Class template array">boost::array</a></code>&lt;int,4&gt; a = { 1, 2, 3 };
  </pre>
  <p>I'd appreciate any constructive feedback. <span class="bold"><strong>Please note: I don't 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.</strong></span></p>
  <p>The code is provided "as is" without expressed or implied
    warranty.</p>
  </div>
  <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  <td align="left"></td>
  <td align="right"><div class="copyright-footer">Copyright © 2001-2004 Nicolai M. Josuttis<br>Copyright © 2012 Marshall Clow<p>Distributed under the Boost Software License, Version 1.0.
        (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at 
        <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
        </p>
  </div></td>
  </tr></table>
  <hr>
  <div class="spirit-nav">
  <a accesskey="p" href="../boost/array.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../array.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="more/info.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
  </div>
  </body>
  </html>