summaryrefslogtreecommitdiff
path: root/doc/test/array.xml
blob: ce3f57e029053524b2e084877d527909e9630a8c (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
<section id="array.intro">
    <title>Introduction</title> 

    <using-namespace name="boost"/>
    <using-class name="array"/>

    <para>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).</para>

    <para>As replacement for ordinary arrays, the STL provides class
    <code><classname>std::vector</classname></code>.  However,
    <code><classname>std::vector&lt;&gt;</classname></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.</para>

    <para>In his book, <emphasis>Generic Programming and the
    STL</emphasis>, Matthew H. Austern introduces a useful wrapper
    class for ordinary arrays with static size, called
    <code>block</code>.  It is safer and has no worse performance than
    ordinary arrays. In <emphasis>The C++ Programming
    Language</emphasis>, 3rd edition, Bjarne Stroustrup introduces a
    similar class, called <code>c_array</code>, which I (<ulink
    url="http://www.josuttis.com">Nicolai Josuttis</ulink>) present
    slightly modified in my book <emphasis>The C++ Standard Library -
    A Tutorial and Reference</emphasis>, called
    <code>carray</code>. This is the essence of these approaches
    spiced with many feedback from <ulink
    url="http://www.boost.org">boost</ulink>.</para>

    <para>After considering different names, we decided to name this
    class simply <code><classname>array</classname></code>.</para>

    <para>Note that this class is suggested to be part of the next
    Technical Report, which will extend the C++ Standard (see
    <ulink url="http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm">http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</ulink>).</para>

    <para>Class <code><classname>array</classname></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:
      <itemizedlist spacing="compact">
        <listitem><simpara>No constructors are provided.</simpara></listitem>
        <listitem><simpara>Elements may have an undetermined initial value (see <xref linkend="array.rationale"/>).</simpara></listitem>
        <listitem><simpara><functionname>swap</functionname>() has no constant complexity.</simpara></listitem>
        <listitem><simpara><methodname>size</methodname>() is always constant, based on the second template argument of the type.</simpara></listitem>
        <listitem><simpara>The container provides no allocator support.</simpara></listitem>
      </itemizedlist>
    </para>

    <para>It doesn't fulfill the requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts] of the C++ Standard), except that:
      <itemizedlist spacing="compact">
        <listitem><simpara><methodname>front</methodname>() and <methodname>back</methodname>() are provided.</simpara></listitem>
        <listitem><simpara><methodname>operator[]</methodname> and <methodname>at</methodname>() are provided.</simpara></listitem>
      </itemizedlist>
    </para>
  </section>