mirror of
https://github.com/boostorg/array.git
synced 2025-07-12 12:16:32 +02:00
initial checkin of Nico's array library
[SVN r7678]
This commit is contained in:
69
array3.cpp.html
Normal file
69
array3.cpp.html
Normal file
@ -0,0 +1,69 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>array3.cpp</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||
|
||||
<TABLE HEIGHT=40 WIDTH="100%">
|
||||
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||
<FONT face="Arial,Helvetica" size=+2><B>
|
||||
array3.cpp
|
||||
</B></FONT>
|
||||
</TD></TR></TABLE><BR>
|
||||
|
||||
<BR><BR>
|
||||
<TT>
|
||||
<SPAN class="Source">
|
||||
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* example for using class array<></FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||
#include <string><BR>
|
||||
#include <iostream><BR>
|
||||
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||
<BR>
|
||||
template <class T><BR>
|
||||
void print_elements (const T& x);<BR>
|
||||
<BR>
|
||||
int main()<BR>
|
||||
{<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create array of four seasons</FONT></I><BR>
|
||||
boost::array<std::string,4> seasons = {<BR>
|
||||
{ "spring", "summer", "autumn", "winter" }<BR>
|
||||
};<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// copy and change order</FONT></I><BR>
|
||||
boost::array<std::string,4> seasons_orig = seasons;<BR>
|
||||
for (unsigned i=seasons.size()-1; i>0; --i) {<BR>
|
||||
swap(seasons.at(i),seasons.at((i+1)%seasons.size()));<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
std::cout << "one way: ";<BR>
|
||||
print_elements(seasons);<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// try swap()</FONT></I><BR>
|
||||
std::cout << "other way: ";<BR>
|
||||
swap(seasons,seasons_orig);<BR>
|
||||
print_elements(seasons);<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// try reverse iterators</FONT></I><BR>
|
||||
std::cout << "reverse: ";<BR>
|
||||
for (boost::array<std::string,4>::reverse_iterator pos<BR>
|
||||
=seasons.rbegin(); pos<seasons.rend(); ++pos) {<BR>
|
||||
std::cout << " " << *pos;<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
template <class T><BR>
|
||||
void print_elements (const T& x)<BR>
|
||||
{<BR>
|
||||
for (unsigned i=0; i<x.size(); ++i) {<BR>
|
||||
std::cout << " " << x[i];<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
</SPAN>
|
||||
</TT>
|
||||
</BODY>
|
||||
</HTML>
|
Reference in New Issue
Block a user