Compare commits

...

14 Commits

Author SHA1 Message Date
f18070dc23 This commit was manufactured by cvs2svn to create branch
'python-v2-dev'.

[SVN r14785]
2002-08-12 13:35:54 +00:00
b87433497e array5.cpp:
- Add (redundant) braces around initializer to silence GCC


[SVN r12528]
2002-01-27 18:22:19 +00:00
09c271cf34 array3.cpp:
- Qualify std::swap for compilers that don't have Koenig lookup

array5.cpp:
  - Don't use std::boolalpha, because it isn't portable


[SVN r12463]
2002-01-23 18:07:11 +00:00
f5699ae164 Fixed reverse iterator declarations so that they work with VC7b2.
[SVN r12173]
2001-12-29 12:33:32 +00:00
f96ac657dd update from Nico
[SVN r10918]
2001-08-23 20:33:35 +00:00
7f73413eed Fix some broken links. Fix order of constructor initializers.
[SVN r10913]
2001-08-23 17:42:07 +00:00
640d1434bf Change absolute URL's to relative
[SVN r10594]
2001-07-12 15:31:15 +00:00
624bd0e218 1.21.1 run up, including new download instructions and fix broken hyperlinks
[SVN r9557]
2001-03-14 15:11:55 +00:00
ad82e2b25c All final 1.20.2 changes, including fixing broken hyperlinks
[SVN r9071]
2001-02-10 14:42:14 +00:00
44887bfe59 Added changelog
[SVN r8662]
2001-01-21 05:02:37 +00:00
fd76085150 Fix for STLport on MSVC
[SVN r8660]
2001-01-20 22:58:11 +00:00
aac83e6667 Replaced boolalpha use with something that the stock gcc library can handle.
[SVN r8659]
2001-01-20 22:36:49 +00:00
a673bc6e82 Broken iterator fix needs to apply to the Intel compiler too, because it uses the MSVC library
[SVN r8639]
2001-01-18 21:20:42 +00:00
a91e96a8ab Docs fixes (Nico)+ add return 0; to test files (Beman)
[SVN r8496]
2000-12-27 02:03:29 +00:00
16 changed files with 134 additions and 86 deletions

View File

@ -19,16 +19,16 @@
&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.josuttis.com/cppcode">http://www.josuttis.com/cppcode</a></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;(C)&nbsp;Copyright&nbsp;Nicolai&nbsp;M.&nbsp;Josuttis&nbsp;2001.</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;Sep&nbsp;29,&nbsp;2000</FONT></I><BR>
&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*&nbsp;Aug&nbsp;05,&nbsp;2001</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>
@ -39,7 +39,7 @@
#include&nbsp;&lt;algorithm&gt;<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;FIXES&nbsp;for&nbsp;broken&nbsp;compilers</FONT></I><BR>
#include&nbsp;&lt;<A href="../../boost/config.hpp"><A href="http://www.boost.org/boost/config.hpp">boost/config.hpp</A></A>&gt;<BR>
#include&nbsp;&lt;<A href="../../boost/config.hpp">boost/config.hpp</A>&gt;<BR>
<BR>
namespace&nbsp;boost&nbsp;{<BR>
<BR>
@ -65,11 +65,11 @@ namespace&nbsp;boost&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>
#if&nbsp;!defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)<BR>
#if&nbsp;!defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)&nbsp;&&&nbsp;!defined(BOOST_MSVC_STD_ITERATOR)<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>
#else<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;workaround&nbsp;for&nbsp;broken&nbsp;reverse_iterator&nbsp;implementations&nbsp;due&nbsp;to&nbsp;no&nbsp;partial&nbsp;specialization</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;workaround&nbsp;for&nbsp;broken&nbsp;reverse_iterator&nbsp;implementations</FONT></I><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;std::reverse_iterator&lt;iterator,T&gt;&nbsp;reverse_iterator;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;std::reverse_iterator&lt;const_iterator,T&gt;&nbsp;const_reverse_iterator;<BR>
#endif<BR>

View File

@ -15,11 +15,14 @@
Wrapper) for Arrays of Constant Size</font></b></td>
</tr>
</table>
<p><font face="Arial, Helvetica, sans-serif" size="-1">The C++ Standard Template
Library STL as part of the C++ Standard Library provides a framework for processing
algorithms on different kind of containers. However, ordinary arrays don't provide
the interface of STL containers (although, they provide the iterator interface
of STL containers).</font>
<p><font size="-1" face="Arial, Helvetica, sans-serif">[<a href="#intro">intro</a>]
[<a href="#interface">interface</a>] [<a href="#discussion">discussion</a>]
[<a href="#code">code</a>]</font>
<p><font face="Arial, Helvetica, sans-serif" size="-1"><a name="intro"></a>The
C++ Standard Template Library STL as part of the C++ Standard Library provides
a framework for processing algorithms on different kind of containers. However,
ordinary arrays don't provide the interface of STL containers (although, they
provide the iterator interface of STL containers).</font>
<p><font face="Arial, Helvetica, sans-serif" size="-1">As replacement for ordinary
arrays, the STL provides class <font face="Courier New, Courier, mono">vector&lt;&gt;</font>.
However, <font face="Courier New, Courier, mono">vector&lt;&gt;</font> provides
@ -38,8 +41,8 @@
the essence of these approaches spiced with many feedback from <a href="http://www.boost.org">boost</a>.</font>
<p><font face="Arial, Helvetica, sans-serif" size="-1">After considering different
names, we decided to name this class simply <font face="Courier New, Courier, mono"><b>array</b></font>.</font>
<p><font face="Arial, Helvetica, sans-serif" size="-1">The class provides the
following interface:</font>
<p><font face="Arial, Helvetica, sans-serif" size="-1"><a name="interface"></a>The
class provides the following interface:</font>
<table border="0">
<tr>
<td><font face="Arial, Helvetica, sans-serif" size="-1"><b>Types:</b></font></td>
@ -127,7 +130,7 @@
<tr>
<td><font face="Courier New, Courier, mono" size="-1">rend()</font></td>
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns reverse iterator
for posistion behind last element of reverese iteration </font></td>
for position behind last element of reverse iteration </font></td>
</tr>
<tr>
<td><font face="Courier New, Courier, mono" size="-1">operator[<i>i</i>]</font></td>
@ -197,15 +200,15 @@
time</font></td>
</tr>
</table>
<p><font face="Arial, Helvetica, sans-serif" size="-1">Class array fulfills most
but not all of the requirements of &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>
<p><font face="Arial, Helvetica, sans-serif" size="-1"><a name="discussion"></a>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>
- 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>
- 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>
@ -236,69 +239,76 @@
<li><font face="Arial, Helvetica, sans-serif" size="-1">It has no virtual functions.</font></li>
</ul>
<p><font face="Arial, Helvetica, sans-serif" size="-1">The current implementation
useus this approach. However, being able to have indetermined initial values
uses this approach. However, being able to have indeterminate initial values
is a big drawback. So, please give me some feedback, how useful you consider
this feature to be. This leads to the list of <b>Open issues:</b></font>
<ul>
<li><font face="Arial, Helvetica, sans-serif">Do we want initializer list support
or would the following be OK?:</font>
<li><font face="Arial, Helvetica, sans-serif" size="-1">Do we want initializer
list support or would the following be OK?:</font>
<blockquote>
<p><font face="Courier New, Courier, mono">int data[] = { 1, 2, 3, 4 }</font></p>
<p><font face="Courier New, Courier, mono">array&lt;int,5&gt; x(data); <font face="Arial, Helvetica, sans-serif">or
</font>&nbsp;&nbsp;array&lt;int,data&gt; x;</font></p>
<p><font face="Courier New, Courier, mono" size="-1">int data[] = { 1, 2,
3, 4 }</font></p>
<p><font face="Courier New, Courier, mono" size="-1">array&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">{
<li><font face="Arial, Helvetica, sans-serif" size="-1">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>
<p><font face="Arial, Helvetica, sans-serif" size="-1">8.5.1 (11) of the Standard
seems to allow it; however, gcc 2.95.2 prints a warning message.</font></p>
</blockquote>
<li><font face="Arial, Helvetica, sans-serif">Any way to have determined initial
values and initializer list support?</font></li>
<li><font face="Arial, Helvetica, sans-serif">Static_casts for reverse iterator
stuff</font><font face="Arial, Helvetica, sans-serif">?</font></li>
<li><font face="Arial, Helvetica, sans-serif" size="-1">Any way to have determinate
initial values and initializer list support?</font></li>
<li><font face="Arial, Helvetica, sans-serif" size="-1">Static_casts for reverse
iterator stuff?</font></li>
</ul>
<p><font face="Arial, Helvetica, sans-serif">I'd appreciate any constructive <a href="mailto:solutions@josuttis.com">feedback</a>.
<b>Please note: I don't have time to read all boost mails. Thus, to make sure
that feedback arrives me, please send me a copy of each mail regarding this
class.</b></font>
<p><font face="Arial, Helvetica, sans-serif">The code is provided "as is" without
expressed or implied warranty.</font>
<p><font face="Arial, Helvetica, sans-serif" size="-1">I'd appreciate any constructive
<a href="mailto:solutions@josuttis.com">feedback</a>. <b>Please note: I don't
have time to read all boost mails. Thus, to make sure that feedback arrives
me, please send me a copy of each mail regarding this class.</b></font>
<p><font face="Arial, Helvetica, sans-serif"><a name="code"></a>The code is provided
"as is" without expressed or implied warranty.</font>
<p><font face="Arial, Helvetica, sans-serif"><b>array.hpp</b>, the implementation
of <font face="Courier New, Courier, mono">array&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="../../boost/array.hpp">as plain file</a></font></li>
<p> <font face="Arial, Helvetica, sans-serif">Simple Example for using <font face="Courier New, Courier, mono">array&lt;&gt;<font face="Arial, Helvetica, sans-serif">:</font></font></font>
<p> <font face="Arial, Helvetica, sans-serif"><b>array1.cpp</b>, a 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>
<p> <font face="Arial, Helvetica, sans-serif"><b>array2.cpp</b>, 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>
<p> <font face="Arial, Helvetica, sans-serif"><b>array3.cpp</b>, 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>
<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">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>
<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&lt;&gt;<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><font face="Arial, Helvetica, sans-serif">
<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>&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.josuttis.com/libbook/">The C++
@ -307,9 +317,14 @@
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>
</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>
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">&nbsp; </font>
</body>
</html>

View File

@ -1,4 +1,8 @@
/* simple example for using class array<>
*
* Changelog:
* 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it
* (David Abrahams)
*/
#include <iostream>
#include <boost/array.hpp>
@ -18,7 +22,7 @@ int main()
// use some common STL container operations
std::cout << "size: " << a.size() << std::endl;
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;
std::cout << "empty: " << (a.empty() ? "true" : "false") << std::endl;
std::cout << "max_size: " << a.max_size() << std::endl;
std::cout << "front: " << a.front() << std::endl;
std::cout << "back: " << a.back() << std::endl;
@ -36,11 +40,13 @@ int main()
c = a;
if (a==b && a==c) {
std::cout << "copy construction and copy assignment are OK"
<< std::endl;
<< std::endl;
}
else {
std::cout << "copy construction and copy assignment FAILED"
<< std::endl;
<< std::endl;
}
return 0; // makes Visual-C++ compiler happy
}

View File

@ -53,12 +53,14 @@ int&nbsp;main()<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;&nbsp;&nbsp;&nbsp;&nbsp;&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;FAILED"<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;return&nbsp;0;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;makes&nbsp;Visual-C++&nbsp;compiler&nbsp;happy</FONT></I><BR>
}<BR>
<BR>
</SPAN>

View File

@ -12,22 +12,24 @@ int main()
// create and initialize array
array<int,10> a = { { 1, 2, 3, 4, 5 } };
PRINT_ELEMENTS(a);
print_elements(a);
// modify elements directly
for (unsigned i=0; i<a.size(); ++i) {
++a[i];
}
PRINT_ELEMENTS(a);
print_elements(a);
// change order using an STL algorithm
reverse(a.begin(),a.end());
PRINT_ELEMENTS(a);
print_elements(a);
// negate elements using STL framework
transform(a.begin(),a.end(), // source
a.begin(), // destination
negate<int>()); // operation
PRINT_ELEMENTS(a);
print_elements(a);
return 0; // makes Visual-C++ compiler happy
}

View File

@ -29,23 +29,25 @@ int&nbsp;main()<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>
&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>
&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>
&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>
&nbsp;&nbsp;&nbsp;&nbsp;print_elements(a);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;makes&nbsp;Visual-C++&nbsp;compiler&nbsp;happy</FONT></I><BR>
}<BR>
<BR>
</SPAN>

View File

@ -17,7 +17,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 +25,7 @@ int main()
// try swap()
std::cout << "other way: ";
swap(seasons,seasons_orig);
std::swap(seasons,seasons_orig);
print_elements(seasons);
// try reverse iterators
@ -35,6 +35,8 @@ int main()
std::cout << " " << *pos;
}
std::cout << std::endl;
return 0; // makes Visual-C++ compiler happy
}
template <class T>

View File

@ -52,6 +52,8 @@ int&nbsp;main()<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>
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;makes&nbsp;Visual-C++&nbsp;compiler&nbsp;happy</FONT></I><BR>
}<BR>
<BR>
template&nbsp;&lt;class&nbsp;T&gt;<BR>

View File

@ -31,6 +31,8 @@ int main()
// 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;
<< std::endl;
return 0; // makes Visual-C++ compiler happy
}

View File

@ -48,7 +48,9 @@ int&nbsp;main()<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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;std::endl;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;makes&nbsp;Visual-C++&nbsp;compiler&nbsp;happy</FONT></I><BR>
}<BR>
<BR>
</SPAN>

View File

@ -27,7 +27,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;
@ -47,18 +48,20 @@ int main()
c = a;
if (a==b && a==c) {
std::cout << "copy construction and copy assignment are OK"
<< std::endl;
<< std::endl;
}
else {
std::cout << "copy construction and copy assignment are OK"
<< std::endl;
std::cout << "copy construction and copy assignment are BROKEN"
<< std::endl;
}
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);
return 0; // makes Visual-C++ compiler happy
}

View File

@ -64,11 +64,11 @@ int&nbsp;main()<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;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;"copy&nbsp;construction&nbsp;and&nbsp;copy&nbsp;assignment&nbsp;are&nbsp;BROKEN"<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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>
@ -77,6 +77,8 @@ int&nbsp;main()<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>
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//&nbsp;makes&nbsp;Visual-C++&nbsp;compiler&nbsp;happy</FONT></I><BR>
}<BR>
<BR>
</SPAN>

View File

@ -5,13 +5,15 @@
* http://www.josuttis.com/cppcode
* for details and the latest version.
*
* (C) Copyright Nicolai M. Josuttis 1999.
* (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.
*
* Sep 29, 2000
* 05 Aug 2001 - minor update (Nico Josuttis)
* 20 Jan 2001 - STLport fix (Beman Dawes)
* 29 Sep 2000 - Initial Revision (Nico Josuttis)
*/
#ifndef BOOST_ARRAY_HPP
#define BOOST_ARRAY_HPP
@ -48,11 +50,17 @@ namespace boost {
const_iterator end() const { return elems+N; }
// reverse iterator support
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
#elif defined(BOOST_MSVC) && (BOOST_MSVC == 1300)
// 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 due to no partial specialization
// 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
@ -152,3 +160,4 @@ namespace boost {
} /* namespace boost */
#endif /*BOOST_ARRAY_HPP*/

View File

@ -26,10 +26,9 @@ of constant size.
<li><a href="array.html">Documentation</a> (HTML).</li>
<li>Header <a href="../../boost/array.hpp">array.hpp</a></li>
<li>See docs for links to example programs.</li>
<li>Download <a href="../../boost_all.zip">all of Boost</a> (ZIP format).</li>
<li>Submitted by <a href="http://www.josuttis.com">Nicolai M. Josuttis</a>.</li>
</ul>
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->10 Nov 2000<!--webbot bot="Timestamp" endspan i-checksum="15233" --></p>
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->14 Mar 2001<!--webbot bot="Timestamp" endspan i-checksum="14885" --></p>
</body>

View File

@ -10,13 +10,13 @@
*/
#include <iostream>
/* PRINT_ELEMENTS()
/* 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="")
inline void print_elements (const T& coll, const char* optcstr="")
{
typename T::const_iterator pos;

View File

@ -26,13 +26,13 @@
<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>
<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>
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>