Imported Upstream version 1.64.0
[platform/upstream/boost.git] / doc / html / array.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5 <title>Chapter&#160;6.&#160;Boost.Array</title>
6 <link rel="stylesheet" href="../../doc/src/boostbook.css" type="text/css">
7 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8 <link rel="home" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9 <link rel="up" href="libraries.html" title="Part&#160;I.&#160;The Boost C++ Libraries (BoostBook Subset)">
10 <link rel="prev" href="any/s04.html" title="Acknowledgements">
11 <link rel="next" href="array/reference.html" title="Reference">
12 </head>
13 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14 <table cellpadding="2" width="100%"><tr>
15 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td>
16 <td align="center"><a href="../../index.html">Home</a></td>
17 <td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
18 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20 <td align="center"><a href="../../more/index.htm">More</a></td>
21 </tr></table>
22 <hr>
23 <div class="spirit-nav">
24 <a accesskey="p" href="any/s04.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.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="array/reference.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
25 </div>
26 <div class="chapter">
27 <div class="titlepage"><div>
28 <div><h2 class="title">
29 <a name="array"></a>Chapter&#160;6.&#160;Boost.Array</h2></div>
30 <div><div class="author"><h3 class="author">
31 <span class="firstname">Nicolai</span> <span class="surname">Josuttis</span>
32 </h3></div></div>
33 <div><p class="copyright">Copyright &#169; 2001-2004 Nicolai M. Josuttis</p></div>
34 <div><p class="copyright">Copyright &#169; 2012 Marshall Clow</p></div>
35 <div><div class="legalnotice">
36 <a name="idp143260992"></a><p>Distributed under the Boost Software License, Version 1.0.
37       (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at 
38       <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
39       </p>
40 </div></div>
41 </div></div>
42 <div class="toc">
43 <p><b>Table of Contents</b></p>
44 <dl class="toc">
45 <dt><span class="section"><a href="array.html#array.intro">Introduction</a></span></dt>
46 <dt><span class="section"><a href="array/reference.html">Reference</a></span></dt>
47 <dd><dl><dt><span class="section"><a href="array/reference.html#header.boost.array_hpp">Header &lt;boost/array.hpp&gt;</a></span></dt></dl></dd>
48 <dt><span class="section"><a href="array/rationale.html">Design Rationale</a></span></dt>
49 <dt><span class="section"><a href="array/more/info.html">For more information...</a></span></dt>
50 <dt><span class="section"><a href="array/ack.html">Acknowledgements</a></span></dt>
51 </dl>
52 </div>
53 <div class="section">
54 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
55 <a name="array.intro"></a>Introduction</h2></div></div></div>
56 <p>The C++ Standard Template Library STL as part of the C++
57     Standard Library provides a framework for processing algorithms on
58     different kind of containers. However, ordinary arrays don't
59     provide the interface of STL containers (although, they provide
60     the iterator interface of STL containers).</p>
61 <p>As replacement for ordinary arrays, the STL provides class
62     <code class="computeroutput">std::vector</code>.  However,
63     <code class="computeroutput">std::vector&lt;&gt;</code> provides
64     the semantics of dynamic arrays. Thus, it manages data to be able
65     to change the number of elements. This results in some overhead in
66     case only arrays with static size are needed.</p>
67 <p>In his book, <span class="emphasis"><em>Generic Programming and the
68     STL</em></span>, Matthew H. Austern introduces a useful wrapper
69     class for ordinary arrays with static size, called
70     <code class="computeroutput">block</code>.  It is safer and has no worse performance than
71     ordinary arrays. In <span class="emphasis"><em>The C++ Programming
72     Language</em></span>, 3rd edition, Bjarne Stroustrup introduces a
73     similar class, called <code class="computeroutput">c_array</code>, which I (<a href="http://www.josuttis.com" target="_top">Nicolai Josuttis</a>) present
74     slightly modified in my book <span class="emphasis"><em>The C++ Standard Library -
75     A Tutorial and Reference</em></span>, called
76     <code class="computeroutput">carray</code>. This is the essence of these approaches
77     spiced with many feedback from <a href="http://www.boost.org" target="_top">boost</a>.</p>
78 <p>After considering different names, we decided to name this
79     class simply <code class="computeroutput"><a class="link" href="boost/array.html" title="Class template array">array</a></code>.</p>
80 <p>Note that this class is suggested to be part of the next
81     Technical Report, which will extend the C++ Standard (see
82     <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm" target="_top">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</a>).</p>
83 <p>Update: <code class="computeroutput">std::array</code> is (as of C++11) part of the C++ standard.
84     The differences between <code class="computeroutput">boost::array</code> and <code class="computeroutput">std::array</code> are minimal.
85     If you are using C++11, you should consider using <code class="computeroutput">std::array</code> instead of <code class="computeroutput">boost::array</code>.
86     </p>
87 <p>Class <code class="computeroutput"><a class="link" href="boost/array.html" title="Class template array">array</a></code> fulfills most
88     but not all of the requirements of "reversible containers" (see
89     Section 23.1, [lib.container.requirements] of the C++
90     Standard). The reasons array is not an reversible STL container is
91     because:
92       </p>
93 <div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: disc; ">
94 <li class="listitem">No constructors are provided.</li>
95 <li class="listitem">Elements may have an undetermined initial value (see <a class="xref" href="array/rationale.html" title="Design Rationale">the section called &#8220;Design Rationale&#8221;</a>).</li>
96 <li class="listitem">
97 <code class="computeroutput"><a class="link" href="boost/swap_idp424614880.html" title="Function swap">swap</a></code>() has no constant complexity.</li>
98 <li class="listitem">
99 <code class="computeroutput"><a class="link" href="boost/array.html#idp424718384-bb">size</a></code>() is always constant, based on the second template argument of the type.</li>
100 <li class="listitem">The container provides no allocator support.</li>
101 </ul></div>
102 <p>
103     </p>
104 <p>It doesn't fulfill the requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts] of the C++ Standard), except that:
105       </p>
106 <div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: disc; ">
107 <li class="listitem">
108 <code class="computeroutput"><a class="link" href="boost/array.html#idp424737648-bb">front</a></code>() and <code class="computeroutput"><a class="link" href="boost/array.html#idp424741712-bb">back</a></code>() are provided.</li>
109 <li class="listitem">
110 <code class="computeroutput"><a class="link" href="boost/array.html#idp424724976-bb">operator[]</a></code> and <code class="computeroutput"><a class="link" href="boost/array.html#idp424731312-bb">at</a></code>() are provided.</li>
111 </ul></div>
112 <p>
113     </p>
114 </div>
115 </div>
116 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
117 <td align="left"></td>
118 <td align="right"><div class="copyright-footer"></div></td>
119 </tr></table>
120 <hr>
121 <div class="spirit-nav">
122 <a accesskey="p" href="any/s04.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.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="array/reference.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
123 </div>
124 </body>
125 </html>