mirror of
https://github.com/boostorg/array.git
synced 2025-06-25 20:11:45 +02:00
Compare commits
34 Commits
boost-1.25
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
bcbf9de9ed | |||
069b5e2ca1 | |||
526953fc5e | |||
b06f12b0b7 | |||
f0bbb8b211 | |||
d7a5408143 | |||
564e4029d0 | |||
0dc11c2f23 | |||
7da1c4b310 | |||
8f10fdf27e | |||
b41f7fdebe | |||
2fde5e334b | |||
4ee6e051fe | |||
bac6446111 | |||
cfb6d6eae6 | |||
0543286830 | |||
1c6f9ef038 | |||
d38c367afd | |||
a5a75f81bd | |||
ab72ec517c | |||
8a119110be | |||
3daa34744f | |||
0f3969f9e0 | |||
c501468b53 | |||
faf0005e86 | |||
785e98fcac | |||
13d4e8bc40 | |||
9ea2182afa | |||
bf3b240686 | |||
6b9c6c9de3 | |||
fe013c42b7 | |||
b87433497e | |||
09c271cf34 | |||
f5699ae164 |
175
array.hpp.html
175
array.hpp.html
@ -1,175 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>array.hpp</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||
|
||||
<TABLE HEIGHT=40 WIDTH="100%">
|
||||
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||
<FONT face="Arial,Helvetica" size=+2><B>
|
||||
array.hpp
|
||||
</B></FONT>
|
||||
</TD></TR></TABLE><BR>
|
||||
|
||||
<BR><BR>
|
||||
<TT>
|
||||
<SPAN class="Source">
|
||||
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* The following code declares class array,</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* an STL container (as wrapper) for arrays of constant size.</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* See</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* <a href="http://www.josuttis.com/cppcode">http://www.josuttis.com/cppcode</a></FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* for details and the latest version.</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* (C) Copyright Nicolai M. Josuttis 2001.</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* Permission to copy, use, modify, sell and distribute this software</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* is granted provided this copyright notice appears in all copies.</FONT></I><BR>
|
||||
<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" >* Aug 05, 2001</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>
|
||||
<BR>
|
||||
#include <cstddef><BR>
|
||||
#include <stdexcept><BR>
|
||||
#include <iterator><BR>
|
||||
#include <algorithm><BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// FIXES for broken compilers</FONT></I><BR>
|
||||
#include <<A href="../../boost/config.hpp">boost/config.hpp</A>><BR>
|
||||
<BR>
|
||||
namespace boost {<BR>
|
||||
<BR>
|
||||
template<class T, std::size_t N><BR>
|
||||
class array {<BR>
|
||||
public:<BR>
|
||||
T elems[N]; <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// fixed-size array of elements of type T</FONT></I><BR>
|
||||
<BR>
|
||||
public:<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// type definitions</FONT></I><BR>
|
||||
typedef T value_type;<BR>
|
||||
typedef T* iterator;<BR>
|
||||
typedef const T* const_iterator;<BR>
|
||||
typedef T& reference;<BR>
|
||||
typedef const T& const_reference;<BR>
|
||||
typedef std::size_t size_type;<BR>
|
||||
typedef std::ptrdiff_t difference_type;<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// iterator support</FONT></I><BR>
|
||||
iterator begin() { return elems; }<BR>
|
||||
const_iterator begin() const { return elems; }<BR>
|
||||
iterator end() { return elems+N; }<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) && !defined(BOOST_MSVC_STD_ITERATOR)<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</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>
|
||||
}<BR>
|
||||
reverse_iterator rend() { return reverse_iterator(begin()); }<BR>
|
||||
const_reverse_iterator rend() const {<BR>
|
||||
return const_reverse_iterator(begin());<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// operator[]</FONT></I><BR>
|
||||
reference operator[](size_type i) { return elems[i]; }<BR>
|
||||
const_reference operator[](size_type i) const { return elems[i]; }<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// at() with range check</FONT></I><BR>
|
||||
reference at(size_type i) { rangecheck(i); return elems[i]; }<BR>
|
||||
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// front() and back()</FONT></I><BR>
|
||||
reference front() { return elems[0]; }<BR>
|
||||
const_reference front() const { return elems[0]; }<BR>
|
||||
reference back() { return elems[N-1]; }<BR>
|
||||
const_reference back() const { return elems[N-1]; }<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// size is constant</FONT></I><BR>
|
||||
static size_type size() { return N; }<BR>
|
||||
static bool empty() { return false; }<BR>
|
||||
static size_type max_size() { return N; }<BR>
|
||||
enum { static_size = N };<BR>
|
||||
<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>
|
||||
}<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// direct access to data</FONT></I><BR>
|
||||
const T* data() const { return elems; }<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// assignment with type conversion</FONT></I><BR>
|
||||
template <typename T2><BR>
|
||||
array<T,N>& operator= (const array<T2,N>& rhs) {<BR>
|
||||
std::copy(rhs.begin(),rhs.end(), begin());<BR>
|
||||
return *this;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// assign one value to all elements</FONT></I><BR>
|
||||
void assign (const T& value)<BR>
|
||||
{<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>
|
||||
}<BR>
|
||||
<BR>
|
||||
};<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// comparisons</FONT></I><BR>
|
||||
template<class T, std::size_t N><BR>
|
||||
bool operator== (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||
return std::equal(x.begin(), x.end(), y.begin());<BR>
|
||||
}<BR>
|
||||
template<class T, std::size_t N><BR>
|
||||
bool operator< (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||
return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());<BR>
|
||||
}<BR>
|
||||
template<class T, std::size_t N><BR>
|
||||
bool operator!= (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||
return !(x==y);<BR>
|
||||
}<BR>
|
||||
template<class T, std::size_t N><BR>
|
||||
bool operator> (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||
return y<x;<BR>
|
||||
}<BR>
|
||||
template<class T, std::size_t N><BR>
|
||||
bool operator<= (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||
return !(y<x);<BR>
|
||||
}<BR>
|
||||
template<class T, std::size_t N><BR>
|
||||
bool operator>= (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||
return !(x<y);<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// global swap()</FONT></I><BR>
|
||||
template<class T, std::size_t N><BR>
|
||||
inline void swap (array<T,N>& x, array<T,N>& y) {<BR>
|
||||
x.swap(y);<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
} <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >/* namespace boost */</FONT></I><BR>
|
||||
<BR>
|
||||
#endif <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >/*BOOST_ARRAY_HPP*/</FONT></I><BR>
|
||||
</SPAN>
|
||||
</TT>
|
||||
</BODY>
|
||||
</HTML>
|
330
array.html
330
array.html
@ -1,330 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Keywords" content="array, block, carray, c_array, array wrapper, adapter, adaptor, STL, C++ Standard Library, array.hpp">
|
||||
|
||||
<title>array.hpp, an STL Array Wrapper</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#FFFFFF" link="#186ABF">
|
||||
<font face="Arial, Helvetica, sans-serif"> </font>
|
||||
<table width="100%" height="40">
|
||||
<tr>
|
||||
<td BGCOLOR="#DDDDDD"><b><font face="Arial,helvetica" color="#000000" size="+1">Class
|
||||
<font face="Courier New, Courier, mono">array</font>, an STL Container (as
|
||||
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">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
|
||||
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.</font>
|
||||
<p><font face="Arial, Helvetica, sans-serif" size="-1">In his book, <i>Generic
|
||||
Programming and the STL</i>, Matthew H. Austern introduces a useful wrapper
|
||||
class for ordinary arrays with static size, called <font face="Courier New, Courier, mono"><b>block</b></font>.
|
||||
It is safer and has no worse performance than ordinary arrays. In <i>The C++
|
||||
Programming Language</i>, 3rd edition, Bjarne Stroustrup introduces a similar
|
||||
class, called <font face="Courier New, Courier, mono"><b>c_array</b></font>,
|
||||
which I (<a href="http://www.josuttis.com">Nicolai Josuttis</a>) present slightly
|
||||
modified in my book <i>The C++ Standard Library - A Tutorial and Reference</i>,
|
||||
called <font face="Courier New, Courier, mono"><b>carray</b></font>. This is
|
||||
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>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1"><b>Types:</b></font></td>
|
||||
<td><font size="-1"></font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">value_type</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of the elements</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">iterator</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of the iterator
|
||||
(random-access iterator)</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">const_iterator</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of iterator that
|
||||
considers elements as being constant</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">reference</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of element reference</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">const_reference</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of element reference
|
||||
that considers elements as being constant</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">size_type</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">type for signed size
|
||||
values</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">difference_type</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">type for unsigned
|
||||
difference values</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1"><b>Operations:</b></font></td>
|
||||
<td><font size="-1"></font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p><font face="Courier New, Courier, mono" size="-1">array<<i>type</i>,<i>num</i>></font></p>
|
||||
</td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">default constructor,
|
||||
creates array of <i><font face="Courier New, Courier, mono">num</font></i>
|
||||
element of <i><font face="Courier New, Courier, mono">type</font></i>, see
|
||||
comment below</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">array<<i>type</i>,<i>num</i>>(<i>a</i>)</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">copy constructor,
|
||||
copies all elements of <i><font face="Courier New, Courier, mono">a</font></i>
|
||||
(<i><font face="Courier New, Courier, mono">a</font></i> must have same
|
||||
<i> <font face="Courier New, Courier, mono">type</font></i><font face="Courier New, Courier, mono"><font face="Arial, Helvetica, sans-serif">
|
||||
and </font></font><i><font face="Courier New, Courier, mono">num</font></i>)</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">operator=</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">assignment, assigns
|
||||
all elements</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">assign(<i>val</i>)</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">assigns <i>val</i>
|
||||
to all elements</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">begin()</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns iterator for
|
||||
the first element</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">end()</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns iterator for
|
||||
position after the last element</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">rbegin()</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns reverse iterator
|
||||
for position of first element of reverse iteration</font></td>
|
||||
</tr>
|
||||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">operator[<i>i</i>]</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns element with
|
||||
index <i><font face="Courier New, Courier, mono">i</font></i> (no range
|
||||
checking)</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">at(<i>i</i>)</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns element with
|
||||
index <font face="Courier New, Courier, mono"><i>i</i></font> (throw std::range_error
|
||||
if <i><font face="Courier New, Courier, mono">i</font></i> is not valid)</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">front()</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns first element
|
||||
(caller has to ensure that it exists)</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">back()</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns last element
|
||||
(caller has to ensure that it exists)</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">data()</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns raw element
|
||||
array for read-only element access</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">size()</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns number of
|
||||
elements</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">empty()</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns whether array
|
||||
is empty</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">max_size()</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns maximum possible
|
||||
number of elements (same as size())</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">swap(a)</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">swap elements with
|
||||
array a</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">==<font face="Arial, Helvetica, sans-serif">,
|
||||
</font>!=</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">checks for equality</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1"><<font face="Arial, Helvetica, sans-serif">,
|
||||
</font><=<font face="Arial, Helvetica, sans-serif">, </font>><font face="Arial, Helvetica, sans-serif">,
|
||||
</font>>=</font></td>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1">compares array</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Arial, Helvetica, sans-serif" size="-1"><b>Values:</b></font></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font face="Courier New, Courier, mono" size="-1">static_size</font></td>
|
||||
<td><font size="-1" face="Arial, Helvetica, sans-serif">yields size at compile
|
||||
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>
|
||||
- No constructors are provided<br>
|
||||
- Elements may have an undetermined 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>
|
||||
<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>
|
||||
- front() and back() are provided<br>
|
||||
- operator[] and at() are provided</font>
|
||||
<p><font face="Arial, Helvetica, sans-serif" size="-1">Regarding the constructors
|
||||
there was an important design tradeoff: We could implement array as an "<b>aggregate</b>"
|
||||
(see Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would mean:</font></p>
|
||||
<ul>
|
||||
<li><font face="Arial, Helvetica, sans-serif" size="-1">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:</font>
|
||||
<blockquote>
|
||||
<p><font face="Arial, Helvetica, sans-serif" size="-1">boost::array<int,4>
|
||||
a = { { 1, 2, 3 } };</font></p>
|
||||
</blockquote>
|
||||
<p><font face="Arial, Helvetica, sans-serif" size="-1">Note that if there
|
||||
are fewer elements in the initializer list, then each remaining element
|
||||
gets default-initialized (thus, it has a defined value).</font></p>
|
||||
</li>
|
||||
<li><font face="Arial, Helvetica, sans-serif" size="-1">However, <b>passing
|
||||
no initializer list means that the elements have an indetermined initial value</b>.</font></li>
|
||||
<li><font face="Arial, Helvetica, sans-serif" size="-1">It has no user-declared
|
||||
constructors.</font></li>
|
||||
<li><font face="Arial, Helvetica, sans-serif" size="-1">It has no private or
|
||||
protected non-static data members.</font></li>
|
||||
<li><font face="Arial, Helvetica, sans-serif" size="-1">It has no base classes.</font></li>
|
||||
<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
|
||||
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>
|
||||
<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>
|
||||
</blockquote>
|
||||
</li>
|
||||
<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" 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" 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" 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="../../boost/array.hpp">as plain file</a></font></li>
|
||||
<p> <font face="Arial, Helvetica, sans-serif"><b>array1.cpp</b>, a 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>
|
||||
<li><font face="Arial, Helvetica, sans-serif">
|
||||
<a href="array1.cpp">as plain file</a></font></li>
|
||||
<p> <font face="Arial, Helvetica, sans-serif"><b>array2.cpp</b>, another 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="array2.cpp.html">as HTML file</a></font></li>
|
||||
<li><font face="Arial, Helvetica, sans-serif">
|
||||
<a href="array2.cpp">as plain file</a></font></li>
|
||||
<p> <font face="Arial, Helvetica, sans-serif"><b>array3.cpp</b>, a third 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="array3.cpp.html">as HTML file</a></font></li>
|
||||
<li><font face="Arial, Helvetica, sans-serif">
|
||||
<a href="array3.cpp">as plain file</a></font></li>
|
||||
<p> <font face="Arial, Helvetica, sans-serif"><b>array4.cpp</b>, an example for
|
||||
using <font face="Courier New, Courier, mono">array</font>s of <font face="Courier New, Courier, mono">array</font>s<font face="Courier New, Courier, mono"><font face="Arial, Helvetica, sans-serif">:</font></font></font>
|
||||
<li><font face="Arial, Helvetica, sans-serif"> <a href="array4.cpp.html">as HTML
|
||||
file</a></font></li>
|
||||
<li><font face="Arial, Helvetica, sans-serif"> <a href="array4.cpp">as plain file</a></font></li>
|
||||
<p><font face="Arial, Helvetica, sans-serif"><b>array5.cpp</b>, an example for
|
||||
testing other operations of <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="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>
|
||||
<br>
|
||||
<br>
|
||||
<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++
|
||||
Standard Library - A Tutorial and Reference</a></i> <br>
|
||||
by <a href="http://www.josuttis.com" target="_top">Nicolai
|
||||
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>
|
||||
</body>
|
||||
</html>
|
107
array0.cpp
Normal file
107
array0.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/* tests for using class array<> specialization for size 0
|
||||
* (C) Copyright Alisdair Meredith 2006.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
namespace {
|
||||
unsigned int failed_tests = 0;
|
||||
|
||||
void fail_test( const char * reason ) {
|
||||
++failed_tests;
|
||||
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void BadValue( const T & )
|
||||
{
|
||||
fail_test( "Unexpected value" );
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void RunTests()
|
||||
{
|
||||
typedef boost::array< T, 0 > test_type;
|
||||
|
||||
// Test value and aggegrate initialization
|
||||
test_type test_case = {};
|
||||
const boost::array< T, 0 > const_test_case = test_type();
|
||||
|
||||
test_case.assign( T() );
|
||||
|
||||
// front/back and operator[] must compile, but calling them is undefined
|
||||
// Likewise, all tests below should evaluate to false, avoiding undefined behaviour
|
||||
if( !test_case.empty() ) {
|
||||
BadValue( test_case.front() );
|
||||
}
|
||||
|
||||
if( !const_test_case.empty() ) {
|
||||
BadValue( const_test_case.back() );
|
||||
}
|
||||
|
||||
if( test_case.size() > 0 ) {
|
||||
BadValue( test_case[ 0 ] );
|
||||
}
|
||||
|
||||
if( const_test_case.max_size() > 0 ) {
|
||||
BadValue( const_test_case[ 0 ] );
|
||||
}
|
||||
|
||||
// Assert requirements of TR1 6.2.2.4
|
||||
if( test_case.begin() != test_case.end() ) {
|
||||
fail_test( "Not an empty range" );
|
||||
}
|
||||
if( const_test_case.begin() != const_test_case.end() ) {
|
||||
fail_test( "Not an empty range" );
|
||||
}
|
||||
|
||||
if( test_case.begin() == const_test_case.begin() ) {
|
||||
fail_test( "iterators for different containers are not distinct" );
|
||||
}
|
||||
|
||||
if( test_case.data() == const_test_case.data() ) {
|
||||
// Value of data is unspecified in TR1, so no requirement this test pass or fail
|
||||
// However, it must compile!
|
||||
}
|
||||
|
||||
|
||||
// Check can safely use all iterator types with std algorithms
|
||||
std::for_each( test_case.begin(), test_case.end(), BadValue< T > );
|
||||
std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > );
|
||||
std::for_each( const_test_case.begin(), const_test_case.end(), BadValue< T > );
|
||||
std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > );
|
||||
|
||||
// Check swap is well formed
|
||||
std::swap( test_case, test_case );
|
||||
|
||||
// Check assigment operator and overloads are well formed
|
||||
test_case = const_test_case;
|
||||
|
||||
// Confirm at() throws the std lib defined exception
|
||||
try {
|
||||
BadValue( test_case.at( 0 ) );
|
||||
} catch ( const std::out_of_range & ) {
|
||||
}
|
||||
|
||||
try {
|
||||
BadValue( const_test_case.at( 0 ) );
|
||||
} catch ( const std::out_of_range & ) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
RunTests< bool >();
|
||||
RunTests< void * >();
|
||||
RunTests< long double >();
|
||||
RunTests< std::string >();
|
||||
return failed_tests;
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
/* simple example for using class array<>
|
||||
*
|
||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* Changelog:
|
||||
* 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it
|
||||
* (David Abrahams)
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
|
@ -1,69 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>array1.cpp</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||
|
||||
<TABLE HEIGHT=40 WIDTH="100%">
|
||||
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||
<FONT face="Arial,Helvetica" size=+2><B>
|
||||
array1.cpp
|
||||
</B></FONT>
|
||||
</TD></TR></TABLE><BR>
|
||||
|
||||
<BR><BR>
|
||||
<TT>
|
||||
<SPAN class="Source">
|
||||
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* simple example for using class array<></FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||
#include <iostream><BR>
|
||||
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||
<BR>
|
||||
int main()<BR>
|
||||
{<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// define special type name</FONT></I><BR>
|
||||
typedef boost::array<float,6> Array;<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create and initialize an array</FONT></I><BR>
|
||||
Array a = { { 42 } };<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// access elements</FONT></I><BR>
|
||||
for (unsigned i=1; i<a.size(); ++i) {<BR>
|
||||
a[i] = a[i-1]+1;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// use some common STL container operations</FONT></I><BR>
|
||||
std::cout << "size: " << a.size() << std::endl;<BR>
|
||||
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;<BR>
|
||||
std::cout << "max_size: " << a.max_size() << std::endl;<BR>
|
||||
std::cout << "front: " << a.front() << std::endl;<BR>
|
||||
std::cout << "back: " << a.back() << std::endl;<BR>
|
||||
std::cout << "elems: ";<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// iterate through all elements</FONT></I><BR>
|
||||
for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {<BR>
|
||||
std::cout << *pos << ' ';<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// check copy constructor and assignment operator</FONT></I><BR>
|
||||
Array b(a);<BR>
|
||||
Array c;<BR>
|
||||
c = a;<BR>
|
||||
if (a==b && a==c) {<BR>
|
||||
std::cout << "copy construction and copy assignment are OK"<BR>
|
||||
<< std::endl;<BR>
|
||||
}<BR>
|
||||
else {<BR>
|
||||
std::cout << "copy construction and copy assignment FAILED"<BR>
|
||||
<< std::endl;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
return 0; <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// makes Visual-C++ compiler happy</FONT></I><BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
</SPAN>
|
||||
</TT>
|
||||
</BODY>
|
||||
</HTML>
|
@ -1,5 +1,10 @@
|
||||
/* example for using class array<>
|
||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <boost/array.hpp>
|
||||
|
@ -1,56 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>array2.cpp</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||
|
||||
<TABLE HEIGHT=40 WIDTH="100%">
|
||||
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||
<FONT face="Arial,Helvetica" size=+2><B>
|
||||
array2.cpp
|
||||
</B></FONT>
|
||||
</TD></TR></TABLE><BR>
|
||||
|
||||
<BR><BR>
|
||||
<TT>
|
||||
<SPAN class="Source">
|
||||
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* example for using class array<></FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||
#include <algorithm><BR>
|
||||
#include <functional><BR>
|
||||
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||
#include "<A href="print.hpp.html">print.hpp</A>"<BR>
|
||||
using namespace std;<BR>
|
||||
using namespace boost;<BR>
|
||||
<BR>
|
||||
int main()<BR>
|
||||
{<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create and initialize array</FONT></I><BR>
|
||||
array<int,10> a = { { 1, 2, 3, 4, 5 } };<BR>
|
||||
<BR>
|
||||
print_elements(a);<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// modify elements directly</FONT></I><BR>
|
||||
for (unsigned i=0; i<a.size(); ++i) {<BR>
|
||||
++a[i];<BR>
|
||||
}<BR>
|
||||
print_elements(a);<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// change order using an STL algorithm</FONT></I><BR>
|
||||
reverse(a.begin(),a.end());<BR>
|
||||
print_elements(a);<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// negate elements using STL framework</FONT></I><BR>
|
||||
transform(a.begin(),a.end(), <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// source</FONT></I><BR>
|
||||
a.begin(), <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// destination</FONT></I><BR>
|
||||
negate<int>()); <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// operation</FONT></I><BR>
|
||||
print_elements(a);<BR>
|
||||
<BR>
|
||||
return 0; <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// makes Visual-C++ compiler happy</FONT></I><BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
</SPAN>
|
||||
</TT>
|
||||
</BODY>
|
||||
</HTML>
|
@ -1,5 +1,10 @@
|
||||
/* example for using class array<>
|
||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <boost/array.hpp>
|
||||
@ -17,7 +22,7 @@ int main()
|
||||
// copy and change order
|
||||
boost::array<std::string,4> seasons_orig = seasons;
|
||||
for (unsigned i=seasons.size()-1; i>0; --i) {
|
||||
swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
|
||||
std::swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
|
||||
}
|
||||
|
||||
std::cout << "one way: ";
|
||||
@ -25,7 +30,7 @@ int main()
|
||||
|
||||
// try swap()
|
||||
std::cout << "other way: ";
|
||||
swap(seasons,seasons_orig);
|
||||
std::swap(seasons,seasons_orig);
|
||||
print_elements(seasons);
|
||||
|
||||
// try reverse iterators
|
||||
|
@ -1,71 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>array3.cpp</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||
|
||||
<TABLE HEIGHT=40 WIDTH="100%">
|
||||
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||
<FONT face="Arial,Helvetica" size=+2><B>
|
||||
array3.cpp
|
||||
</B></FONT>
|
||||
</TD></TR></TABLE><BR>
|
||||
|
||||
<BR><BR>
|
||||
<TT>
|
||||
<SPAN class="Source">
|
||||
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* example for using class array<></FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||
#include <string><BR>
|
||||
#include <iostream><BR>
|
||||
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||
<BR>
|
||||
template <class T><BR>
|
||||
void print_elements (const T& x);<BR>
|
||||
<BR>
|
||||
int main()<BR>
|
||||
{<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create array of four seasons</FONT></I><BR>
|
||||
boost::array<std::string,4> seasons = {<BR>
|
||||
{ "spring", "summer", "autumn", "winter" }<BR>
|
||||
};<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// copy and change order</FONT></I><BR>
|
||||
boost::array<std::string,4> seasons_orig = seasons;<BR>
|
||||
for (unsigned i=seasons.size()-1; i>0; --i) {<BR>
|
||||
swap(seasons.at(i),seasons.at((i+1)%seasons.size()));<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
std::cout << "one way: ";<BR>
|
||||
print_elements(seasons);<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// try swap()</FONT></I><BR>
|
||||
std::cout << "other way: ";<BR>
|
||||
swap(seasons,seasons_orig);<BR>
|
||||
print_elements(seasons);<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// try reverse iterators</FONT></I><BR>
|
||||
std::cout << "reverse: ";<BR>
|
||||
for (boost::array<std::string,4>::reverse_iterator pos<BR>
|
||||
=seasons.rbegin(); pos<seasons.rend(); ++pos) {<BR>
|
||||
std::cout << " " << *pos;<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
<BR>
|
||||
return 0; <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// makes Visual-C++ compiler happy</FONT></I><BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
template <class T><BR>
|
||||
void print_elements (const T& x)<BR>
|
||||
{<BR>
|
||||
for (unsigned i=0; i<x.size(); ++i) {<BR>
|
||||
std::cout << " " << x[i];<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
</SPAN>
|
||||
</TT>
|
||||
</BODY>
|
||||
</HTML>
|
@ -1,5 +1,10 @@
|
||||
/* example for using class array<>
|
||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
@ -1,59 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>array4.cpp</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||
|
||||
<TABLE HEIGHT=40 WIDTH="100%">
|
||||
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||
<FONT face="Arial,Helvetica" size=+2><B>
|
||||
array4.cpp
|
||||
</B></FONT>
|
||||
</TD></TR></TABLE><BR>
|
||||
|
||||
<BR><BR>
|
||||
<TT>
|
||||
<SPAN class="Source">
|
||||
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* example for using class array<></FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||
#include <algorithm><BR>
|
||||
#include <functional><BR>
|
||||
#include <string><BR>
|
||||
#include <iostream><BR>
|
||||
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||
<BR>
|
||||
int main()<BR>
|
||||
{<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// array of arrays of seasons</FONT></I><BR>
|
||||
boost::array<boost::array<std::string,4>,2> seasons_i18n = {<BR>
|
||||
{ { { "spring", "summer", "autumn", "winter", } },<BR>
|
||||
{ { "Fruehling", "Sommer", "Herbst", "Winter" } }<BR>
|
||||
}<BR>
|
||||
};<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// for any array of seasons print seasons</FONT></I><BR>
|
||||
for (unsigned i=0; i<seasons_i18n.size(); ++i) {<BR>
|
||||
boost::array<std::string,4> seasons = seasons_i18n[i];<BR>
|
||||
for (unsigned j=0; j<seasons.size(); ++j) {<BR>
|
||||
std::cout << seasons[j] << " ";<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// print first element of first array</FONT></I><BR>
|
||||
std::cout << "first element of first array: "<BR>
|
||||
<< seasons_i18n[0][0] << std::endl;<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// print last element of last array</FONT></I><BR>
|
||||
std::cout << "last element of last array: "<BR>
|
||||
<< seasons_i18n[seasons_i18n.size()-1][seasons_i18n[0].size()-1]<BR>
|
||||
<< std::endl;<BR>
|
||||
<BR>
|
||||
return 0; <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// makes Visual-C++ compiler happy</FONT></I><BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
</SPAN>
|
||||
</TT>
|
||||
</BODY>
|
||||
</HTML>
|
14
array5.cpp
14
array5.cpp
@ -1,5 +1,10 @@
|
||||
/* simple example for using class array<>
|
||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
@ -10,8 +15,8 @@ void test_static_size (const T& cont)
|
||||
for (unsigned i=0; i<T::static_size; ++i) {
|
||||
tmp[i] = int(cont[i]);
|
||||
}
|
||||
for (unsigned i=0; i<T::static_size; ++i) {
|
||||
std::cout << tmp[i] << ' ';
|
||||
for (unsigned j=0; j<T::static_size; ++j) {
|
||||
std::cout << tmp[j] << ' ';
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@ -27,7 +32,8 @@ int main()
|
||||
// use some common STL container operations
|
||||
std::cout << "static_size: " << a.size() << std::endl;
|
||||
std::cout << "size: " << a.size() << std::endl;
|
||||
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;
|
||||
// Can't use std::boolalpha because it isn't portable
|
||||
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;
|
||||
@ -56,7 +62,7 @@ int main()
|
||||
|
||||
typedef boost::array<double,6> DArray;
|
||||
typedef boost::array<int,6> IArray;
|
||||
IArray ia = { 1, 2, 3, 4, 5, 6 };
|
||||
IArray ia = { { 1, 2, 3, 4, 5, 6 } } ; // extra braces silence GCC warning
|
||||
DArray da;
|
||||
da = ia;
|
||||
da.assign(42);
|
||||
|
@ -1,87 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>array5.cpp</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||
|
||||
<TABLE HEIGHT=40 WIDTH="100%">
|
||||
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||
<FONT face="Arial,Helvetica" size=+2><B>
|
||||
array5.cpp
|
||||
</B></FONT>
|
||||
</TD></TR></TABLE><BR>
|
||||
|
||||
<BR><BR>
|
||||
<TT>
|
||||
<SPAN class="Source">
|
||||
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* simple example for using class array<></FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||
#include <iostream><BR>
|
||||
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||
<BR>
|
||||
template <typename T><BR>
|
||||
void test_static_size (const T& cont)<BR>
|
||||
{<BR>
|
||||
int tmp[T::static_size];<BR>
|
||||
for (unsigned i=0; i<T::static_size; ++i) {<BR>
|
||||
tmp[i] = int(cont[i]);<BR>
|
||||
}<BR>
|
||||
for (unsigned i=0; i<T::static_size; ++i) {<BR>
|
||||
std::cout << tmp[i] << ' ';<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
int main()<BR>
|
||||
{<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// define special type name</FONT></I><BR>
|
||||
typedef boost::array<float,6> Array;<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create and initialize an array</FONT></I><BR>
|
||||
const Array a = { { 42.42 } };<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// use some common STL container operations</FONT></I><BR>
|
||||
std::cout << "static_size: " << a.size() << std::endl;<BR>
|
||||
std::cout << "size: " << a.size() << std::endl;<BR>
|
||||
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;<BR>
|
||||
std::cout << "max_size: " << a.max_size() << std::endl;<BR>
|
||||
std::cout << "front: " << a.front() << std::endl;<BR>
|
||||
std::cout << "back: " << a.back() << std::endl;<BR>
|
||||
std::cout << "[0]: " << a[0] << std::endl;<BR>
|
||||
std::cout << "elems: ";<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// iterate through all elements</FONT></I><BR>
|
||||
for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {<BR>
|
||||
std::cout << *pos << ' ';<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
test_static_size(a);<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// check copy constructor and assignment operator</FONT></I><BR>
|
||||
Array b(a);<BR>
|
||||
Array c;<BR>
|
||||
c = a;<BR>
|
||||
if (a==b && a==c) {<BR>
|
||||
std::cout << "copy construction and copy assignment are OK"<BR>
|
||||
<< std::endl;<BR>
|
||||
}<BR>
|
||||
else {<BR>
|
||||
std::cout << "copy construction and copy assignment are BROKEN"<BR>
|
||||
<< std::endl;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
typedef boost::array<double,6> DArray;<BR>
|
||||
typedef boost::array<int,6> IArray;<BR>
|
||||
IArray ia = { 1, 2, 3, 4, 5, 6 };<BR>
|
||||
DArray da;<BR>
|
||||
da = ia;<BR>
|
||||
da.assign(42);<BR>
|
||||
<BR>
|
||||
return 0; <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// makes Visual-C++ compiler happy</FONT></I><BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
</SPAN>
|
||||
</TT>
|
||||
</BODY>
|
||||
</HTML>
|
546
doc/array.xml
Normal file
546
doc/array.xml
Normal file
@ -0,0 +1,546 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
<library name="Array" dirname="array" id="array" last-revision="$Date$">
|
||||
<libraryinfo>
|
||||
<author>
|
||||
<firstname>Nicolai</firstname>
|
||||
<surname>Josuttis</surname>
|
||||
</author>
|
||||
|
||||
<copyright>
|
||||
<year>2001</year>
|
||||
<year>2002</year>
|
||||
<year>2003</year>
|
||||
<year>2004</year>
|
||||
<holder>Nicolai M. Josuttis</holder>
|
||||
</copyright>
|
||||
|
||||
<legalnotice>
|
||||
<para>Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at
|
||||
<ulink
|
||||
url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>)
|
||||
</para>
|
||||
</legalnotice>
|
||||
|
||||
<librarypurpose>STL compliant container wrapper for arrays of constant size</librarypurpose>
|
||||
<librarycategory name="category:containers"/>
|
||||
</libraryinfo>
|
||||
|
||||
<title>Boost.Array</title>
|
||||
|
||||
<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<></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>
|
||||
|
||||
<library-reference>
|
||||
<header name="boost/array.hpp">
|
||||
<namespace name="boost">
|
||||
<class name="array">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<purpose><para>STL compliant container wrapper for arrays of constant size</para></purpose>
|
||||
<typedef name="value_type">
|
||||
<type>T</type>
|
||||
</typedef>
|
||||
<typedef name="iterator">
|
||||
<type>T*</type>
|
||||
</typedef>
|
||||
<typedef name="const_iterator">
|
||||
<type>const T*</type>
|
||||
</typedef>
|
||||
<typedef name="reverse_iterator">
|
||||
<type><classname>std::reverse_iterator</classname><iterator></type>
|
||||
</typedef>
|
||||
<typedef name="const_reverse_iterator">
|
||||
<type><classname>std::reverse_iterator</classname><const_iterator></type>
|
||||
</typedef>
|
||||
<typedef name="reference">
|
||||
<type>T&</type>
|
||||
</typedef>
|
||||
<typedef name="const_reference">
|
||||
<type>const T&</type>
|
||||
</typedef>
|
||||
<typedef name="size_type">
|
||||
<type>std::size_t</type>
|
||||
</typedef>
|
||||
<typedef name="difference_type">
|
||||
<type>std::ptrdiff_t</type>
|
||||
</typedef>
|
||||
|
||||
<static-constant name="static_size">
|
||||
<type>size_type</type>
|
||||
<default>N</default>
|
||||
</static-constant>
|
||||
|
||||
<copy-assignment>
|
||||
<template>
|
||||
<template-type-parameter name="U"/>
|
||||
</template>
|
||||
<parameter name="other">
|
||||
<paramtype>const <classname>array</classname><U, N>&</paramtype>
|
||||
</parameter>
|
||||
<effects><simpara><code>std::copy(rhs.<methodname>begin</methodname>(),rhs.<methodname>end</methodname>(), <methodname>begin</methodname>())</code></simpara></effects>
|
||||
</copy-assignment>
|
||||
|
||||
<method-group name="iterator support">
|
||||
<overloaded-method name="begin">
|
||||
<signature>
|
||||
<type>iterator</type>
|
||||
</signature>
|
||||
<signature cv="const">
|
||||
<type>const_iterator</type>
|
||||
</signature>
|
||||
|
||||
<returns><simpara>iterator for the first element</simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</overloaded-method>
|
||||
|
||||
<overloaded-method name="end">
|
||||
<signature>
|
||||
<type>iterator</type>
|
||||
</signature>
|
||||
<signature cv="const">
|
||||
<type>const_iterator</type>
|
||||
</signature>
|
||||
|
||||
<returns><simpara>iterator for position after the last element</simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</overloaded-method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="reverse iterator support">
|
||||
<overloaded-method name="rbegin">
|
||||
<signature>
|
||||
<type>reverse_iterator</type>
|
||||
</signature>
|
||||
<signature cv="const">
|
||||
<type>const_reverse_iterator</type>
|
||||
</signature>
|
||||
|
||||
<returns><simpara>reverse iterator for the first element of reverse iteration</simpara></returns>
|
||||
</overloaded-method>
|
||||
|
||||
<overloaded-method name="rend">
|
||||
<signature>
|
||||
<type>reverse_iterator</type>
|
||||
</signature>
|
||||
<signature cv="const">
|
||||
<type>const_reverse_iterator</type>
|
||||
</signature>
|
||||
|
||||
<returns><simpara>reverse iterator for position after the last element in reverse iteration</simpara></returns>
|
||||
</overloaded-method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="capacity">
|
||||
<method name="size">
|
||||
<type>size_type</type>
|
||||
<returns><simpara><code>N</code></simpara></returns>
|
||||
</method>
|
||||
<method name="empty">
|
||||
<type>bool</type>
|
||||
<returns><simpara><code>N==0</code></simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</method>
|
||||
<method name="max_size">
|
||||
<type>size_type</type>
|
||||
<returns><simpara><code>N</code></simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="element access">
|
||||
<overloaded-method name="operator[]">
|
||||
<signature>
|
||||
<type>reference</type>
|
||||
<parameter name="i">
|
||||
<paramtype>size_type</paramtype>
|
||||
</parameter>
|
||||
</signature>
|
||||
|
||||
<signature cv="const">
|
||||
<type>const_reference</type>
|
||||
<parameter name="i">
|
||||
<paramtype>size_type</paramtype>
|
||||
</parameter>
|
||||
</signature>
|
||||
|
||||
<requires><simpara><code>i < N</code></simpara></requires>
|
||||
<returns><simpara>element with index <code>i</code></simpara></returns>
|
||||
<throws><simpara>will not throw.</simpara></throws>
|
||||
</overloaded-method>
|
||||
|
||||
<overloaded-method name="at">
|
||||
<signature>
|
||||
<type>reference</type>
|
||||
<parameter name="i">
|
||||
<paramtype>size_type</paramtype>
|
||||
</parameter>
|
||||
</signature>
|
||||
|
||||
<signature cv="const">
|
||||
<type>const_reference</type>
|
||||
<parameter name="i">
|
||||
<paramtype>size_type</paramtype>
|
||||
</parameter>
|
||||
</signature>
|
||||
|
||||
<returns><simpara>element with index <code>i</code></simpara></returns>
|
||||
<throws><simpara><code><classname>std::range_error</classname></code> if <code>i >= N</code></simpara></throws>
|
||||
</overloaded-method>
|
||||
|
||||
<overloaded-method name="front">
|
||||
<signature>
|
||||
<type>reference</type>
|
||||
</signature>
|
||||
<signature cv="const">
|
||||
<type>const_reference</type>
|
||||
</signature>
|
||||
<requires><simpara><code>N > 0</code></simpara></requires>
|
||||
<returns><simpara>the first element</simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</overloaded-method>
|
||||
|
||||
<overloaded-method name="back">
|
||||
<signature>
|
||||
<type>reference</type>
|
||||
</signature>
|
||||
<signature cv="const">
|
||||
<type>const_reference</type>
|
||||
</signature>
|
||||
<requires><simpara><code>N > 0</code></simpara></requires>
|
||||
<returns><simpara>the last element</simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</overloaded-method>
|
||||
|
||||
<method name="data" cv="const">
|
||||
<type>const T*</type>
|
||||
<returns><simpara><code>elems</code></simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</method>
|
||||
|
||||
<method name="c_array">
|
||||
<type>T*</type>
|
||||
<returns><simpara><code>elems</code></simpara></returns>
|
||||
<throws><simpara>will not throw</simpara></throws>
|
||||
</method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="modifiers">
|
||||
<method name="swap">
|
||||
<type>void</type>
|
||||
<parameter name="other">
|
||||
<paramtype><classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<effects><simpara><code>std::swap_ranges(<methodname>begin</methodname>(), <methodname>end</methodname>(), other.<methodname>begin</methodname>())</code></simpara></effects>
|
||||
<complexity><simpara>linear in <code>N</code></simpara></complexity>
|
||||
</method>
|
||||
<method name="assign">
|
||||
<type>void</type>
|
||||
<parameter name="value">
|
||||
<paramtype>const T&</paramtype>
|
||||
</parameter>
|
||||
<effects><simpara><code>std::fill_n(<methodname>begin</methodname>(), N, value)</code></simpara></effects>
|
||||
</method>
|
||||
</method-group>
|
||||
|
||||
<data-member name="elems[N]"> <!-- HACK -->
|
||||
<type>T</type>
|
||||
</data-member>
|
||||
|
||||
<free-function-group name="specialized algorithms">
|
||||
<function name="swap">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<type>void</type>
|
||||
|
||||
<parameter name="x">
|
||||
<paramtype><classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<parameter name="y">
|
||||
<paramtype><classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects><simpara><code>x.<methodname>swap</methodname>(y)</code></simpara></effects>
|
||||
<throws><simpara>will not throw.</simpara></throws>
|
||||
</function>
|
||||
</free-function-group>
|
||||
|
||||
<free-function-group name="comparisons">
|
||||
<function name="operator==">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="x">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<parameter name="y">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<returns><simpara><code>std::equal(x.<methodname>begin</methodname>(), x.<methodname>end</methodname>(), y.<methodname>begin</methodname>())</code></simpara>
|
||||
</returns>
|
||||
</function>
|
||||
|
||||
<function name="operator!=">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="x">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<parameter name="y">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<returns><simpara><code>!(x == y)</code></simpara>
|
||||
</returns>
|
||||
</function>
|
||||
|
||||
<function name="operator<">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="x">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<parameter name="y">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<returns><simpara><code>std::lexicographical_compare(x.<methodname>begin</methodname>(), x.<methodname>end</methodname>(), y.<methodname>begin</methodname>(), y.<methodname>end</methodname>())</code></simpara>
|
||||
</returns>
|
||||
</function>
|
||||
|
||||
<function name="operator>">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="x">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<parameter name="y">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<returns><simpara><code>y < x</code></simpara></returns>
|
||||
</function>
|
||||
|
||||
<function name="operator<=">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="x">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<parameter name="y">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<returns><simpara><code>!(y < x)</code></simpara></returns>
|
||||
</function>
|
||||
|
||||
<function name="operator>=">
|
||||
<template>
|
||||
<template-type-parameter name="T"/>
|
||||
<template-nontype-parameter name="N">
|
||||
<type>std::size_t</type>
|
||||
</template-nontype-parameter>
|
||||
</template>
|
||||
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="x">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
<parameter name="y">
|
||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<returns><simpara><code>!(x < y)</code></simpara></returns>
|
||||
</function>
|
||||
</free-function-group>
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
</library-reference>
|
||||
|
||||
<section id="array.rationale">
|
||||
<title>Design Rationale</title>
|
||||
|
||||
<para>There was an important design tradeoff regarding the
|
||||
constructors: We could implement array as an "aggregate" (see
|
||||
Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would
|
||||
mean:
|
||||
<itemizedlist>
|
||||
<listitem><simpara>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:</simpara>
|
||||
|
||||
<programlisting><classname>boost::array</classname><int,4> a = { { 1, 2, 3 } };</programlisting>
|
||||
|
||||
<simpara>Note that if there are fewer elements in the
|
||||
initializer list, then each remaining element gets
|
||||
default-initialized (thus, it has a defined value).</simpara>
|
||||
</listitem></itemizedlist></para>
|
||||
|
||||
<para>However, this approach has its drawbacks: <emphasis
|
||||
role="bold"> passing no initializer list means that the elements
|
||||
have an indetermined initial value</emphasis>, because the rule says
|
||||
that aggregates may have:
|
||||
<itemizedlist>
|
||||
<listitem><simpara>No user-declared constructors.</simpara></listitem>
|
||||
<listitem><simpara>No private or protected non-static data members.</simpara></listitem>
|
||||
<listitem><simpara>No base classes.</simpara></listitem>
|
||||
<listitem><simpara>No virtual functions.</simpara></listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
|
||||
<para>Nevertheless, The current implementation uses this approach.</para>
|
||||
|
||||
<para>Note that for standard conforming compilers it is possible to
|
||||
use fewer braces (according to 8.5.1 (11) of the Standard). That is,
|
||||
you can initialize an array as follows:</para>
|
||||
|
||||
<programlisting>
|
||||
<classname>boost::array</classname><int,4> a = { 1, 2, 3 };
|
||||
</programlisting>
|
||||
|
||||
<para>I'd appreciate any constructive feedback. <emphasis
|
||||
role="bold">Please note: I don't have time to read all boost
|
||||
mails. Thus, to make sure that feedback arrives to me, please send
|
||||
me a copy of each mail regarding this class.</emphasis></para>
|
||||
|
||||
<para>The code is provided "as is" without expressed or implied
|
||||
warranty.</para>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="array.more.info">
|
||||
<title>For more information...</title>
|
||||
<para>To find more details about using ordinary arrays in C++ and
|
||||
the framework of the STL, see e.g.
|
||||
|
||||
<literallayout>The C++ Standard Library - A Tutorial and Reference
|
||||
by Nicolai M. Josuttis
|
||||
Addison Wesley Longman, 1999
|
||||
ISBN 0-201-37926-0</literallayout>
|
||||
</para>
|
||||
|
||||
<para><ulink url="http://www.josuttis.com/">Home Page of Nicolai
|
||||
Josuttis</ulink></para>
|
||||
</section>
|
||||
|
||||
<section id="array.ack">
|
||||
<title>Acknowledgements</title>
|
||||
|
||||
<para>Doug Gregor ported the documentation to the BoostBook format.</para>
|
||||
</section>
|
||||
|
||||
<!-- Notes:
|
||||
empty() should return N != 0
|
||||
size(), empty(), max_size() should be const
|
||||
-->
|
||||
|
||||
</library>
|
@ -2,30 +2,41 @@
|
||||
* an STL container (as wrapper) for arrays of constant size.
|
||||
*
|
||||
* See
|
||||
* http://www.josuttis.com/cppcode
|
||||
* for details and the latest version.
|
||||
* http://www.boost.org/libs/array/
|
||||
* for documentation.
|
||||
*
|
||||
* The original author site is at: http://www.josuttis.com/
|
||||
*
|
||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
||||
* Permission to copy, use, modify, sell and distribute this software
|
||||
* is granted provided this copyright notice appears in all copies.
|
||||
* This software is provided "as is" without express or implied
|
||||
* warranty, and with no claim as to its suitability for any purpose.
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* 29 Jan 2004 - c_array() added, BOOST_NO_PRIVATE_IN_AGGREGATE removed (Nico Josuttis)
|
||||
* 23 Aug 2002 - fix for Non-MSVC compilers combined with MSVC libraries.
|
||||
* 05 Aug 2001 - minor update (Nico Josuttis)
|
||||
* 20 Jan 2001 - STLport fix (Beman Dawes)
|
||||
* 29 Sep 2000 - Initial Revision (Nico Josuttis)
|
||||
*
|
||||
* Jan 29, 2004
|
||||
*/
|
||||
#ifndef BOOST_ARRAY_HPP
|
||||
#define BOOST_ARRAY_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <iterator>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
// Handles broken standard libraries better than <iterator>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
// FIXES for broken compilers
|
||||
#include <boost/config.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T, std::size_t N>
|
||||
@ -42,7 +53,7 @@ namespace boost {
|
||||
typedef const T& const_reference;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
|
||||
// iterator support
|
||||
iterator begin() { return elems; }
|
||||
const_iterator begin() const { return elems; }
|
||||
@ -50,9 +61,15 @@ namespace boost {
|
||||
const_iterator end() const { return elems+N; }
|
||||
|
||||
// reverse iterator support
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
#elif defined(_MSC_VER) && (_MSC_VER == 1300) && defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB == 310)
|
||||
// workaround for broken reverse_iterator in VC7
|
||||
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, iterator,
|
||||
reference, iterator, reference> > reverse_iterator;
|
||||
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
|
||||
const_reference, iterator, reference> > const_reverse_iterator;
|
||||
#else
|
||||
// workaround for broken reverse_iterator implementations
|
||||
typedef std::reverse_iterator<iterator,T> reverse_iterator;
|
||||
@ -69,18 +86,42 @@ namespace boost {
|
||||
}
|
||||
|
||||
// operator[]
|
||||
reference operator[](size_type i) { return elems[i]; }
|
||||
const_reference operator[](size_type i) const { return elems[i]; }
|
||||
reference operator[](size_type i)
|
||||
{
|
||||
BOOST_ASSERT( i < N && "out of range" );
|
||||
return elems[i];
|
||||
}
|
||||
|
||||
const_reference operator[](size_type i) const
|
||||
{
|
||||
BOOST_ASSERT( i < N && "out of range" );
|
||||
return elems[i];
|
||||
}
|
||||
|
||||
// at() with range check
|
||||
reference at(size_type i) { rangecheck(i); return elems[i]; }
|
||||
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }
|
||||
|
||||
// front() and back()
|
||||
reference front() { return elems[0]; }
|
||||
const_reference front() const { return elems[0]; }
|
||||
reference back() { return elems[N-1]; }
|
||||
const_reference back() const { return elems[N-1]; }
|
||||
reference front()
|
||||
{
|
||||
return elems[0];
|
||||
}
|
||||
|
||||
const_reference front() const
|
||||
{
|
||||
return elems[0];
|
||||
}
|
||||
|
||||
reference back()
|
||||
{
|
||||
return elems[N-1];
|
||||
}
|
||||
|
||||
const_reference back() const
|
||||
{
|
||||
return elems[N-1];
|
||||
}
|
||||
|
||||
// size is constant
|
||||
static size_type size() { return N; }
|
||||
@ -93,8 +134,12 @@ namespace boost {
|
||||
std::swap_ranges(begin(),end(),y.begin());
|
||||
}
|
||||
|
||||
// direct access to data
|
||||
// direct access to data (read-only)
|
||||
const T* data() const { return elems; }
|
||||
T* data() { return elems; }
|
||||
|
||||
// use array as C array (direct read/write access to data)
|
||||
T* c_array() { return elems; }
|
||||
|
||||
// assignment with type conversion
|
||||
template <typename T2>
|
||||
@ -109,16 +154,136 @@ 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"); }
|
||||
if (i >= size()) {
|
||||
throw std::out_of_range("array<>: index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
template< class T >
|
||||
class array< T, 0 > {
|
||||
|
||||
public:
|
||||
// type definitions
|
||||
typedef T value_type;
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
// iterator support
|
||||
iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); }
|
||||
const_iterator begin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
|
||||
iterator end() { return begin(); }
|
||||
const_iterator end() const { return begin(); }
|
||||
|
||||
// reverse iterator support
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
#elif defined(_MSC_VER) && (_MSC_VER == 1300) && defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB == 310)
|
||||
// workaround for broken reverse_iterator in VC7
|
||||
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, iterator,
|
||||
reference, iterator, reference> > reverse_iterator;
|
||||
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
|
||||
const_reference, iterator, reference> > const_reverse_iterator;
|
||||
#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
|
||||
|
||||
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
||||
const_reverse_iterator rbegin() const {
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
reverse_iterator rend() { return reverse_iterator(begin()); }
|
||||
const_reverse_iterator rend() const {
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
// operator[]
|
||||
reference operator[](size_type i)
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
const_reference operator[](size_type i) const
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
// at() with range check
|
||||
reference at(size_type i) { return failed_rangecheck(); }
|
||||
const_reference at(size_type i) const { return failed_rangecheck(); }
|
||||
|
||||
// front() and back()
|
||||
reference front()
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
const_reference front() const
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
reference back()
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
const_reference back() const
|
||||
{
|
||||
return failed_rangecheck();
|
||||
}
|
||||
|
||||
// size is constant
|
||||
static size_type size() { return 0; }
|
||||
static bool empty() { return true; }
|
||||
static size_type max_size() { return 0; }
|
||||
enum { static_size = 0 };
|
||||
|
||||
void swap (array<T,0>& y) {
|
||||
}
|
||||
|
||||
// direct access to data (read-only)
|
||||
const T* data() const { return 0; }
|
||||
T* data() { return 0; }
|
||||
|
||||
// use array as C array (direct read/write access to data)
|
||||
T* c_array() { return 0; }
|
||||
|
||||
// assignment with type conversion
|
||||
template <typename T2>
|
||||
array<T,0>& operator= (const array<T2,0>& ) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// assign one value to all elements
|
||||
void assign (const T& ) { }
|
||||
|
||||
// check range (may be private because it is static)
|
||||
static reference failed_rangecheck () {
|
||||
std::out_of_range e("attempt to access element of an empty array");
|
||||
boost::throw_exception(e);
|
||||
//
|
||||
// We need to return something here to keep
|
||||
// some compilers happy: however we will never
|
||||
// actually get here....
|
||||
//
|
||||
static T placeholder;
|
||||
return placeholder;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
// comparisons
|
||||
template<class T, std::size_t N>
|
||||
bool operator== (const array<T,N>& x, const array<T,N>& y) {
|
||||
|
35
index.htm
35
index.htm
@ -1,35 +0,0 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Array Wrapper Libary</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<table border="1" bgcolor="#007F7F" cellpadding="2">
|
||||
<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/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>
|
||||
</table>
|
||||
<h1>Array wrapper library</h1>
|
||||
<p>The header array.hpp provides an STL compliant container wrapper for arrays
|
||||
of constant size.
|
||||
<ul>
|
||||
<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>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 -->14 Mar 2001<!--webbot bot="Timestamp" endspan i-checksum="14885" --></p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
13
index.html
Normal file
13
index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=../../doc/html/array.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../../doc/html/array.html">../../doc/html/array.html</a> <hr>
|
||||
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
</body>
|
||||
</html>
|
@ -3,10 +3,9 @@
|
||||
* by Nicolai M. Josuttis, Addison-Wesley, 1999
|
||||
*
|
||||
* (C) Copyright Nicolai M. Josuttis 1999.
|
||||
* Permission to copy, use, modify, sell and distribute this software
|
||||
* is granted provided this copyright notice appears in all copies.
|
||||
* This software is provided "as is" without express or implied
|
||||
* warranty, and with no claim as to its suitability for any purpose.
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <iostream>
|
||||
|
||||
|
@ -1,48 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>PRINT_ELEMENTS()</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||
|
||||
<TABLE HEIGHT=40 WIDTH="100%">
|
||||
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||
<FONT face="Arial,Helvetica" size=+2><B>
|
||||
PRINT_ELEMENTS()
|
||||
</B></FONT>
|
||||
</TD></TR></TABLE><BR>
|
||||
|
||||
<FONT face="Arial,Helvetica"><B>
|
||||
The following code example is taken from the book<BR>
|
||||
<A HREF="http://www.josuttis.com/libbook/" TARGET="_top">
|
||||
The C++ Standard Library - A Tutorial and Reference</A><BR>
|
||||
by Nicolai M. Josuttis, Addison-Wesley, 1999<BR>
|
||||
<A HREF="http://www.josuttis.com/libbook/copyright.html">
|
||||
© Copyright</A> Nicolai M. Josuttis 1999<BR>
|
||||
</B></FONT>
|
||||
|
||||
<BR><BR>
|
||||
<TT>
|
||||
<SPAN class="Source">
|
||||
#include <iostream><BR>
|
||||
<BR>
|
||||
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* print_elements()</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* - prints optional C-string optcstr followed by</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* - all elements of the collection coll</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* - separated by spaces</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||
template <class T><BR>
|
||||
inline void print_elements (const T& coll, const char* optcstr="")<BR>
|
||||
{<BR>
|
||||
typename T::const_iterator pos;<BR>
|
||||
<BR>
|
||||
std::cout << optcstr;<BR>
|
||||
for (pos=coll.begin(); pos!=coll.end(); ++pos) {<BR>
|
||||
std::cout << *pos << ' ';<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
}<BR>
|
||||
</SPAN>
|
||||
</TT>
|
||||
</BODY>
|
||||
</HTML>
|
Reference in New Issue
Block a user