mirror of
https://github.com/boostorg/array.git
synced 2025-07-13 12:46:32 +02:00
initial checkin of Nico's array library
[SVN r7678]
This commit is contained in:
84
array5.cpp.html
Normal file
84
array5.cpp.html
Normal file
@ -0,0 +1,84 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>array5.cpp</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||
|
||||
<TABLE HEIGHT=40 WIDTH="100%">
|
||||
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||
<FONT face="Arial,Helvetica" size=+2><B>
|
||||
array5.cpp
|
||||
</B></FONT>
|
||||
</TD></TR></TABLE><BR>
|
||||
|
||||
<BR><BR>
|
||||
<TT>
|
||||
<SPAN class="Source">
|
||||
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* simple example for using class array<></FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||
#include <iostream><BR>
|
||||
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||
<BR>
|
||||
template <typename T><BR>
|
||||
void test_static_size (const T& cont)<BR>
|
||||
{<BR>
|
||||
int tmp[T::static_size];<BR>
|
||||
for (unsigned i=0; i<T::static_size; ++i) {<BR>
|
||||
tmp[i] = int(cont[i]);<BR>
|
||||
}<BR>
|
||||
for (unsigned i=0; i<T::static_size; ++i) {<BR>
|
||||
std::cout << tmp[i] << ' ';<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
int main()<BR>
|
||||
{<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// define special type name</FONT></I><BR>
|
||||
typedef boost::array<float,6> Array;<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create and initialize an array</FONT></I><BR>
|
||||
const Array a = { { 42.42 } };<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// use some common STL container operations</FONT></I><BR>
|
||||
std::cout << "static_size: " << a.size() << std::endl;<BR>
|
||||
std::cout << "size: " << a.size() << std::endl;<BR>
|
||||
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;<BR>
|
||||
std::cout << "max_size: " << a.max_size() << std::endl;<BR>
|
||||
std::cout << "front: " << a.front() << std::endl;<BR>
|
||||
std::cout << "back: " << a.back() << std::endl;<BR>
|
||||
std::cout << "[0]: " << a[0] << std::endl;<BR>
|
||||
std::cout << "elems: ";<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// iterate through all elements</FONT></I><BR>
|
||||
for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {<BR>
|
||||
std::cout << *pos << ' ';<BR>
|
||||
}<BR>
|
||||
std::cout << std::endl;<BR>
|
||||
test_static_size(a);<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// check copy constructor and assignment operator</FONT></I><BR>
|
||||
Array b(a);<BR>
|
||||
Array c;<BR>
|
||||
c = a;<BR>
|
||||
if (a==b && a==c) {<BR>
|
||||
std::cout << "copy construction and copy assignment are OK"<BR>
|
||||
<< std::endl;<BR>
|
||||
}<BR>
|
||||
else {<BR>
|
||||
std::cout << "copy construction and copy assignment are OK"<BR>
|
||||
<< std::endl;<BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//typedef boost::array<double,6> DArray;</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//typedef boost::array<int,6> IArray;</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//IArray ia = { { 1, 2, 3, 4, 5, 6 } };</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//DArray da;</FONT></I><BR>
|
||||
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >//da.assign(ia);</FONT></I><BR>
|
||||
}<BR>
|
||||
<BR>
|
||||
</SPAN>
|
||||
</TT>
|
||||
</BODY>
|
||||
</HTML>
|
Reference in New Issue
Block a user