diff --git a/array.hpp.html b/array.hpp.html
index 6c7bc2c..3a51cac 100644
--- a/array.hpp.html
+++ b/array.hpp.html
@@ -28,7 +28,7 @@
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*
- * Jul 31, 2000
+ * Sep 29, 2000
*/
#ifndef BOOST_ARRAY_HPP
#define BOOST_ARRAY_HPP
@@ -38,10 +38,8 @@
#include <iterator>
#include <algorithm>
-// BUG-FIX for compilers that don't support
-// std::size_t and std::ptrdiff_t yet
-// (such as gcc)
-#include <boost/config.hpp>
+// FIXES for broken compilers
+#include <boost/config.hpp>
namespace boost {
@@ -67,8 +65,15 @@ namespace boost {
const_iterator end() const { return elems+N; }
// reverse iterator support
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+#else
+ // workaround for broken reverse_iterator implementations due to no partial specialization
+ typedef std::reverse_iterator<iterator,T> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
+#endif
+
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
@@ -98,7 +103,6 @@ namespace boost {
static size_type max_size() { return N; }
enum { static_size = N };
- public:
// swap (note: linear complexity)
void swap (array<T,N>& y) {
std::swap_ranges(begin(),end(),y.begin());
@@ -120,7 +124,9 @@ namespace boost {
std::fill_n(begin(),size(),value);
}
+#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
private:
+#endif
// check range (may be private because it is static)
static void rangecheck (size_type i) {
if (i >= size()) { throw std::range_error("array"); }
diff --git a/array.html b/array.html
index c432704..8ddb880 100644
--- a/array.html
+++ b/array.html
@@ -1,315 +1,320 @@
-
Class
- array, an STL Container (as
+ Class
+ array, an STL Container (as
Wrapper) for Arrays of Constant Size |
|
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: +
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_type | type of the elements | |||||||||
iterator | -type of the iterator + | type of the iterator (random-access iterator) | ||||||||
const_iterator | -type of iterator + | type of iterator that + considers elements as being constant | +||||||||
reference | +type of element reference | +|||||||||
const_reference | +type of element reference that considers elements as being constant | |||||||||
reference | -type of element - reference | -|||||||||
const_reference | -type of element - reference that considers elements as being constant | -|||||||||
size_type | -type for signed size + | type for signed size values | ||||||||
difference_type | -type for unsigned + | type for unsigned difference values | ||||||||
Operations: | ||||||||||
+ | ||||||||||
array<type,num> |
- default constructor, - creates array of num - element of type, see + | 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 + | copy constructor, + copies all elements of a + (a must have same + type and num) | ||||||||
operator= | -assignment, assigns + | assignment, assigns all elements | ||||||||
assign(val) | -assigns val + | assigns val to all elements | ||||||||
begin() | -returns iterator for + | returns iterator for the first element | ||||||||
end() | -returns iterator for + | returns iterator for position after the last element | ||||||||
rbegin() | -returns reverse - iterator for position of first element of reverse iteration | +returns reverse iterator + for position of first element of reverse iteration | ||||||||
rend() | -returns reverse - iterator for posistion behind last element of reverese iteration | +returns reverse iterator + for posistion behind last element of reverese iteration | ||||||||
operator[i] | -returns element with - index i (no range + | returns element with + index i (no range checking) | ||||||||
at(i) | -returns element with - index i (throw - std::range_error if i - is not valid) | +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 + | 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 + | returns raw element array for read-only element access | ||||||||
size() | -returns number of + | returns number of elements | ||||||||
empty() | -returns whether - array is empty | +returns whether array + is empty | ||||||||
max_size() | -returns maximum - possible number of elements (same as size()) | +returns maximum possible + number of elements (same as size()) | ||||||||
swap(a) | -swap elements with + | swap elements with array a | ||||||||
==,
+ ==,
!= |
checks for equality |
<,
- <=, >,
+ | <,
+ <=, >,
>= |
compares array |
Values: |
|
static_size |
- yields size at
- compile time |
+ yields 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:
+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:
-boost::array<int,4> - a = { { 1, 2, 3 } };
+- An array can be initialized + with a brace-enclosing, comma-separated list of initializers for the elements + of the container, written in increasing subscript order: +
-+-boost::array<int,4> + a = { { 1, 2, 3 } };
Note that if there - are fewer elements in the initializer list, then each remaining element gets - default-initialized (thus, it has a defined value).
+Note that if there + are fewer elements in the initializer list, then each remaining element + gets default-initialized (thus, it has a defined value).
- However, passing no - initializer list means that the elements have an indetermined initial value.
-- It has no - user-declared constructors.
-- It has no private or +
- However, passing + no initializer list means that the elements have an indetermined initial value.
+- It has no user-declared + constructors.
+- It has no private or protected non-static data members.
-- It has no base - classes.
-- It has no virtual - functions.
+- It has no base classes.
+- It has no virtual functions.
The current -implementation 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 Open issues: +
The current implementation + 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 Open issues:
+- Do we want initializer list support + or would the following be OK?: +
-int data[] = { 1, 2, 3, 4 }
-array<int,5> x(data); or - array<int,data> x;
+array<int,5> x(data); or + array<int,data> x;
- Could "{ - ... }" be used - portably instead of "{ { ... - } }" to initialize values?
+- Could "{ + ... }" be used + portably instead of "{ { ... + } }" to initialize values?
--8.5.1 (11) of the Standard seem - to allow it; however, gcc 2.95.2 printa warning message.
+8.5.1 (11) of the Standard seem + to allow it; however, gcc 2.95.2 printa warning message.
- Any way to have determined - initial values and initializer list support?
-- Static_casts for reverse - iterator stuff?
+- Any way to have determined initial + values and initializer list support?
+- Static_casts for reverse iterator + stuff?
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 -
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
-
-
+
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<>: +
Simple Example for using array<>: +
Another Example for using array<>: +
A third Example for using array<>: +
An Example for using arrays + of arrays: +
An Example for testing other operations + of array<>: +
All files +
Home
+ Page of Nicolai Josuttis
+
-
diff --git a/array1.cpp b/array1.cpp
index d04052c..e2be664 100644
--- a/array1.cpp
+++ b/array1.cpp
@@ -39,7 +39,7 @@ int main()
<< std::endl;
}
else {
- std::cout << "copy construction and copy assignment are OK"
+ std::cout << "copy construction and copy assignment FAILED"
<< std::endl;
}
}
diff --git a/array1.cpp.html b/array1.cpp.html
index a0cfa8f..1a9c061 100644
--- a/array1.cpp.html
+++ b/array1.cpp.html
@@ -56,7 +56,7 @@ int main()
<< std::endl;
}
else {
- std::cout << "copy construction and copy assignment are OK"
+ std::cout << "copy construction and copy assignment FAILED"
<< std::endl;
}
}
diff --git a/include/boost/array.hpp b/include/boost/array.hpp
index 31cc861..5200f60 100644
--- a/include/boost/array.hpp
+++ b/include/boost/array.hpp
@@ -11,7 +11,7 @@
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*
- * Jul 31, 2000
+ * Sep 29, 2000
*/
#ifndef BOOST_ARRAY_HPP
#define BOOST_ARRAY_HPP
@@ -21,9 +21,7 @@
#include