Compare commits

...

1 Commits

Author SHA1 Message Date
2a876cf76e This commit was manufactured by cvs2svn to create branch
'boost-graph-library'.

[SVN r7698]
2000-09-09 10:20:25 +00:00
16 changed files with 1306 additions and 132 deletions

169
array.hpp.html Normal file
View File

@ -0,0 +1,169 @@
<HTML>
<HEAD>
<TITLE>array.hpp</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
&nbsp;
<TABLE HEIGHT=40 WIDTH="100%">
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
<FONT face="Arial,Helvetica" size=+2><B>
&nbsp;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" >*&nbsp;The&nbsp;following&nbsp;code&nbsp;declares&nbsp;class&nbsp;array,</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;an&nbsp;STL&nbsp;container&nbsp;(as&nbsp;wrapper)&nbsp;for&nbsp;arrays&nbsp;of&nbsp;constant&nbsp;size.</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;See</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://www.josuttis.com/cppcode</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;for&nbsp;details&nbsp;and&nbsp;the&nbsp;latest&nbsp;version.</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;(C)&nbsp;Copyright&nbsp;Nicolai&nbsp;M.&nbsp;Josuttis&nbsp;1999.</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;Permission&nbsp;to&nbsp;copy,&nbsp;use,&nbsp;modify,&nbsp;sell&nbsp;and&nbsp;distribute&nbsp;this&nbsp;software</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;is&nbsp;granted&nbsp;provided&nbsp;this&nbsp;copyright&nbsp;notice&nbsp;appears&nbsp;in&nbsp;all&nbsp;copies.</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;This&nbsp;software&nbsp;is&nbsp;provided&nbsp;"as&nbsp;is"&nbsp;without&nbsp;express&nbsp;or&nbsp;implied</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;warranty,&nbsp;and&nbsp;with&nbsp;no&nbsp;claim&nbsp;as&nbsp;to&nbsp;its&nbsp;suitability&nbsp;for&nbsp;any&nbsp;purpose.</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;Jul&nbsp;31,&nbsp;2000</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
#ifndef&nbsp;BOOST_ARRAY_HPP<BR>
#define&nbsp;BOOST_ARRAY_HPP<BR>
<BR>
#include&nbsp;&lt;cstddef&gt;<BR>
#include&nbsp;&lt;stdexcept&gt;<BR>
#include&nbsp;&lt;iterator&gt;<BR>
#include&nbsp;&lt;algorithm&gt;<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;BUG-FIX&nbsp;for&nbsp;compilers&nbsp;that&nbsp;don't&nbsp;support</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;std::size_t&nbsp;and&nbsp;std::ptrdiff_t&nbsp;yet</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;(such&nbsp;as&nbsp;gcc)</FONT></I><BR>
#include&nbsp;&lt;<A href="./config.hpp.html">boost/config.hpp</A>&gt;<BR>
<BR>
namespace&nbsp;boost&nbsp;{<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;template&lt;class&nbsp;T,&nbsp;std::size_t&nbsp;N&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;class&nbsp;array&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T&nbsp;elems[N];&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;fixed-size&nbsp;array&nbsp;of&nbsp;elements&nbsp;of&nbsp;type&nbsp;T</FONT></I><BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;type&nbsp;definitions</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;T&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value_type;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;T*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iterator;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;const&nbsp;T*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_iterator;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;T&&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reference;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;const&nbsp;T&&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_reference;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;std::size_t&nbsp;&nbsp;&nbsp;&nbsp;size_type;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;std::ptrdiff_t&nbsp;difference_type;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;iterator&nbsp;support</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iterator&nbsp;begin()&nbsp;{&nbsp;return&nbsp;elems;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_iterator&nbsp;begin()&nbsp;const&nbsp;{&nbsp;return&nbsp;elems;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iterator&nbsp;end()&nbsp;{&nbsp;return&nbsp;elems+N;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_iterator&nbsp;end()&nbsp;const&nbsp;{&nbsp;return&nbsp;elems+N;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;reverse&nbsp;iterator&nbsp;support</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;std::reverse_iterator&lt;iterator&gt;&nbsp;reverse_iterator;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;std::reverse_iterator&lt;const_iterator&gt;&nbsp;const_reverse_iterator;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverse_iterator&nbsp;rbegin()&nbsp;{&nbsp;return&nbsp;reverse_iterator(end());&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_reverse_iterator&nbsp;rbegin()&nbsp;const&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;const_reverse_iterator(end());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverse_iterator&nbsp;rend()&nbsp;{&nbsp;return&nbsp;reverse_iterator(begin());&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_reverse_iterator&nbsp;rend()&nbsp;const&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;const_reverse_iterator(begin());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;operator[]</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reference&nbsp;operator[](size_type&nbsp;i)&nbsp;{&nbsp;return&nbsp;elems[i];&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_reference&nbsp;operator[](size_type&nbsp;i)&nbsp;const&nbsp;{&nbsp;return&nbsp;elems[i];&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;at()&nbsp;with&nbsp;range&nbsp;check</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reference&nbsp;at(size_type&nbsp;i)&nbsp;{&nbsp;rangecheck(i);&nbsp;return&nbsp;elems[i];&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_reference&nbsp;at(size_type&nbsp;i)&nbsp;const&nbsp;{&nbsp;rangecheck(i);&nbsp;return&nbsp;elems[i];&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;front()&nbsp;and&nbsp;back()</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reference&nbsp;front()&nbsp;{&nbsp;return&nbsp;elems[0];&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_reference&nbsp;front()&nbsp;const&nbsp;{&nbsp;return&nbsp;elems[0];&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reference&nbsp;back()&nbsp;{&nbsp;return&nbsp;elems[N-1];&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const_reference&nbsp;back()&nbsp;const&nbsp;{&nbsp;return&nbsp;elems[N-1];&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;size&nbsp;is&nbsp;constant</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;size_type&nbsp;size()&nbsp;{&nbsp;return&nbsp;N;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;bool&nbsp;empty()&nbsp;{&nbsp;return&nbsp;false;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;size_type&nbsp;max_size()&nbsp;{&nbsp;return&nbsp;N;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enum&nbsp;{&nbsp;static_size&nbsp;=&nbsp;N&nbsp;};<BR>
<BR>
&nbsp;&nbsp;public:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;swap&nbsp;(note:&nbsp;linear&nbsp;complexity)</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;swap&nbsp;(array&lt;T,N&gt;&&nbsp;y)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::swap_ranges(begin(),end(),y.begin());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;direct&nbsp;access&nbsp;to&nbsp;data</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;T*&nbsp;data()&nbsp;const&nbsp;{&nbsp;return&nbsp;elems;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;assignment&nbsp;with&nbsp;type&nbsp;conversion</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;template&nbsp;&lt;typename&nbsp;T2&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array&lt;T,N&gt;&&nbsp;operator=&nbsp;(const&nbsp;array&lt;T2,N&gt;&&nbsp;rhs)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::copy(rhs.begin(),rhs.end(),&nbsp;begin());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;*this;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;assign&nbsp;one&nbsp;value&nbsp;to&nbsp;all&nbsp;elements</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;assign&nbsp;(const&nbsp;T&&nbsp;value)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::fill_n(begin(),size(),value);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;check&nbsp;range&nbsp;(may&nbsp;be&nbsp;private&nbsp;because&nbsp;it&nbsp;is&nbsp;static)</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;rangecheck&nbsp;(size_type&nbsp;i)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(i&nbsp;&gt;=&nbsp;size())&nbsp;{&nbsp;throw&nbsp;std::range_error("array");&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;};<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;comparisons</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;template&lt;class&nbsp;T,&nbsp;std::size_t&nbsp;N&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;operator==&nbsp;(const&nbsp;array&lt;T,N&gt;&&nbsp;x,&nbsp;const&nbsp;array&lt;T,N&gt;&&nbsp;y)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;std::equal(x.begin(),&nbsp;x.end(),&nbsp;y.begin());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;template&lt;class&nbsp;T,&nbsp;std::size_t&nbsp;N&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;operator&lt;&nbsp;(const&nbsp;array&lt;T,N&gt;&&nbsp;x,&nbsp;const&nbsp;array&lt;T,N&gt;&&nbsp;y)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;template&lt;class&nbsp;T,&nbsp;std::size_t&nbsp;N&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;operator!=&nbsp;(const&nbsp;array&lt;T,N&gt;&&nbsp;x,&nbsp;const&nbsp;array&lt;T,N&gt;&&nbsp;y)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;!(x==y);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;template&lt;class&nbsp;T,&nbsp;std::size_t&nbsp;N&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;operator&gt;&nbsp;(const&nbsp;array&lt;T,N&gt;&&nbsp;x,&nbsp;const&nbsp;array&lt;T,N&gt;&&nbsp;y)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;y&lt;x;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;template&lt;class&nbsp;T,&nbsp;std::size_t&nbsp;N&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;operator&lt;=&nbsp;(const&nbsp;array&lt;T,N&gt;&&nbsp;x,&nbsp;const&nbsp;array&lt;T,N&gt;&&nbsp;y)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;!(y&lt;x);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;template&lt;class&nbsp;T,&nbsp;std::size_t&nbsp;N&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;operator&gt;=&nbsp;(const&nbsp;array&lt;T,N&gt;&&nbsp;x,&nbsp;const&nbsp;array&lt;T,N&gt;&&nbsp;y)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;!(x&lt;y);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;global&nbsp;swap()</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;template&lt;class&nbsp;T,&nbsp;std::size_t&nbsp;N&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;inline&nbsp;void&nbsp;swap&nbsp;(array&lt;T,N&gt;&&nbsp;x,&nbsp;array&lt;T,N&gt;&&nbsp;y)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.swap(y);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
}&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >/*&nbsp;namespace&nbsp;boost&nbsp;*/</FONT></I><BR>
<BR>
#endif&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >/*BOOST_ARRAY_HPP*/</FONT></I><BR>
</SPAN>
</TT>
</BODY>
</HTML>

320
array.html Normal file
View File

@ -0,0 +1,320 @@
<!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">&nbsp; </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 face="Arial, Helvetica, sans-serif" size="-1">The C++ Standard Template
Library STL as part of the C++ Standard Library provides a framework for processing
algorithms on different kind of containers. However, ordinary arrays don't provide
the interface of STL containers (although, they provide the iterator interface
of STL containers).</font>
<p><font face="Arial, Helvetica, sans-serif" size="-1">As replacement for ordinary
arrays, the STL provides class <font face="Courier New, Courier, mono">vector&lt;&gt;</font>.
However, <font face="Courier New, Courier, mono">vector&lt;&gt;</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">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&lt;<i>type</i>,<i>num</i>&gt;</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&lt;<i>type</i>,<i>num</i>&gt;(<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 posistion behind last element of reverese iteration </font></td>
</tr>
<tr>
<td><font face="Courier New, Courier, mono" size="-1">operator[<i>i</i>]</font></td>
<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">&lt;<font face="Arial, Helvetica, sans-serif">,
</font>&lt;=<font face="Arial, Helvetica, sans-serif">, </font>&gt;<font face="Arial, Helvetica, sans-serif">,
</font>&gt;=</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>&nbsp;</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">Class array fulfills most
but not all of the requirements of &quot;reversible containers&quot; (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>
<p><font face="Arial, Helvetica, sans-serif" size="-1">It doesn't fulfill the
requirements of a &quot;sequence&quot; (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 &quot;<b>aggregate</b>&quot;
(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&lt;int,4&gt;
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
useus this approach. However, being able to have indetermined initial values
is a big drawback. So, please give me some feedback, how useful you consider
this feature to be. This leads to the list of <b>Open issues:</b></font>
<ul>
<li><font face="Arial, Helvetica, sans-serif">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&lt;int,5&gt; x(data); <font face="Arial, Helvetica, sans-serif">or
</font>&nbsp;&nbsp;array&lt;int,data&gt; x;</font></p>
</blockquote>
</li>
<li><font face="Arial, Helvetica, sans-serif">Could &quot;<font face="Courier New, Courier, mono">{
</font>...<font face="Courier New, Courier, mono"> }</font>&quot; be used
portably instead of &quot;<font face="Courier New, Courier, mono">{ { </font>...<font face="Courier New, Courier, mono">
} }</font>&quot; 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>
<li><font face="Arial, Helvetica, sans-serif">Any way to have determined initial
values and initializer list support?</font></li>
<li><font face="Arial, Helvetica, sans-serif">Static_casts for reverse iterator
stuff</font><font face="Arial, Helvetica, sans-serif">?</font></li>
</ul>
<p><font face="Arial, Helvetica, sans-serif">I'd appreciate any constructive <a href="mailto:solutions@josuttis.com">feedback</a>.
<b>Please note: I don't have time to read all boost mails. Thus, to make sure
that feedback arrives me, please send me a copy of each mail regarding this
class.</b></font>
<p><font face="Arial, Helvetica, sans-serif">The code is provided "as is" without
expressed or implied warranty.</font>
<p><font face="Arial, Helvetica, sans-serif"><b>array.hpp</b>, the implementation
of <font face="Courier New, Courier, mono">array&lt;&gt;</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>
<p> <font face="Arial, Helvetica, sans-serif">Simple Example for using <font face="Courier New, Courier, mono">array&lt;&gt;<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">Another Example for using <font face="Courier New, Courier, mono">array&lt;&gt;<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">A third Example for using <font face="Courier New, Courier, mono">array&lt;&gt;<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">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">An Example for testing other operations
of <font face="Courier New, Courier, mono">array&lt;&gt;</font><font face="Courier New, Courier, mono"><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>
<p><b><font face="Arial, Helvetica, sans-serif">All files</font></b>
<li><font face="Arial, Helvetica, sans-serif"> <a href="array.zip">as ZIP file
(24KB)</a></font></li>
<li><font face="Arial, Helvetica, sans-serif"> <a href="array.tgz">as TGZ file
(13KB)</a><br>
<br>
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>&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.josuttis.com/libbook/">The C++
Standard Library - A Tutorial and Reference</a></i> <br>
&nbsp;&nbsp;&nbsp;&nbsp; by <a href="http://www.josuttis.com" target="_top">Nicolai
M. Josuttis</a></font> <font face="Arial, Helvetica, sans-serif"><br>
&nbsp;&nbsp;&nbsp;&nbsp; Addison Wesley Longman, 1999</font> <font face="Arial, Helvetica, sans-serif"><br>
&nbsp;&nbsp;&nbsp;&nbsp; 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>
&nbsp; </font>
</body>
</html>

46
array1.cpp Normal file
View File

@ -0,0 +1,46 @@
/* simple example for using class array<>
*/
#include <iostream>
#include <boost/array.hpp>
int main()
{
// define special type name
typedef boost::array<float,6> Array;
// create and initialize an array
Array a = { { 42 } };
// access elements
for (unsigned i=1; i<a.size(); ++i) {
a[i] = a[i-1]+1;
}
// use some common STL container operations
std::cout << "size: " << a.size() << std::endl;
std::cout << "empty: " << std::boolalpha << a.empty() << 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;
std::cout << "elems: ";
// iterate through all elements
for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {
std::cout << *pos << ' ';
}
std::cout << std::endl;
// check copy constructor and assignment operator
Array b(a);
Array c;
c = a;
if (a==b && a==c) {
std::cout << "copy construction and copy assignment are OK"
<< std::endl;
}
else {
std::cout << "copy construction and copy assignment are OK"
<< std::endl;
}
}

67
array1.cpp.html Normal file
View File

@ -0,0 +1,67 @@
<HTML>
<HEAD>
<TITLE>array1.cpp</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
&nbsp;
<TABLE HEIGHT=40 WIDTH="100%">
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
<FONT face="Arial,Helvetica" size=+2><B>
&nbsp;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" >*&nbsp;simple&nbsp;example&nbsp;for&nbsp;using&nbsp;class&nbsp;array&lt;&gt;</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
#include&nbsp;&lt;iostream&gt;<BR>
#include&nbsp;&lt;<A href="./array.hpp.html">boost/array.hpp</A>&gt;<BR>
<BR>
int&nbsp;main()<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;define&nbsp;special&nbsp;type&nbsp;name</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;boost::array&lt;float,6&gt;&nbsp;Array;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;create&nbsp;and&nbsp;initialize&nbsp;an&nbsp;array</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;Array&nbsp;a&nbsp;=&nbsp;{&nbsp;{&nbsp;42&nbsp;}&nbsp;};<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;access&nbsp;elements</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(unsigned&nbsp;i=1;&nbsp;i&lt;a.size();&nbsp;++i)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]&nbsp;=&nbsp;a[i-1]+1;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;use&nbsp;some&nbsp;common&nbsp;STL&nbsp;container&nbsp;operations</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"size:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;a.size()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"empty:&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;std::boolalpha&nbsp;&lt;&lt;&nbsp;a.empty()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"max_size:&nbsp;"&nbsp;&lt;&lt;&nbsp;a.max_size()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"front:&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;a.front()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"back:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;a.back()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"elems:&nbsp;&nbsp;&nbsp;&nbsp;";<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;iterate&nbsp;through&nbsp;all&nbsp;elements</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(Array::const_iterator&nbsp;pos=a.begin();&nbsp;pos&lt;a.end();&nbsp;++pos)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;*pos&nbsp;&lt;&lt;&nbsp;'&nbsp;';<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;check&nbsp;copy&nbsp;constructor&nbsp;and&nbsp;assignment&nbsp;operator</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;Array&nbsp;b(a);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;Array&nbsp;c;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;=&nbsp;a;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(a==b&nbsp;&&&nbsp;a==c)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"copy&nbsp;construction&nbsp;and&nbsp;copy&nbsp;assignment&nbsp;are&nbsp;OK"<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"copy&nbsp;construction&nbsp;and&nbsp;copy&nbsp;assignment&nbsp;are&nbsp;OK"<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
}<BR>
<BR>
</SPAN>
</TT>
</BODY>
</HTML>

33
array2.cpp Normal file
View File

@ -0,0 +1,33 @@
/* example for using class array<>
*/
#include <algorithm>
#include <functional>
#include <boost/array.hpp>
#include "print.hpp"
using namespace std;
using namespace boost;
int main()
{
// create and initialize array
array<int,10> a = { { 1, 2, 3, 4, 5 } };
PRINT_ELEMENTS(a);
// modify elements directly
for (unsigned i=0; i<a.size(); ++i) {
++a[i];
}
PRINT_ELEMENTS(a);
// change order using an STL algorithm
reverse(a.begin(),a.end());
PRINT_ELEMENTS(a);
// negate elements using STL framework
transform(a.begin(),a.end(), // source
a.begin(), // destination
negate<int>()); // operation
PRINT_ELEMENTS(a);
}

54
array2.cpp.html Normal file
View File

@ -0,0 +1,54 @@
<HTML>
<HEAD>
<TITLE>array2.cpp</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
&nbsp;
<TABLE HEIGHT=40 WIDTH="100%">
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
<FONT face="Arial,Helvetica" size=+2><B>
&nbsp;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" >*&nbsp;example&nbsp;for&nbsp;using&nbsp;class&nbsp;array&lt;&gt;</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
#include&nbsp;&lt;algorithm&gt;<BR>
#include&nbsp;&lt;functional&gt;<BR>
#include&nbsp;&lt;<A href="./array.hpp.html">boost/array.hpp</A>&gt;<BR>
#include&nbsp;"<A href="print.hpp.html">print.hpp</A>"<BR>
using&nbsp;namespace&nbsp;std;<BR>
using&nbsp;namespace&nbsp;boost;<BR>
<BR>
int&nbsp;main()<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;create&nbsp;and&nbsp;initialize&nbsp;array</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;array&lt;int,10&gt;&nbsp;a&nbsp;=&nbsp;{&nbsp;{&nbsp;1,&nbsp;2,&nbsp;3,&nbsp;4,&nbsp;5&nbsp;}&nbsp;};<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;PRINT_ELEMENTS(a);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;modify&nbsp;elements&nbsp;directly</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(unsigned&nbsp;i=0;&nbsp;i&lt;a.size();&nbsp;++i)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;++a[i];<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;PRINT_ELEMENTS(a);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;change&nbsp;order&nbsp;using&nbsp;an&nbsp;STL&nbsp;algorithm</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;reverse(a.begin(),a.end());<BR>
&nbsp;&nbsp;&nbsp;&nbsp;PRINT_ELEMENTS(a);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;negate&nbsp;elements&nbsp;using&nbsp;STL&nbsp;framework</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;transform(a.begin(),a.end(),&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;source</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a.begin(),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;destination</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;negate&lt;int&gt;());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;operation</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;PRINT_ELEMENTS(a);<BR>
}<BR>
<BR>
</SPAN>
</TT>
</BODY>
</HTML>

48
array3.cpp Normal file
View File

@ -0,0 +1,48 @@
/* example for using class array<>
*/
#include <string>
#include <iostream>
#include <boost/array.hpp>
template <class T>
void print_elements (const T& x);
int main()
{
// create array of four seasons
boost::array<std::string,4> seasons = {
{ "spring", "summer", "autumn", "winter" }
};
// 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::cout << "one way: ";
print_elements(seasons);
// try swap()
std::cout << "other way: ";
swap(seasons,seasons_orig);
print_elements(seasons);
// try reverse iterators
std::cout << "reverse: ";
for (boost::array<std::string,4>::reverse_iterator pos
=seasons.rbegin(); pos<seasons.rend(); ++pos) {
std::cout << " " << *pos;
}
std::cout << std::endl;
}
template <class T>
void print_elements (const T& x)
{
for (unsigned i=0; i<x.size(); ++i) {
std::cout << " " << x[i];
}
std::cout << std::endl;
}

69
array3.cpp.html Normal file
View File

@ -0,0 +1,69 @@
<HTML>
<HEAD>
<TITLE>array3.cpp</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
&nbsp;
<TABLE HEIGHT=40 WIDTH="100%">
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
<FONT face="Arial,Helvetica" size=+2><B>
&nbsp;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" >*&nbsp;example&nbsp;for&nbsp;using&nbsp;class&nbsp;array&lt;&gt;</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
#include&nbsp;&lt;string&gt;<BR>
#include&nbsp;&lt;iostream&gt;<BR>
#include&nbsp;&lt;<A href="./array.hpp.html">boost/array.hpp</A>&gt;<BR>
<BR>
template&nbsp;&lt;class&nbsp;T&gt;<BR>
void&nbsp;print_elements&nbsp;(const&nbsp;T&&nbsp;x);<BR>
<BR>
int&nbsp;main()<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;create&nbsp;array&nbsp;of&nbsp;four&nbsp;seasons</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;boost::array&lt;std::string,4&gt;&nbsp;seasons&nbsp;=&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"spring",&nbsp;"summer",&nbsp;"autumn",&nbsp;"winter"&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;};<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;copy&nbsp;and&nbsp;change&nbsp;order</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;boost::array&lt;std::string,4&gt;&nbsp;seasons_orig&nbsp;=&nbsp;seasons;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(unsigned&nbsp;i=seasons.size()-1;&nbsp;i&gt;0;&nbsp;--i)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(seasons.at(i),seasons.at((i+1)%seasons.size()));<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"one&nbsp;way:&nbsp;&nbsp;&nbsp;";<BR>
&nbsp;&nbsp;&nbsp;&nbsp;print_elements(seasons);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;try&nbsp;swap()</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"other&nbsp;way:&nbsp;";<BR>
&nbsp;&nbsp;&nbsp;&nbsp;swap(seasons,seasons_orig);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;print_elements(seasons);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;try&nbsp;reverse&nbsp;iterators</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"reverse:&nbsp;&nbsp;&nbsp;";<BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(boost::array&lt;std::string,4&gt;::reverse_iterator&nbsp;pos<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=seasons.rbegin();&nbsp;pos&lt;seasons.rend();&nbsp;++pos)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"&nbsp;"&nbsp;&lt;&lt;&nbsp;*pos;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
}<BR>
<BR>
template&nbsp;&lt;class&nbsp;T&gt;<BR>
void&nbsp;print_elements&nbsp;(const&nbsp;T&&nbsp;x)<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(unsigned&nbsp;i=0;&nbsp;i&lt;x.size();&nbsp;++i)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"&nbsp;"&nbsp;&lt;&lt;&nbsp;x[i];<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
}<BR>
<BR>
</SPAN>
</TT>
</BODY>
</HTML>

36
array4.cpp Normal file
View File

@ -0,0 +1,36 @@
/* example for using class array<>
*/
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <boost/array.hpp>
int main()
{
// array of arrays of seasons
boost::array<boost::array<std::string,4>,2> seasons_i18n = {
{ { { "spring", "summer", "autumn", "winter", } },
{ { "Fruehling", "Sommer", "Herbst", "Winter" } }
}
};
// for any array of seasons print seasons
for (unsigned i=0; i<seasons_i18n.size(); ++i) {
boost::array<std::string,4> seasons = seasons_i18n[i];
for (unsigned j=0; j<seasons.size(); ++j) {
std::cout << seasons[j] << " ";
}
std::cout << std::endl;
}
// print first element of first array
std::cout << "first element of first array: "
<< seasons_i18n[0][0] << std::endl;
// print last element of last array
std::cout << "last element of last array: "
<< seasons_i18n[seasons_i18n.size()-1][seasons_i18n[0].size()-1]
<< std::endl;
}

57
array4.cpp.html Normal file
View File

@ -0,0 +1,57 @@
<HTML>
<HEAD>
<TITLE>array4.cpp</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
&nbsp;
<TABLE HEIGHT=40 WIDTH="100%">
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
<FONT face="Arial,Helvetica" size=+2><B>
&nbsp;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" >*&nbsp;example&nbsp;for&nbsp;using&nbsp;class&nbsp;array&lt;&gt;</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
#include&nbsp;&lt;algorithm&gt;<BR>
#include&nbsp;&lt;functional&gt;<BR>
#include&nbsp;&lt;string&gt;<BR>
#include&nbsp;&lt;iostream&gt;<BR>
#include&nbsp;&lt;<A href="./array.hpp.html">boost/array.hpp</A>&gt;<BR>
<BR>
int&nbsp;main()<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;array&nbsp;of&nbsp;arrays&nbsp;of&nbsp;seasons</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;boost::array&lt;boost::array&lt;std::string,4&gt;,2&gt;&nbsp;seasons_i18n&nbsp;=&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;{&nbsp;{&nbsp;"spring",&nbsp;"summer",&nbsp;"autumn",&nbsp;"winter",&nbsp;}&nbsp;},<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;{&nbsp;"Fruehling",&nbsp;"Sommer",&nbsp;"Herbst",&nbsp;"Winter"&nbsp;}&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;};<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;for&nbsp;any&nbsp;array&nbsp;of&nbsp;seasons&nbsp;print&nbsp;seasons</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(unsigned&nbsp;i=0;&nbsp;i&lt;seasons_i18n.size();&nbsp;++i)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;boost::array&lt;std::string,4&gt;&nbsp;seasons&nbsp;=&nbsp;seasons_i18n[i];<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(unsigned&nbsp;j=0;&nbsp;j&lt;seasons.size();&nbsp;++j)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;seasons[j]&nbsp;&lt;&lt;&nbsp;"&nbsp;";<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;print&nbsp;first&nbsp;element&nbsp;of&nbsp;first&nbsp;array</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"first&nbsp;element&nbsp;of&nbsp;first&nbsp;array:&nbsp;"<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;seasons_i18n[0][0]&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;print&nbsp;last&nbsp;element&nbsp;of&nbsp;last&nbsp;array</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"last&nbsp;element&nbsp;of&nbsp;last&nbsp;array:&nbsp;"<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;seasons_i18n[seasons_i18n.size()-1][seasons_i18n[0].size()-1]<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
}<BR>
<BR>
</SPAN>
</TT>
</BODY>
</HTML>

64
array5.cpp Normal file
View File

@ -0,0 +1,64 @@
/* simple example for using class array<>
*/
#include <iostream>
#include <boost/array.hpp>
template <typename T>
void test_static_size (const T& cont)
{
int tmp[T::static_size];
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] << ' ';
}
std::cout << std::endl;
}
int main()
{
// define special type name
typedef boost::array<float,6> Array;
// create and initialize an array
const Array a = { { 42.42 } };
// 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;
std::cout << "max_size: " << a.max_size() << std::endl;
std::cout << "front: " << a.front() << std::endl;
std::cout << "back: " << a.back() << std::endl;
std::cout << "[0]: " << a[0] << std::endl;
std::cout << "elems: ";
// iterate through all elements
for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {
std::cout << *pos << ' ';
}
std::cout << std::endl;
test_static_size(a);
// check copy constructor and assignment operator
Array b(a);
Array c;
c = a;
if (a==b && a==c) {
std::cout << "copy construction and copy assignment are OK"
<< std::endl;
}
else {
std::cout << "copy construction and copy assignment are OK"
<< std::endl;
}
typedef boost::array<double,6> DArray;
typedef boost::array<int,6> IArray;
IArray ia = { 1, 2, 3, 4, 5, 6 };
DArray da;
da = ia;
da.assign(42);
}

85
array5.cpp.html Normal file
View File

@ -0,0 +1,85 @@
<HTML>
<HEAD>
<TITLE>array5.cpp</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
&nbsp;
<TABLE HEIGHT=40 WIDTH="100%">
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
<FONT face="Arial,Helvetica" size=+2><B>
&nbsp;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" >*&nbsp;simple&nbsp;example&nbsp;for&nbsp;using&nbsp;class&nbsp;array&lt;&gt;</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
#include&nbsp;&lt;iostream&gt;<BR>
#include&nbsp;&lt;<A href="./array.hpp.html">boost/array.hpp</A>&gt;<BR>
<BR>
template&nbsp;&lt;typename&nbsp;T&gt;<BR>
void&nbsp;test_static_size&nbsp;(const&nbsp;T&&nbsp;cont)<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;tmp[T::static_size];<BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(unsigned&nbsp;i=0;&nbsp;i&lt;T::static_size;&nbsp;++i)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp[i]&nbsp;=&nbsp;int(cont[i]);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(unsigned&nbsp;i=0;&nbsp;i&lt;T::static_size;&nbsp;++i)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;tmp[i]&nbsp;&lt;&lt;&nbsp;'&nbsp;';<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
}<BR>
<BR>
int&nbsp;main()<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;define&nbsp;special&nbsp;type&nbsp;name</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;boost::array&lt;float,6&gt;&nbsp;Array;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;create&nbsp;and&nbsp;initialize&nbsp;an&nbsp;array</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;Array&nbsp;a&nbsp;=&nbsp;{&nbsp;{&nbsp;42.42&nbsp;}&nbsp;};<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;use&nbsp;some&nbsp;common&nbsp;STL&nbsp;container&nbsp;operations</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"static_size:&nbsp;"&nbsp;&lt;&lt;&nbsp;a.size()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"size:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;a.size()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"empty:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;std::boolalpha&nbsp;&lt;&lt;&nbsp;a.empty()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"max_size:&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;a.max_size()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"front:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;a.front()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"back:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;a.back()&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"[0]:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&lt;&lt;&nbsp;a[0]&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"elems:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;iterate&nbsp;through&nbsp;all&nbsp;elements</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(Array::const_iterator&nbsp;pos=a.begin();&nbsp;pos&lt;a.end();&nbsp;++pos)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;*pos&nbsp;&lt;&lt;&nbsp;'&nbsp;';<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;test_static_size(a);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;check&nbsp;copy&nbsp;constructor&nbsp;and&nbsp;assignment&nbsp;operator</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;Array&nbsp;b(a);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;Array&nbsp;c;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;=&nbsp;a;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(a==b&nbsp;&&&nbsp;a==c)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"copy&nbsp;construction&nbsp;and&nbsp;copy&nbsp;assignment&nbsp;are&nbsp;OK"<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"copy&nbsp;construction&nbsp;and&nbsp;copy&nbsp;assignment&nbsp;are&nbsp;OK"<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;boost::array&lt;double,6&gt;&nbsp;DArray;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;boost::array&lt;int,6&gt;&nbsp;IArray;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;IArray&nbsp;ia&nbsp;=&nbsp;{&nbsp;1,&nbsp;2,&nbsp;3,&nbsp;4,&nbsp;5,&nbsp;6&nbsp;};<BR>
&nbsp;&nbsp;&nbsp;&nbsp;DArray&nbsp;da;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;da&nbsp;=&nbsp;ia;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;da.assign(42);<BR>
}<BR>
<BR>
</SPAN>
</TT>
</BODY>
</HTML>

View File

@ -1,143 +1,157 @@
// -*-C++-*- array.hpp
// <!!---------------------------------------------------------------------->
// <!! Copyright (C) 1998 Dietmar Kuehl, Claas Solutions GmbH >
// <!!>
// <!! Permission to use, copy, modify, distribute and sell this >
// <!! software for any purpose is hereby granted without fee, provided >
// <!! that the above copyright notice appears in all copies and that >
// <!! both that copyright notice and this permission notice appear in >
// <!! supporting documentation. Dietmar Kuehl and Claas Solutions make no >
// <!! representations about the suitability of this software for any >
// <!! purpose. It is provided "as is" without express or implied warranty. >
// <!!---------------------------------------------------------------------->
// Author: Dietmar Kuehl dietmar.kuehl@claas-solutions.de
// Title: STL container support, including support for built-in arrays
// Version: $Id$
// --------------------------------------------------------------------------
#if !defined(BOOST_ARRAY_HPP)
#define BOOST_ARRAY_HPP 1
// --------------------------------------------------------------------------
/* The following code declares class array,
* an STL container (as wrapper) for arrays of constant size.
*
* See
* http://www.josuttis.com/cppcode
* for details and the latest version.
*
* (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.
*
* Jul 31, 2000
*/
#ifndef BOOST_ARRAY_HPP
#define BOOST_ARRAY_HPP
#include <cstddef>
#include <stdexcept>
#include <iterator>
#include <algorithm>
// --------------------------------------------------------------------------
// BUG-FIX for compilers that don't support
// std::size_t and std::ptrdiff_t yet
// (such as gcc)
#include <boost/config.hpp>
namespace boost
{
namespace boost {
// --- a general version of container traits ------------------------------
template<class T, std::size_t N>
class array {
public:
T elems[N]; // fixed-size array of elements of type T
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 elems; }
const_iterator begin() const { return elems; }
iterator end() { return elems+N; }
const_iterator end() const { return elems+N; }
// reverse iterator support
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
# else
// workaround for broken reverse_iterator implementations due to no partial specialization
typedef std::reverse_iterator<iterator,T> reverse_iterator;
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
# endif
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
}
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const {
return const_reverse_iterator(begin());
}
// operator[]
reference operator[](size_type i) { return elems[i]; }
const_reference operator[](size_type i) const { 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]; }
// size is constant
static size_type size() { return N; }
static bool empty() { return false; }
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());
}
// direct access to data
const T* data() const { return elems; }
// assignment with type conversion
template <typename T2>
array<T,N>& operator= (const array<T2,N>& rhs) {
std::copy(rhs.begin(),rhs.end(), begin());
return *this;
}
// assign one value to all elements
void assign (const T& value)
{
std::fill_n(begin(),size(),value);
}
# ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
private:
# endif
// private member functions are allowed in aggregates [ISO 8.5.1]
static void rangecheck (size_type i) {
if (i >= size()) { throw std::range_error("array"); }
}
template <typename Cont>
struct array_traits
{
typedef typename Cont::iterator iter_type;
typedef typename Cont::size_type size_type;
static iter_type begin(Cont &cont) { return cont.begin(); }
static iter_type end(Cont &cont) { return cont.end(); }
static size_type size(Cont &cont) { return cont.size(); }
};
// --- a version of container traits for constant constainer --------------
// comparisons
template<class T, std::size_t N>
bool operator== (const array<T,N>& x, const array<T,N>& y) {
return std::equal(x.begin(), x.end(), y.begin());
}
template<class T, std::size_t N>
bool operator< (const array<T,N>& x, const array<T,N>& y) {
return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
}
template<class T, std::size_t N>
bool operator!= (const array<T,N>& x, const array<T,N>& y) {
return !(x==y);
}
template<class T, std::size_t N>
bool operator> (const array<T,N>& x, const array<T,N>& y) {
return y<x;
}
template<class T, std::size_t N>
bool operator<= (const array<T,N>& x, const array<T,N>& y) {
return !(y<x);
}
template<class T, std::size_t N>
bool operator>= (const array<T,N>& x, const array<T,N>& y) {
return !(x<y);
}
template <typename Cont>
struct array_traits<Cont const>
{
typedef typename Cont::const_iterator iter_type;
typedef typename Cont::size_type size_type;
static iter_type begin(Cont const &cont) { return cont.begin(); }
static iter_type end(Cont const &cont) { return cont.end(); }
static size_type size(Cont const &cont) { return cont.size(); }
};
// global swap()
template<class T, std::size_t N>
inline void swap (array<T,N>& x, array<T,N>& y) {
x.swap(y);
}
// --- a special version for non-const built-in arrays --------------------
} /* namespace boost */
template <typename T, size_t sz>
struct array_traits<T[sz]>
{
typedef T* iter_type;
typedef size_t size_type;
static iter_type begin(T (&array)[sz]) { return array; }
static iter_type end(T (&array)[sz]) { return array + sz; }
static size_type size(T (&)[sz]) { return sz; }
};
// --- a special version for const built-in arrays ------------------------
template <typename T, size_t sz>
struct array_traits<T const[sz]>
{
typedef T const* iter_type;
typedef size_t size_type;
static iter_type begin(T const (&array)[sz]) { return array; }
static iter_type end(T const (&array)[sz]) { return array + sz; }
static size_type size(T const (&array)[sz]) { return sz; }
};
template <typename T, int sz>
inline char (&sizer(T (&)[sz]))[sz];
// --- general version of the global accessor functions ---------------------
template <typename Cont>
inline typename array_traits<Cont>::iter_type
begin(Cont &cont) { return array_traits<Cont>::begin(cont); }
template <typename Cont>
inline typename array_traits<Cont>::iter_type
end(Cont &cont) { return array_traits<Cont>::end(cont); }
template <typename Cont>
inline typename array_traits<Cont>::size_type
size(Cont &cont) { return array_traits<Cont>::size(cont); }
// --- Actually the above should be sufficient but compilers seem -----------
// --- to welcome some help. So here we go:
template <typename T, size_t sz>
inline typename array_traits<T[sz]>::iter_type
begin(T (&a)[sz]) { return array_traits<T[sz]>::begin(a); }
template <typename T, size_t sz>
inline typename array_traits<T[sz]>::iter_type
end(T (&a)[sz]) { return array_traits<T[sz]>::end(a); }
template <typename T, size_t sz>
inline typename array_traits<T[sz]>::size_type
size(T (&a)[sz]) { return array_traits<T[sz]>::size(a); }
// --- Apparently the compilers also need some specific help, ---------------
// --- EDG-2.39 wants to pass around pointers in some contexts --------------
#ifdef __EDG__
template <typename T>
struct array_traits<T*>
{
typedef T* iter_type;
typedef size_t size_type;
};
#endif
// --- egcs-1998-11-22 apparently likes an extra const version: -------------
#ifdef __GNUG__
template <typename T, size_t sz>
inline typename array_traits<T const[sz]>::iter_type
begin(T const(&a)[sz]) { return array_traits<T const[sz]>::begin(a); }
template <typename T, size_t sz>
inline typename array_traits<T const[sz]>::iter_type
end(T const(&a)[sz]) { return array_traits<T const[sz]>::end(a); }
template <typename T, size_t sz>
inline typename array_traits<T const[sz]>::size_type
size(T const (&a)[sz]) { return array_traits<T const[sz]>::size(a); }
#endif
}
// -----------------------------------------------------------------------------
#endif /* BOOST_ARRAY_HPP */
#endif /*BOOST_ARRAY_HPP*/

36
index.htm Normal file
View File

@ -0,0 +1,36 @@
<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.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.htm">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>
</body>
</html>

28
print.hpp Normal file
View File

@ -0,0 +1,28 @@
/* The following code example is taken from the book
* "The C++ Standard Library - A Tutorial and Reference"
* 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.
*/
#include <iostream>
/* PRINT_ELEMENTS()
* - prints optional C-string optcstr followed by
* - all elements of the collection coll
* - separated by spaces
*/
template <class T>
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr="")
{
typename T::const_iterator pos;
std::cout << optcstr;
for (pos=coll.begin(); pos!=coll.end(); ++pos) {
std::cout << *pos << ' ';
}
std::cout << std::endl;
}

48
print.hpp.html Normal file
View File

@ -0,0 +1,48 @@
<HTML>
<HEAD>
<TITLE>PRINT_ELEMENTS()</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
&nbsp;
<TABLE HEIGHT=40 WIDTH="100%">
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
<FONT face="Arial,Helvetica" size=+2><B>
&nbsp;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">
&copy; Copyright</A> Nicolai M. Josuttis 1999<BR>
</B></FONT>
<BR><BR>
<TT>
<SPAN class="Source">
#include&nbsp;&lt;iostream&gt;<BR>
<BR>
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;PRINT_ELEMENTS()</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;-&nbsp;prints&nbsp;optional&nbsp;C-string&nbsp;optcstr&nbsp;followed&nbsp;by</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;-&nbsp;all&nbsp;elements&nbsp;of&nbsp;the&nbsp;collection&nbsp;coll</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;-&nbsp;separated&nbsp;by&nbsp;spaces</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
template&nbsp;&lt;class&nbsp;T&gt;<BR>
inline&nbsp;void&nbsp;PRINT_ELEMENTS&nbsp;(const&nbsp;T&&nbsp;coll,&nbsp;const&nbsp;char*&nbsp;optcstr="")<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;typename&nbsp;T::const_iterator&nbsp;pos;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;optcstr;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(pos=coll.begin();&nbsp;pos!=coll.end();&nbsp;++pos)&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;*pos&nbsp;&lt;&lt;&nbsp;'&nbsp;';<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
}<BR>
</SPAN>
</TT>
</BODY>
</HTML>