2000-08-30 12:44:40 +00:00
|
|
|
<HTML>
|
|
|
|
<HEAD>
|
|
|
|
<TITLE>array.hpp</TITLE>
|
|
|
|
</HEAD>
|
2000-08-02 18:15:32 +00:00
|
|
|
|
2000-08-30 12:44:40 +00:00
|
|
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
2000-08-02 18:15:32 +00:00
|
|
|
|
2000-08-30 12:44:40 +00:00
|
|
|
<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>
|
2000-08-02 18:15:32 +00:00
|
|
|
|
2000-08-30 12:44:40 +00:00
|
|
|
<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" >* http://www.josuttis.com/cppcode</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 1999.</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>
|
2000-09-30 20:54:15 +00:00
|
|
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* Sep 29, 2000</FONT></I><BR>
|
2000-08-30 12:44:40 +00:00
|
|
|
<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>
|
2000-09-30 20:54:15 +00:00
|
|
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// FIXES for broken compilers</FONT></I><BR>
|
2001-08-23 17:42:07 +00:00
|
|
|
#include <<A href="../../boost/config.hpp">boost/config.hpp</A>><BR>
|
2000-08-30 12:44:40 +00:00
|
|
|
<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>
|
2000-09-30 20:54:15 +00:00
|
|
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)<BR>
|
2000-08-30 12:44:40 +00:00
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;<BR>
|
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;<BR>
|
2000-09-30 20:54:15 +00:00
|
|
|
#else<BR>
|
|
|
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// workaround for broken reverse_iterator implementations due to no partial specialization</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>
|
2000-08-30 12:44:40 +00:00
|
|
|
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>
|
2000-09-30 20:54:15 +00:00
|
|
|
#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE<BR>
|
2000-08-30 12:44:40 +00:00
|
|
|
private:<BR>
|
2000-09-30 20:54:15 +00:00
|
|
|
#endif<BR>
|
2000-08-30 12:44:40 +00:00
|
|
|
<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>
|