forked from boostorg/array
Compare commits
14 Commits
svn-branch
...
boost-1.22
Author | SHA1 | Date | |
---|---|---|---|
e3af599fd6 | |||
624bd0e218 | |||
ad82e2b25c | |||
44887bfe59 | |||
fd76085150 | |||
aac83e6667 | |||
a673bc6e82 | |||
a91e96a8ab | |||
debb0f0908 | |||
52dadb9764 | |||
b62e1aa4e7 | |||
8c5daba6b3 | |||
6533fa4606 | |||
e3d87e942c |
@ -28,7 +28,7 @@
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* This software is provided "as is" without express or implied</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* warranty, and with no claim as to its suitability for any purpose.</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* Jul 31, 2000</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* Sep 29, 2000</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||
#ifndef BOOST_ARRAY_HPP<BR>
|
||||
#define BOOST_ARRAY_HPP<BR>
|
||||
@ -38,10 +38,8 @@
|
||||
#include <iterator><BR>
|
||||
#include <algorithm><BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// BUG-FIX for compilers that don't support</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// std::size_t and std::ptrdiff_t yet</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// (such as gcc)</FONT></I><BR>
|
||||
#include <<A href="./config.hpp.html">boost/config.hpp</A>><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// FIXES for broken compilers</FONT></I><BR>
|
||||
#include <<A href="../../boost/config.hpp"><A href="http://www.boost.org/boost/config.hpp">boost/config.hpp</A></A>><BR>
|
||||
<BR>
|
||||
namespace boost {<BR>
|
||||
<BR>
|
||||
@ -67,8 +65,15 @@ namespace boost {<BR>
|
||||
const_iterator end() const { return elems+N; }<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// reverse iterator support</FONT></I><BR>
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)<BR>
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;<BR>
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;<BR>
|
||||
#else<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// workaround for broken reverse_iterator implementations due to no partial specialization</FONT></I><BR>
|
||||
typedef std::reverse_iterator<iterator,T> reverse_iterator;<BR>
|
||||
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;<BR>
|
||||
#endif<BR>
|
||||
<BR>
|
||||
reverse_iterator rbegin() { return reverse_iterator(end()); }<BR>
|
||||
const_reverse_iterator rbegin() const {<BR>
|
||||
return const_reverse_iterator(end());<BR>
|
||||
@ -98,7 +103,6 @@ namespace boost {<BR>
|
||||
static size_type max_size() { return N; }<BR>
|
||||
enum { static_size = N };<BR>
|
||||
<BR>
|
||||
public:<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// swap (note: linear complexity)</FONT></I><BR>
|
||||
void swap (array<T,N>& y) {<BR>
|
||||
std::swap_ranges(begin(),end(),y.begin());<BR>
|
||||
@ -120,7 +124,9 @@ namespace boost {<BR>
|
||||
std::fill_n(begin(),size(),value);<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE<BR>
|
||||
private:<BR>
|
||||
#endif<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// check range (may be private because it is static)</FONT></I><BR>
|
||||
static void rangecheck (size_type i) {<BR>
|
||||
if (i >= size()) { throw std::range_error("array"); }<BR>
|
||||
|
82
array.html
82
array.html
@ -15,11 +15,14 @@
|
||||
Wrapper) for Arrays of Constant Size</font></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<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 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">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
|
||||
@ -38,8 +41,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">The class provides the
|
||||
following interface:</font>
|
||||
<p><font face="Arial, Helvetica, sans-serif" size="-1"><a name="interface"></a>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>
|
||||
@ -127,7 +130,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 posistion behind last element of reverese iteration </font></td>
|
||||
for position behind last element of reverse iteration </font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">operator[<i>i</i>]</font></td>
|
||||
@ -197,15 +200,15 @@
|
||||
time</font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<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>
|
||||
<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>
|
||||
- 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>
|
||||
@ -236,43 +239,45 @@
|
||||
<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
|
||||
useus this approach. However, being able to have indetermined initial values
|
||||
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 <b>Open issues:</b></font>
|
||||
<ul>
|
||||
<li><font face="Arial, Helvetica, sans-serif">Do we want initializer list support
|
||||
or would the following be OK?:</font>
|
||||
<li><font face="Arial, Helvetica, sans-serif" size="-1">Do we want initializer
|
||||
list support or would the following be OK?:</font>
|
||||
<blockquote>
|
||||
<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>
|
||||
<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>
|
||||
</blockquote>
|
||||
</li>
|
||||
<li><font face="Arial, Helvetica, sans-serif">Could "<font face="Courier New, Courier, mono">{
|
||||
<li><font face="Arial, Helvetica, sans-serif" size="-1">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">8.5.1 (11) of the Standard seem
|
||||
to allow it; however, gcc 2.95.2 printa warning message.</font></p>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</ul>
|
||||
<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" 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"><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">
|
||||
<a href="array.hpp.html">as HTML file</a></font></li>
|
||||
<li><font face="Arial, Helvetica, sans-serif">
|
||||
<a href="array.hpp">as plain file</a></font></li>
|
||||
<a href="../../boost/array.hpp">as plain file</a></font></li>
|
||||
<p> <font face="Arial, Helvetica, sans-serif">Simple Example for using <font face="Courier New, Courier, mono">array<><font face="Arial, Helvetica, sans-serif">:</font></font></font>
|
||||
<li><font face="Arial, Helvetica, sans-serif">
|
||||
<a href="array1.cpp.html">as HTML file</a></font> </li>
|
||||
@ -314,7 +319,12 @@
|
||||
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"><br>
|
||||
</font>
|
||||
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>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,4 +1,8 @@
|
||||
/* simple example for using class array<>
|
||||
*
|
||||
* Changelog:
|
||||
* 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it
|
||||
* (David Abrahams)
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <boost/array.hpp>
|
||||
@ -18,7 +22,7 @@ int main()
|
||||
|
||||
// use some common STL container operations
|
||||
std::cout << "size: " << a.size() << std::endl;
|
||||
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;
|
||||
std::cout << "empty: " << (a.empty() ? "true" : "false") << std::endl;
|
||||
std::cout << "max_size: " << a.max_size() << std::endl;
|
||||
std::cout << "front: " << a.front() << std::endl;
|
||||
std::cout << "back: " << a.back() << std::endl;
|
||||
@ -39,8 +43,9 @@ int main()
|
||||
<< std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << "copy construction and copy assignment are OK"
|
||||
std::cout << "copy construction and copy assignment FAILED"
|
||||
<< std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ int main()<BR>
|
||||
<< std::endl;<BR>
|
||||
}<BR>
|
||||
else {<BR>
|
||||
std::cout << "copy construction and copy assignment are OK"<BR>
|
||||
std::cout << "copy construction and copy assignment FAILED"<BR>
|
||||
<< std::endl;<BR>
|
||||
}<BR>
|
||||
}<BR>
|
||||
|
@ -29,5 +29,6 @@ int main()
|
||||
a.begin(), // destination
|
||||
negate<int>()); // operation
|
||||
PRINT_ELEMENTS(a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ int main()
|
||||
std::cout << " " << *pos;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
@ -32,5 +32,6 @@ int main()
|
||||
std::cout << "last element of last array: "
|
||||
<< seasons_i18n[seasons_i18n.size()-1][seasons_i18n[0].size()-1]
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -60,5 +60,6 @@ int main()
|
||||
DArray da;
|
||||
da = ia;
|
||||
da.assign(42);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,8 @@
|
||||
* 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
|
||||
* 20 Jan 2001 - STLport fix (Beman Dawes)
|
||||
* 29 Sep 2000 - Initial Revision (Nico Josuttis)
|
||||
*/
|
||||
#ifndef BOOST_ARRAY_HPP
|
||||
#define BOOST_ARRAY_HPP
|
||||
@ -21,9 +22,7 @@
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
// BUG-FIX for compilers that don't support
|
||||
// std::size_t and std::ptrdiff_t yet
|
||||
// (such as gcc)
|
||||
// FIXES for broken compilers
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost {
|
||||
@ -50,14 +49,14 @@ namespace boost {
|
||||
const_iterator end() const { return elems+N; }
|
||||
|
||||
// reverse iterator support
|
||||
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
|
||||
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
|
||||
#else
|
||||
// workaround for broken reverse_iterator implementations
|
||||
typedef std::reverse_iterator<iterator,T> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
||||
const_reverse_iterator rbegin() const {
|
||||
@ -88,7 +87,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());
|
||||
@ -110,10 +108,10 @@ namespace boost {
|
||||
std::fill_n(begin(),size(),value);
|
||||
}
|
||||
|
||||
# ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
|
||||
#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
|
||||
private:
|
||||
# endif
|
||||
// private member functions are allowed in aggregates [ISO 8.5.1]
|
||||
#endif
|
||||
// check range (may be private because it is static)
|
||||
static void rangecheck (size_type i) {
|
||||
if (i >= size()) { throw std::range_error("array"); }
|
||||
}
|
||||
|
@ -13,8 +13,8 @@
|
||||
<tr>
|
||||
<td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
||||
<td><a href="../../index.htm"><font face="Arial" color="#FFFFFF"><big>Home</big></font></a></td>
|
||||
<td><a href="../../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td>
|
||||
<td><a href="../../people.htm"><font face="Arial" color="#FFFFFF"><big>People</big></font></a></td>
|
||||
<td><a href="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td>
|
||||
<td><a href="../../people/people.htm"><font face="Arial" color="#FFFFFF"><big>People</big></font></a></td>
|
||||
<td><a href="../../more/faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ</big></font></a></td>
|
||||
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More</big></font></a></td>
|
||||
</tr>
|
||||
@ -23,13 +23,12 @@
|
||||
<p>The header array.hpp provides an STL compliant container wrapper for arrays
|
||||
of constant size.
|
||||
<ul>
|
||||
<li><a href="array.htm">Documentation</a> (HTML).</li>
|
||||
<li><a href="array.html">Documentation</a> (HTML).</li>
|
||||
<li>Header <a href="../../boost/array.hpp">array.hpp</a></li>
|
||||
<li>See docs for links to example programs.</li>
|
||||
<li>Download <a href="../../boost_all.zip">all of Boost</a> (ZIP format).</li>
|
||||
<li>Submitted by <a href="http://www.josuttis.com">Nicolai M. Josuttis</a>.</li>
|
||||
</ul>
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->02 Aug 2000<!--webbot bot="Timestamp" endspan i-checksum="14748" --></p>
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->14 Mar 2001<!--webbot bot="Timestamp" endspan i-checksum="14885" --></p>
|
||||
|
||||
</body>
|
||||
|
||||
|
Reference in New Issue
Block a user