forked from boostorg/array
57 lines
2.9 KiB
HTML
57 lines
2.9 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>array2.cpp</TITLE>
|
|
</HEAD>
|
|
|
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
|
|
|
<TABLE HEIGHT=40 WIDTH="100%">
|
|
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
|
<FONT face="Arial,Helvetica" size=+2><B>
|
|
array2.cpp
|
|
</B></FONT>
|
|
</TD></TR></TABLE><BR>
|
|
|
|
<BR><BR>
|
|
<TT>
|
|
<SPAN class="Source">
|
|
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* example for using class array<></FONT></I><BR>
|
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
|
#include <algorithm><BR>
|
|
#include <functional><BR>
|
|
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
|
#include "<A href="print.hpp.html">print.hpp</A>"<BR>
|
|
using namespace std;<BR>
|
|
using namespace boost;<BR>
|
|
<BR>
|
|
int main()<BR>
|
|
{<BR>
|
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create and initialize array</FONT></I><BR>
|
|
array<int,10> a = { { 1, 2, 3, 4, 5 } };<BR>
|
|
<BR>
|
|
print_elements(a);<BR>
|
|
<BR>
|
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// modify elements directly</FONT></I><BR>
|
|
for (unsigned i=0; i<a.size(); ++i) {<BR>
|
|
++a[i];<BR>
|
|
}<BR>
|
|
print_elements(a);<BR>
|
|
<BR>
|
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// change order using an STL algorithm</FONT></I><BR>
|
|
reverse(a.begin(),a.end());<BR>
|
|
print_elements(a);<BR>
|
|
<BR>
|
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// negate elements using STL framework</FONT></I><BR>
|
|
transform(a.begin(),a.end(), <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// source</FONT></I><BR>
|
|
a.begin(), <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// destination</FONT></I><BR>
|
|
negate<int>()); <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// operation</FONT></I><BR>
|
|
print_elements(a);<BR>
|
|
<BR>
|
|
return 0; <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// makes Visual-C++ compiler happy</FONT></I><BR>
|
|
}<BR>
|
|
<BR>
|
|
</SPAN>
|
|
</TT>
|
|
</BODY>
|
|
</HTML>
|