summaryrefslogtreecommitdiff
path: root/doc/html/array.html
blob: f99373c27056a26075516fe937506716bfde2d37 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter 2. Boost.Array</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
<link rel="start" href="index.html" title="The Boost C++ Libraries">
<link rel="up" href="libraries.html" title="Part I. The Boost C++ Libraries">
<link rel="prev" href="any/s04.html" title="Acknowledgements">
<link rel="next" href="array/reference.html" title="Reference">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../boost.png"></td>
<td align="center"><a href="../../index.htm">Home</a></td>
<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../people/people.htm">People</a></td>
<td align="center"><a href="../../more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../more/index.htm">More</a></td>
</table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="any/s04.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.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="array/reference.html"><img src="images/next.png" alt="Next"></a>
</div>
<div class="chapter" lang="en">
<div class="titlepage"><div>
<div><h2 class="title">
<a name="array"></a>Chapter 2. Boost.Array</h2></div>
<div><div class="author"><h3 class="author">
<span class="firstname">Nicolai</span> <span class="surname">Josuttis</span>
</h3></div></div>
<div><p class="copyright">Copyright © 2001-2004 Nicolai M. Josuttis</p></div>
<div><div class="legalnotice">
<a name="id971681"></a><p>Permission to copy, use, modify, sell and distribute this
      software is granted provided this copyright notice appears in
      all copies. This software is provided "as is" without express or
      implied warranty, and with no claim as to its suitability for
      any purpose.</p>
</div></div>
</div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="section"><a href="array.html#array.intro">Introduction</a></span></dt>
<dt><span class="section"><a href="array/reference.html">Reference</a></span></dt>
<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>
<dt><span class="section"><a href="array/rationale.html">Design Rationale</a></span></dt>
<dt><span class="section"><a href="array/more/info.html">For more information...</a></span></dt>
<dt><span class="section"><a href="array/ack.html">Acknowledgements</a></span></dt>
</dl>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="array.intro"></a>Introduction</h3></div></div></div>
<p>The C++ Standard Template Library STL as part of the C++
    Standard Library provides a framework for processing algorithms on
    different kind of containers. However, ordinary arrays don't
    provide the interface of STL containers (although, they provide
    the iterator interface of STL containers).</p>
<p>As replacement for ordinary arrays, the STL provides class
    <code class="computeroutput">std::vector</code>.  However,
    <code class="computeroutput">std::vector&lt;&gt;</code> provides
    the semantics of dynamic arrays. Thus, it manages data to be able
    to change the number of elements. This results in some overhead in
    case only arrays with static size are needed.</p>
<p>In his book, <span class="emphasis"><em>Generic Programming and the
    STL</em></span>, Matthew H. Austern introduces a useful wrapper
    class for ordinary arrays with static size, called
    <code class="computeroutput">block</code>.  It is safer and has no worse performance than
    ordinary arrays. In <span class="emphasis"><em>The C++ Programming
    Language</em></span>, 3rd edition, Bjarne Stroustrup introduces a
    similar class, called <code class="computeroutput">c_array</code>, which I (<a href="http://www.josuttis.com" target="_top">Nicolai Josuttis</a>) present
    slightly modified in my book <span class="emphasis"><em>The C++ Standard Library -
    A Tutorial and Reference</em></span>, called
    <code class="computeroutput">carray</code>. This is the essence of these approaches
    spiced with many feedback from <a href="http://www.boost.org" target="_top">boost</a>.</p>
<p>After considering different names, we decided to name this
    class simply <code class="computeroutput"><a href="boost/array.html" title="Class template array">array</a></code>.</p>
<p>Note that this class is suggested to be part of the next
    Technical Report, which will extend the C++ Standard (see
    <a href="" target="_top">http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</a>).</p>
<p>Class <code class="computeroutput"><a href="boost/array.html" title="Class template array">array</a></code> fulfills most
    but not all of the requirements of "reversible containers" (see
    Section 23.1, [lib.container.requirements] of the C++
    Standard). The reasons array is not an reversible STL container is
    because:
      </p>
<div class="itemizedlist"><ul type="disc" compact>
<li>No constructors are provided.</li>
<li>Elements may have an undetermined initial value (see <a href="array/rationale.html" title="Design Rationale">the section called &#8220;Design Rationale&#8221;</a>).</li>
<li>
<code class="computeroutput"><a href="boost/array.html#id763420">swap</a></code>() has no constant complexity.</li>
<li>
<code class="computeroutput"><a href="boost/array.html#id686133-bb">size</a></code>() is always constant, based on the second template argument of the type.</li>
<li>The container provides no allocator support.</li>
</ul></div>
<p>It doesn't fulfill the requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts] of the C++ Standard), except that:
      </p>
<div class="itemizedlist"><ul type="disc" compact>
<li>
<code class="computeroutput"><a href="boost/array.html#id763241-bb">front</a></code>() and <code class="computeroutput"><a href="boost/array.html#id763273-bb">back</a></code>() are provided.</li>
<li>
<code class="computeroutput"><a href="boost/array.html#id685146-bb">operator[]</a></code> and <code class="computeroutput"><a href="boost/array.html#id726524-bb">at</a></code>() are provided.</li>
</ul></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><small><p>Last revised: January 30, 2004 at 03:51:06 GMT</p></small></td>
<td align="right"><small></small></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="any/s04.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.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="array/reference.html"><img src="images/next.png" alt="Next"></a>
</div>
</body>
</html>