|
|
|
@ -15,14 +15,11 @@
|
|
|
|
|
Wrapper) for Arrays of Constant Size</font></b></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
<p><font size="-1" face="Arial, Helvetica, sans-serif">[<a href="#intro">intro</a>]
|
|
|
|
|
[<a href="#interface">interface</a>] [<a href="#discussion">discussion</a>]
|
|
|
|
|
[<a href="#code">code</a>]</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1"><a name="intro"></a>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).</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">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).</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">As replacement for ordinary
|
|
|
|
|
arrays, the STL provides class <font face="Courier New, Courier, mono">vector<></font>.
|
|
|
|
|
However, <font face="Courier New, Courier, mono">vector<></font> provides
|
|
|
|
@ -41,8 +38,8 @@
|
|
|
|
|
the essence of these approaches spiced with many feedback from <a href="http://www.boost.org">boost</a>.</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">After considering different
|
|
|
|
|
names, we decided to name this class simply <font face="Courier New, Courier, mono"><b>array</b></font>.</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1"><a name="interface"></a>The
|
|
|
|
|
class provides the following interface:</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">The class provides the
|
|
|
|
|
following interface:</font>
|
|
|
|
|
<table border="0">
|
|
|
|
|
<tr>
|
|
|
|
|
<td><font face="Arial, Helvetica, sans-serif" size="-1"><b>Types:</b></font></td>
|
|
|
|
@ -130,7 +127,7 @@
|
|
|
|
|
<tr>
|
|
|
|
|
<td><font face="Courier New, Courier, mono" size="-1">rend()</font></td>
|
|
|
|
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns reverse iterator
|
|
|
|
|
for position behind last element of reverse iteration </font></td>
|
|
|
|
|
for posistion behind last element of reverese iteration </font></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td><font face="Courier New, Courier, mono" size="-1">operator[<i>i</i>]</font></td>
|
|
|
|
@ -200,15 +197,15 @@
|
|
|
|
|
time</font></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1"><a name="discussion"></a>Class
|
|
|
|
|
array 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: </font> <font face="Arial, Helvetica, sans-serif" size="-1"><br>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">Class array 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: </font> <font face="Arial, Helvetica, sans-serif" size="-1"><br>
|
|
|
|
|
- No constructors are provided<br>
|
|
|
|
|
- Elements may have an indetermined initial value (see below)<br>
|
|
|
|
|
- swap() has no constant complexity<br>
|
|
|
|
|
- size() is always constant, based on the second template argument of the type<br>
|
|
|
|
|
- The container provides no allocator support</font>
|
|
|
|
|
- The container provides no allocator support</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">It doesn't fulfill the
|
|
|
|
|
requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts]
|
|
|
|
|
of the C++ Standard), except that</font> <font face="Arial, Helvetica, sans-serif" size="-1"><br>
|
|
|
|
@ -239,39 +236,37 @@
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">It has no virtual functions.</font></li>
|
|
|
|
|
</ul>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">The current implementation
|
|
|
|
|
uses this approach. However, being able to have indeterminate initial values
|
|
|
|
|
useus this approach. However, being able to have indetermined initial values
|
|
|
|
|
is a big drawback. So, please give me some feedback, how useful you consider
|
|
|
|
|
this feature to be. This leads to the list of <b>Open issues:</b></font>
|
|
|
|
|
<ul>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">Do we want initializer
|
|
|
|
|
list support or would the following be OK?:</font>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif">Do we want initializer list support
|
|
|
|
|
or would the following be OK?:</font>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p><font face="Courier New, Courier, mono" size="-1">int data[] = { 1, 2,
|
|
|
|
|
3, 4 }</font></p>
|
|
|
|
|
<p><font face="Courier New, Courier, mono" size="-1">array<int,5>
|
|
|
|
|
x(data); <font face="Arial, Helvetica, sans-serif">or </font> array<int,data>
|
|
|
|
|
x;</font></p>
|
|
|
|
|
<p><font face="Courier New, Courier, mono">int data[] = { 1, 2, 3, 4 }</font></p>
|
|
|
|
|
<p><font face="Courier New, Courier, mono">array<int,5> x(data); <font face="Arial, Helvetica, sans-serif">or
|
|
|
|
|
</font> array<int,data> x;</font></p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</li>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">Could "<font face="Courier New, Courier, mono">{
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif">Could "<font face="Courier New, Courier, mono">{
|
|
|
|
|
</font>...<font face="Courier New, Courier, mono"> }</font>" be used
|
|
|
|
|
portably instead of "<font face="Courier New, Courier, mono">{ { </font>...<font face="Courier New, Courier, mono">
|
|
|
|
|
} }</font>" to initialize values?</font> </li>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">8.5.1 (11) of the Standard
|
|
|
|
|
seems to allow it; however, gcc 2.95.2 prints a warning message.</font></p>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif">8.5.1 (11) of the Standard seem
|
|
|
|
|
to allow it; however, gcc 2.95.2 printa warning message.</font></p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">Any way to have determinate
|
|
|
|
|
initial values and initializer list support?</font></li>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">Static_casts for reverse
|
|
|
|
|
iterator stuff?</font></li>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif">Any way to have determined initial
|
|
|
|
|
values and initializer list support?</font></li>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif">Static_casts for reverse iterator
|
|
|
|
|
stuff</font><font face="Arial, Helvetica, sans-serif">?</font></li>
|
|
|
|
|
</ul>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">I'd appreciate any constructive
|
|
|
|
|
<a href="mailto:solutions@josuttis.com">feedback</a>. <b>Please note: I don't
|
|
|
|
|
have time to read all boost mails. Thus, to make sure that feedback arrives
|
|
|
|
|
me, please send me a copy of each mail regarding this class.</b></font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif"><a name="code"></a>The code is provided
|
|
|
|
|
"as is" without expressed or implied warranty.</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif">I'd appreciate any constructive <a href="mailto:solutions@josuttis.com">feedback</a>.
|
|
|
|
|
<b>Please note: I don't have time to read all boost mails. Thus, to make sure
|
|
|
|
|
that feedback arrives me, please send me a copy of each mail regarding this
|
|
|
|
|
class.</b></font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif">The code is provided "as is" without
|
|
|
|
|
expressed or implied warranty.</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif"><b>array.hpp</b>, the implementation
|
|
|
|
|
of <font face="Courier New, Courier, mono">array<></font><b>:</b> </font>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif">
|
|
|
|
@ -303,12 +298,7 @@
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array5.cpp.html">as HTML
|
|
|
|
|
file</a></font></li>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array5.cpp">as plain file</a></font></li>
|
|
|
|
|
<p><b><font face="Arial, Helvetica, sans-serif">All files</font></b>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array.zip">as ZIP file
|
|
|
|
|
(24KB)</a></font></li>
|
|
|
|
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array.tgz">as TGZ file
|
|
|
|
|
(13KB)</a><br>
|
|
|
|
|
<br>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif">
|
|
|
|
|
To find more details about using ordinary arrays in C++ and the framework of
|
|
|
|
|
the STL, see e.g.</font> <font face="Arial, Helvetica, sans-serif"><br>
|
|
|
|
|
<i> <a href="http://www.josuttis.com/libbook/">The C++
|
|
|
|
@ -317,14 +307,9 @@
|
|
|
|
|
M. Josuttis</a></font> <font face="Arial, Helvetica, sans-serif"><br>
|
|
|
|
|
Addison Wesley Longman, 1999</font> <font face="Arial, Helvetica, sans-serif"><br>
|
|
|
|
|
ISBN 0-201-37926-0</font> <font face="Arial, Helvetica, sans-serif"><br>
|
|
|
|
|
</font></li>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif"><a href="http://www.josuttis.com/" TARGET="_top">Home
|
|
|
|
|
Page of Nicolai Josuttis</a></font><font face="Arial, Helvetica, sans-serif">
|
|
|
|
|
</font>
|
|
|
|
|
<p><font size="-1" face="Arial, Helvetica, sans-serif">[<a href="#intro">intro</a>]
|
|
|
|
|
[<a href="#interface">interface</a>] [<a href="#discussion">discussion</a>]
|
|
|
|
|
[<a href="#code">code</a>]</font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif" size="-1"></font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif"> </font>
|
|
|
|
|
<p><font face="Arial, Helvetica, sans-serif"><a href="http://www.josuttis.com/" TARGET="_top">Home
|
|
|
|
|
Page of Nicolai Josuttis</a></font> <font face="Arial, Helvetica, sans-serif"><br>
|
|
|
|
|
</font>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|