From 6a4597e4b2c8f34a388dda856db9e54191d51390 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 20 Feb 2001 12:17:56 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create branch 'unlabeled-1.5.2'. [SVN r9288] --- .gitattributes | 96 ++++++++++++++ array.html | 330 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 426 insertions(+) create mode 100644 .gitattributes create mode 100644 array.html diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3e84d7c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,96 @@ +* text=auto !eol svneol=native#text/plain +*.gitattributes text svneol=native#text/plain + +# Scriptish formats +*.bat text svneol=native#text/plain +*.bsh text svneol=native#text/x-beanshell +*.cgi text svneol=native#text/plain +*.cmd text svneol=native#text/plain +*.js text svneol=native#text/javascript +*.php text svneol=native#text/x-php +*.pl text svneol=native#text/x-perl +*.pm text svneol=native#text/x-perl +*.py text svneol=native#text/x-python +*.sh eol=lf svneol=LF#text/x-sh +configure eol=lf svneol=LF#text/x-sh + +# Image formats +*.bmp binary svneol=unset#image/bmp +*.gif binary svneol=unset#image/gif +*.ico binary svneol=unset#image/ico +*.jpeg binary svneol=unset#image/jpeg +*.jpg binary svneol=unset#image/jpeg +*.png binary svneol=unset#image/png +*.tif binary svneol=unset#image/tiff +*.tiff binary svneol=unset#image/tiff +*.svg text svneol=native#image/svg%2Bxml + +# Data formats +*.pdf binary svneol=unset#application/pdf +*.avi binary svneol=unset#video/avi +*.doc binary svneol=unset#application/msword +*.dsp text svneol=crlf#text/plain +*.dsw text svneol=crlf#text/plain +*.eps binary svneol=unset#application/postscript +*.gz binary svneol=unset#application/gzip +*.mov binary svneol=unset#video/quicktime +*.mp3 binary svneol=unset#audio/mpeg +*.ppt binary svneol=unset#application/vnd.ms-powerpoint +*.ps binary svneol=unset#application/postscript +*.psd binary svneol=unset#application/photoshop +*.rdf binary svneol=unset#text/rdf +*.rss text svneol=unset#text/xml +*.rtf binary svneol=unset#text/rtf +*.sln text svneol=native#text/plain +*.swf binary svneol=unset#application/x-shockwave-flash +*.tgz binary svneol=unset#application/gzip +*.vcproj text svneol=native#text/xml +*.vcxproj text svneol=native#text/xml +*.vsprops text svneol=native#text/xml +*.wav binary svneol=unset#audio/wav +*.xls binary svneol=unset#application/vnd.ms-excel +*.zip binary svneol=unset#application/zip + +# Text formats +.htaccess text svneol=native#text/plain +*.bbk text svneol=native#text/xml +*.cmake text svneol=native#text/plain +*.css text svneol=native#text/css +*.dtd text svneol=native#text/xml +*.htm text svneol=native#text/html +*.html text svneol=native#text/html +*.ini text svneol=native#text/plain +*.log text svneol=native#text/plain +*.mak text svneol=native#text/plain +*.qbk text svneol=native#text/plain +*.rst text svneol=native#text/plain +*.sql text svneol=native#text/x-sql +*.txt text svneol=native#text/plain +*.xhtml text svneol=native#text/xhtml%2Bxml +*.xml text svneol=native#text/xml +*.xsd text svneol=native#text/xml +*.xsl text svneol=native#text/xml +*.xslt text svneol=native#text/xml +*.xul text svneol=native#text/xul +*.yml text svneol=native#text/plain +boost-no-inspect text svneol=native#text/plain +CHANGES text svneol=native#text/plain +COPYING text svneol=native#text/plain +INSTALL text svneol=native#text/plain +Jamfile text svneol=native#text/plain +Jamroot text svneol=native#text/plain +Jamfile.v2 text svneol=native#text/plain +Jamrules text svneol=native#text/plain +Makefile* text svneol=native#text/plain +README text svneol=native#text/plain +TODO text svneol=native#text/plain + +# Code formats +*.c text svneol=native#text/plain +*.cpp text svneol=native#text/plain +*.h text svneol=native#text/plain +*.hpp text svneol=native#text/plain +*.ipp text svneol=native#text/plain +*.tpp text svneol=native#text/plain +*.jam text svneol=native#text/plain +*.java text svneol=native#text/plain diff --git a/array.html b/array.html new file mode 100644 index 0000000..cd17aea --- /dev/null +++ b/array.html @@ -0,0 +1,330 @@ + + + + + + +array.hpp, an STL Array Wrapper + + +  + + + + +
Class + array, an STL Container (as + Wrapper) for Arrays of Constant Size
+

[intro] + [interface] [discussion] + [code] +

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). +

As replacement for ordinary + arrays, the STL provides class vector<>. + However, vector<> 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. +

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

After considering different + names, we decided to name this class simply array. +

The + class provides the following interface: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Types:
value_typetype of the elements
iteratortype of the iterator + (random-access iterator)
const_iteratortype of iterator that + considers elements as being constant
referencetype of element reference
const_referencetype of element reference + that considers elements as being constant
size_typetype for signed size + values
difference_typetype for unsigned + difference values
Operations:
+

array<type,num>

+
default constructor, + creates array of num + element of type, see + comment below
array<type,num>(a)copy constructor, + copies all elements of a + (a must have same + type + and num)
operator=assignment, assigns + all elements
assign(val)assigns val + to all elements
begin()returns iterator for + the first element
end()returns iterator for + position after the last element
rbegin()returns reverse iterator + for position of first element of reverse iteration
rend()returns reverse iterator + for position behind last element of reverse iteration
operator[i]returns element with + index i (no range + checking)
at(i)returns element with + index i (throw std::range_error + if i is not valid)
front()returns first element + (caller has to ensure that it exists)
back()returns last element + (caller has to ensure that it exists)
data()returns raw element + array for read-only element access
size()returns number of + elements
empty()returns whether array + is empty
max_size()returns maximum possible + number of elements (same as size())
swap(a)swap elements with + array a
==, + !=checks for equality
<, + <=, >, + >=compares array
Values: 
static_sizeyields size at compile + time
+

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:
+ - No constructors are provided
+ - Elements may have an indetermined initial value (see below)
+ - swap() has no constant complexity
+ - size() is always constant, based on the second template argument of the type
+ - The container provides no allocator support
+

It doesn't fulfill the + requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts] + of the C++ Standard), except that
+ - front() and back() are provided
+ - operator[] and at() are provided
+

Regarding the constructors + there was an important design tradeoff: We could implement array as an "aggregate" + (see Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would mean:

+ +

The current implementation + uses this approach. However, being able to have indeterminate 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 Open issues: +

+

I'd appreciate any constructive + feedback. 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. +

The code is provided + "as is" without expressed or implied warranty. +

array.hpp, the implementation + of array<>: +

  • + as HTML file
  • +
  • + as plain file
  • +

    Simple Example for using array<>: +

  • + as HTML file
  • +
  • + as plain file
  • +

    Another Example for using array<>: +

  • + as HTML file
  • +
  • + as plain file
  • +

    A third Example for using array<>: +

  • + as HTML file
  • +
  • + as plain file
  • +

    An Example for using arrays + of arrays: +

  • as HTML + file
  • +
  • as plain file
  • +

    An Example for testing other operations + of array<>: +

  • as HTML + file
  • +
  • as plain file
  • +

    All files +

  • as ZIP file + (24KB)
  • +
  • as TGZ file + (13KB)
    +
    + To find more details about using ordinary arrays in C++ and the framework of + the STL, see e.g.

    +      The C++ + Standard Library - A Tutorial and Reference
    +      by Nicolai + M. Josuttis

    +      Addison Wesley Longman, 1999

    +      ISBN 0-201-37926-0

    +
  • +

    Home + Page of Nicolai Josuttis + +

    [intro] + [interface] [discussion] + [code] +

    +

      + +