PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

XML | 64 lines | 53 code | 11 blank | 0 comment | 0 complexity | 8a21654d78d6b6be8239799a2ba13ba8 MD5 | raw file
 1<section id="array.intro">
 2    <title>Introduction</title> 
 4    <using-namespace name="boost"/>
 5    <using-class name="array"/>
 7    <para>The C++ Standard Template Library STL as part of the C++
 8    Standard Library provides a framework for processing algorithms on
 9    different kind of containers. However, ordinary arrays don't
10    provide the interface of STL containers (although, they provide
11    the iterator interface of STL containers).</para>
13    <para>As replacement for ordinary arrays, the STL provides class
14    <code><classname>std::vector</classname></code>.  However,
15    <code><classname>std::vector&lt;&gt;</classname></code> provides
16    the semantics of dynamic arrays. Thus, it manages data to be able
17    to change the number of elements. This results in some overhead in
18    case only arrays with static size are needed.</para>
20    <para>In his book, <emphasis>Generic Programming and the
21    STL</emphasis>, Matthew H. Austern introduces a useful wrapper
22    class for ordinary arrays with static size, called
23    <code>block</code>.  It is safer and has no worse performance than
24    ordinary arrays. In <emphasis>The C++ Programming
25    Language</emphasis>, 3rd edition, Bjarne Stroustrup introduces a
26    similar class, called <code>c_array</code>, which I (<ulink
27    url="">Nicolai Josuttis</ulink>) present
28    slightly modified in my book <emphasis>The C++ Standard Library -
29    A Tutorial and Reference</emphasis>, called
30    <code>carray</code>. This is the essence of these approaches
31    spiced with many feedback from <ulink
32    url="">boost</ulink>.</para>
34    <para>After considering different names, we decided to name this
35    class simply <code><classname>array</classname></code>.</para>
37    <para>Note that this class is suggested to be part of the next
38    Technical Report, which will extend the C++ Standard (see
39    <ulink url=""></ulink>).</para>
41    <para>Class <code><classname>array</classname></code> fulfills most
42    but not all of the requirements of "reversible containers" (see
43    Section 23.1, [lib.container.requirements] of the C++
44    Standard). The reasons array is not an reversible STL container is
45    because:
46      <itemizedlist spacing="compact">
47        <listitem><simpara>No constructors are provided.</simpara></listitem>
48        <listitem><simpara>Elements may have an undetermined initial value (see <xref linkend="array.rationale"/>).</simpara></listitem>
49        <listitem><simpara><functionname>swap</functionname>() has no constant complexity.</simpara></listitem>
50        <listitem><simpara><methodname>size</methodname>() is always constant, based on the second template argument of the type.</simpara></listitem>
51        <listitem><simpara>The container provides no allocator support.</simpara></listitem>
52      </itemizedlist>
53    </para>
55    <para>It doesn't fulfill the requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts] of the C++ Standard), except that:
56      <itemizedlist spacing="compact">
57        <listitem><simpara><methodname>front</methodname>() and <methodname>back</methodname>() are provided.</simpara></listitem>
58        <listitem><simpara><methodname>operator[]</methodname> and <methodname>at</methodname>() are provided.</simpara></listitem>
59      </itemizedlist>
60    </para>
61  </section>