1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
<HTML>
<HEAD>
<TITLE>array.hpp</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>
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" >* The following code declares class array,</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* an STL container (as wrapper) for arrays of constant size.</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* See</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* <a href="http://www.josuttis.com/cppcode">http://www.josuttis.com/cppcode</a></FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* for details and the latest version.</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* (C) Copyright Nicolai M. Josuttis 2001.</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* Permission to copy, use, modify, sell and distribute this software</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* is granted provided this copyright notice appears in all copies.</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* This software is provided "as is" without express or implied</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* warranty, and with no claim as to its suitability for any purpose.</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* Aug 05, 2001</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
#ifndef BOOST_ARRAY_HPP<BR>
#define BOOST_ARRAY_HPP<BR>
<BR>
#include <cstddef><BR>
#include <stdexcept><BR>
#include <iterator><BR>
#include <algorithm><BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// FIXES for broken compilers</FONT></I><BR>
#include <<A href="../../boost/config.hpp">boost/config.hpp</A>><BR>
<BR>
namespace boost {<BR>
<BR>
template<class T, std::size_t N><BR>
class array {<BR>
public:<BR>
T elems[N]; <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// fixed-size array of elements of type T</FONT></I><BR>
<BR>
public:<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// type definitions</FONT></I><BR>
typedef T value_type;<BR>
typedef T* iterator;<BR>
typedef const T* const_iterator;<BR>
typedef T& reference;<BR>
typedef const T& const_reference;<BR>
typedef std::size_t size_type;<BR>
typedef std::ptrdiff_t difference_type;<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// iterator support</FONT></I><BR>
iterator begin() { return elems; }<BR>
const_iterator begin() const { return elems; }<BR>
iterator end() { return elems+N; }<BR>
const_iterator end() const { return elems+N; }<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// reverse iterator support</FONT></I><BR>
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)<BR>
typedef std::reverse_iterator<iterator> reverse_iterator;<BR>
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;<BR>
#else<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// workaround for broken reverse_iterator implementations</FONT></I><BR>
typedef std::reverse_iterator<iterator,T> reverse_iterator;<BR>
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;<BR>
#endif<BR>
<BR>
reverse_iterator rbegin() { return reverse_iterator(end()); }<BR>
const_reverse_iterator rbegin() const {<BR>
return const_reverse_iterator(end());<BR>
}<BR>
reverse_iterator rend() { return reverse_iterator(begin()); }<BR>
const_reverse_iterator rend() const {<BR>
return const_reverse_iterator(begin());<BR>
}<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// operator[]</FONT></I><BR>
reference operator[](size_type i) { return elems[i]; }<BR>
const_reference operator[](size_type i) const { return elems[i]; }<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// at() with range check</FONT></I><BR>
reference at(size_type i) { rangecheck(i); return elems[i]; }<BR>
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// front() and back()</FONT></I><BR>
reference front() { return elems[0]; }<BR>
const_reference front() const { return elems[0]; }<BR>
reference back() { return elems[N-1]; }<BR>
const_reference back() const { return elems[N-1]; }<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// size is constant</FONT></I><BR>
static size_type size() { return N; }<BR>
static bool empty() { return false; }<BR>
static size_type max_size() { return N; }<BR>
enum { static_size = N };<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// swap (note: linear complexity)</FONT></I><BR>
void swap (array<T,N>& y) {<BR>
std::swap_ranges(begin(),end(),y.begin());<BR>
}<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// direct access to data</FONT></I><BR>
const T* data() const { return elems; }<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// assignment with type conversion</FONT></I><BR>
template <typename T2><BR>
array<T,N>& operator= (const array<T2,N>& rhs) {<BR>
std::copy(rhs.begin(),rhs.end(), begin());<BR>
return *this;<BR>
}<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// assign one value to all elements</FONT></I><BR>
void assign (const T& value)<BR>
{<BR>
std::fill_n(begin(),size(),value);<BR>
}<BR>
<BR>
#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE<BR>
private:<BR>
#endif<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// check range (may be private because it is static)</FONT></I><BR>
static void rangecheck (size_type i) {<BR>
if (i >= size()) { throw std::range_error("array"); }<BR>
}<BR>
<BR>
};<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// comparisons</FONT></I><BR>
template<class T, std::size_t N><BR>
bool operator== (const array<T,N>& x, const array<T,N>& y) {<BR>
return std::equal(x.begin(), x.end(), y.begin());<BR>
}<BR>
template<class T, std::size_t N><BR>
bool operator< (const array<T,N>& x, const array<T,N>& y) {<BR>
return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());<BR>
}<BR>
template<class T, std::size_t N><BR>
bool operator!= (const array<T,N>& x, const array<T,N>& y) {<BR>
return !(x==y);<BR>
}<BR>
template<class T, std::size_t N><BR>
bool operator> (const array<T,N>& x, const array<T,N>& y) {<BR>
return y<x;<BR>
}<BR>
template<class T, std::size_t N><BR>
bool operator<= (const array<T,N>& x, const array<T,N>& y) {<BR>
return !(y<x);<BR>
}<BR>
template<class T, std::size_t N><BR>
bool operator>= (const array<T,N>& x, const array<T,N>& y) {<BR>
return !(x<y);<BR>
}<BR>
<BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// global swap()</FONT></I><BR>
template<class T, std::size_t N><BR>
inline void swap (array<T,N>& x, array<T,N>& y) {<BR>
x.swap(y);<BR>
}<BR>
<BR>
} <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >/* namespace boost */</FONT></I><BR>
<BR>
#endif <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >/*BOOST_ARRAY_HPP*/</FONT></I><BR>
</SPAN>
</TT>
</BODY>
</HTML>
|