| 1 | <html> |
|---|
| 2 | <head> |
|---|
| 3 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
|---|
| 4 | <title>Chapter 2. Boost.Array</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 BoostBook Documentation Subset"> |
|---|
| 8 | <link rel="up" href="libraries.html" title="Part I. The Boost C++ Libraries (BoostBook Subset)"> |
|---|
| 9 | <link rel="prev" href="any/s04.html" title="Acknowledgements"> |
|---|
| 10 | <link rel="next" href="array/reference.html" title="Reference"> |
|---|
| 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 C++ Libraries" 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="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> |
|---|
| 24 | </div> |
|---|
| 25 | <div class="chapter" lang="en"> |
|---|
| 26 | <div class="titlepage"><div> |
|---|
| 27 | <div><h2 class="title"> |
|---|
| 28 | <a name="array"></a>Chapter 2. Boost.Array</h2></div> |
|---|
| 29 | <div><div class="author"><h3 class="author"> |
|---|
| 30 | <span class="firstname">Nicolai</span> <span class="surname">Josuttis</span> |
|---|
| 31 | </h3></div></div> |
|---|
| 32 | <div><p class="copyright">Copyright © 2001-2004 Nicolai M. Josuttis</p></div> |
|---|
| 33 | <div><div class="legalnotice"> |
|---|
| 34 | <a name="id938650"></a><p>Distributed under the Boost Software License, Version 1.0. |
|---|
| 35 | (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at |
|---|
| 36 | <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) |
|---|
| 37 | </p> |
|---|
| 38 | </div></div> |
|---|
| 39 | </div></div> |
|---|
| 40 | <div class="toc"> |
|---|
| 41 | <p><b>Table of Contents</b></p> |
|---|
| 42 | <dl> |
|---|
| 43 | <dt><span class="section"><a href="array.html#array.intro">Introduction</a></span></dt> |
|---|
| 44 | <dt><span class="section"><a href="array/reference.html">Reference</a></span></dt> |
|---|
| 45 | <dd><dl><dt><span class="section"><a href="array/reference.html#header.boost.array.hpp">Header <boost/array.hpp></a></span></dt></dl></dd> |
|---|
| 46 | <dt><span class="section"><a href="array/rationale.html">Design Rationale</a></span></dt> |
|---|
| 47 | <dt><span class="section"><a href="array/more/info.html">For more information...</a></span></dt> |
|---|
| 48 | <dt><span class="section"><a href="array/ack.html">Acknowledgements</a></span></dt> |
|---|
| 49 | </dl> |
|---|
| 50 | </div> |
|---|
| 51 | <div class="section" lang="en"> |
|---|
| 52 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
|---|
| 53 | <a name="array.intro"></a>Introduction</h2></div></div></div> |
|---|
| 54 | <p>The C++ Standard Template Library STL as part of the C++ |
|---|
| 55 | Standard Library provides a framework for processing algorithms on |
|---|
| 56 | different kind of containers. However, ordinary arrays don't |
|---|
| 57 | provide the interface of STL containers (although, they provide |
|---|
| 58 | the iterator interface of STL containers).</p> |
|---|
| 59 | <p>As replacement for ordinary arrays, the STL provides class |
|---|
| 60 | <code class="computeroutput">std::vector</code>. However, |
|---|
| 61 | <code class="computeroutput">std::vector<></code> provides |
|---|
| 62 | the semantics of dynamic arrays. Thus, it manages data to be able |
|---|
| 63 | to change the number of elements. This results in some overhead in |
|---|
| 64 | case only arrays with static size are needed.</p> |
|---|
| 65 | <p>In his book, <span class="emphasis"><em>Generic Programming and the |
|---|
| 66 | STL</em></span>, Matthew H. Austern introduces a useful wrapper |
|---|
| 67 | class for ordinary arrays with static size, called |
|---|
| 68 | <code class="computeroutput">block</code>. It is safer and has no worse performance than |
|---|
| 69 | ordinary arrays. In <span class="emphasis"><em>The C++ Programming |
|---|
| 70 | Language</em></span>, 3rd edition, Bjarne Stroustrup introduces a |
|---|
| 71 | similar class, called <code class="computeroutput">c_array</code>, which I (<a href="http://www.josuttis.com" target="_top">Nicolai Josuttis</a>) present |
|---|
| 72 | slightly modified in my book <span class="emphasis"><em>The C++ Standard Library - |
|---|
| 73 | A Tutorial and Reference</em></span>, called |
|---|
| 74 | <code class="computeroutput">carray</code>. This is the essence of these approaches |
|---|
| 75 | spiced with many feedback from <a href="http://www.boost.org" target="_top">boost</a>.</p> |
|---|
| 76 | <p>After considering different names, we decided to name this |
|---|
| 77 | class simply <code class="computeroutput"><a href="boost/array.html" title="Class template array">array</a></code>.</p> |
|---|
| 78 | <p>Note that this class is suggested to be part of the next |
|---|
| 79 | Technical Report, which will extend the C++ Standard (see |
|---|
| 80 | <a href="http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm" target="_top">http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</a>).</p> |
|---|
| 81 | <p>Class <code class="computeroutput"><a href="boost/array.html" title="Class template array">array</a></code> fulfills most |
|---|
| 82 | but not all of the requirements of "reversible containers" (see |
|---|
| 83 | Section 23.1, [lib.container.requirements] of the C++ |
|---|
| 84 | Standard). The reasons array is not an reversible STL container is |
|---|
| 85 | because: |
|---|
| 86 | </p> |
|---|
| 87 | <div class="itemizedlist"><ul type="disc" compact> |
|---|
| 88 | <li>No constructors are provided.</li> |
|---|
| 89 | <li>Elements may have an undetermined initial value (see <a href="array/rationale.html" title="Design Rationale">the section called “Design Rationale”</a>).</li> |
|---|
| 90 | <li> |
|---|
| 91 | <code class="computeroutput"><a href="boost/array.html#id719226-bb">swap</a></code>() has no constant complexity.</li> |
|---|
| 92 | <li> |
|---|
| 93 | <code class="computeroutput"><a href="boost/array.html#id718877-bb">size</a></code>() is always constant, based on the second template argument of the type.</li> |
|---|
| 94 | <li>The container provides no allocator support.</li> |
|---|
| 95 | </ul></div> |
|---|
| 96 | <p> |
|---|
| 97 | </p> |
|---|
| 98 | <p>It doesn't fulfill the requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts] of the C++ Standard), except that: |
|---|
| 99 | </p> |
|---|
| 100 | <div class="itemizedlist"><ul type="disc" compact> |
|---|
| 101 | <li> |
|---|
| 102 | <code class="computeroutput"><a href="boost/array.html#id719036-bb">front</a></code>() and <code class="computeroutput"><a href="boost/array.html#id719070-bb">back</a></code>() are provided.</li> |
|---|
| 103 | <li> |
|---|
| 104 | <code class="computeroutput"><a href="boost/array.html#id718932-bb">operator[]</a></code> and <code class="computeroutput"><a href="boost/array.html#id718984-bb">at</a></code>() are provided.</li> |
|---|
| 105 | </ul></div> |
|---|
| 106 | <p> |
|---|
| 107 | </p> |
|---|
| 108 | </div> |
|---|
| 109 | </div> |
|---|
| 110 | <table width="100%"><tr> |
|---|
| 111 | <td align="left"><small><p>Last revised: December 01, 2006 at 11:34:43 GMT</p></small></td> |
|---|
| 112 | <td align="right"><small></small></td> |
|---|
| 113 | </tr></table> |
|---|
| 114 | <hr> |
|---|
| 115 | <div class="spirit-nav"> |
|---|
| 116 | <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> |
|---|
| 117 | </div> |
|---|
| 118 | </body> |
|---|
| 119 | </html> |
|---|