The templated class unbounded_array<T>
implements a
simple C-like array using allocation via new/delete
.
#include <boost/numeric/ublas/storage.hpp>
int main () {
using namespace boost::numeric::ublas;
unbounded_array<double> a (3);
for (unsigned i = 0; i < a.size (); ++ i) {
a [i] = i;
std::cout << a [i] << std::endl;
}
}
Defined in the header storage.hpp.
Parameter | Description | Default |
---|---|---|
T |
The type of object stored in the array. |
Random Access Container.
None, except for those imposed by the requirements of Random Access Container.
None.
Member | Description |
---|---|
unbounded_array () |
Allocates an uninitialized unbounded_array that
holds at most zero elements. |
unbounded_array (size_type size) |
Allocates an uninitialized unbounded_array that
holds at most size elements. |
unbounded_array (const unbounded_array &a) |
The copy constructor. |
~unbounded_array () |
Deallocates the unbounded_array itself. |
void resize (size_type size) |
Reallocates an unbounded_array to hold at
most size elements. The content of the unbounded_array
is not preserved. |
size_type size () const |
Returns the size of the unbounded_array . |
const_reference operator [] (size_type i) const |
Returns a const reference of the i -th
element. |
reference operator [] (size_type i) |
Returns a reference of the i -th element. |
unbounded_array &operator = (const unbounded_array
&a) |
The assignment operator. |
unbounded_array &assign_temporary (unbounded_array
&a) |
Assigns a temporary. May change the array a . |
void swap (unbounded_array &a) |
Swaps the contents of the arrays. |
pointer insert (pointer it, const value_type &t) |
Inserts the value t at it . |
void erase (pointer it) |
Erases the value at it . |
void clear () |
Clears the array. |
const_iterator begin () const |
Returns a const_iterator pointing to the beginning
of the unbounded_array . |
const_iterator end () const |
Returns a const_iterator pointing to the end
of the unbounded_array . |
iterator begin () |
Returns a iterator pointing to the beginning
of the unbounded_array . |
iterator end () |
Returns a iterator pointing to the end of
the unbounded_array . |
const_reverse_iterator rbegin () const |
Returns a const_reverse_iterator pointing to
the beginning of the reversed unbounded_array . |
const_reverse_iterator rend () const |
Returns a const_reverse_iterator pointing to
the end of the reversed unbounded_array . |
reverse_iterator rbegin () |
Returns a reverse_iterator pointing to the
beginning of the reversed unbounded_array . |
reverse_iterator rend () |
Returns a reverse_iterator pointing to the
end of the reversed unbounded_array . |
// Unbounded array
template<class T>
class unbounded_array {
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T value_type;
typedef const T &const_reference;
typedef T &reference;
typedef const T *const_pointer;
typedef T *pointer;
// Construction and destruction
unbounded_array ();
unbounded_array (size_type size);
unbounded_array (const unbounded_array &a);
~unbounded_array ();
// Resizing
void resize (size_type size);
size_type size () const;
// Element access
const_reference operator [] (size_type i) const;
reference operator [] (size_type i);
// Assignment
unbounded_array &operator = (const unbounded_array &a);
unbounded_array &assign_temporary (unbounded_array &a);
// Swapping
void swap (unbounded_array &a);
friend void swap (unbounded_array &a1, unbounded_array &a2);
// Element insertion and deletion
pointer insert (pointer it, const value_type &t);
void insert (pointer it, pointer it1, pointer it2);
void erase (pointer it);
void erase (pointer it1, pointer it2);
void clear ();
// Iterators simply are pointers.
typedef const_pointer const_iterator;
const_iterator begin () const;
const_iterator end () const;
typedef pointer iterator;
iterator begin ();
iterator end ();
// Reverse iterators
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
typedef std::reverse_iterator<iterator> reverse_iterator;
reverse_iterator rbegin ();
reverse_iterator rend ();
};
template<class T>
unbounded_array<T> &assign_temporary (unbounded_array<T> &a1, unbounded_array<T> &a2);
The templated class bounded_array<T, N>
implements
a simple C-like array.
#include <boost/numeric/ublas/storage.hpp>
int main () {
using namespace boost::numeric::ublas;
bounded_array<double, 3> a (3);
for (unsigned i = 0; i < a.size (); ++ i) {
a [i] = i;
std::cout << a [i] << std::endl;
}
}
Defined in the header storage.hpp.
Parameter | Description | Default |
---|---|---|
T |
The type of object stored in the array. | |
N |
The allocation size of the array. |
Random Access Container.
None, except for those imposed by the requirements of Random Access Container.
None.
Member | Description |
---|---|
bounded_array () |
Allocates an uninitialized bounded_array that
holds at most zero elements. |
bounded_array (size_type size) |
Allocates an uninitialized bounded_array that
holds at most size elements. |
bounded_array (const bounded_array &a) |
The copy constructor. |
~bounded_array () |
Deallocates the bounded_array itself. |
void resize (size_type size) |
Reallocates a bounded_array to hold at most
size elements. The content of the bounded_array
is preserved. |
size_type size () const |
Returns the size of the bounded_array . |
const_reference operator [] (size_type i) const |
Returns a const reference of the i -th
element. |
reference operator [] (size_type i) |
Returns a reference of the i -th element. |
bounded_array &operator = (const bounded_array
&a) |
The assignment operator. |
bounded_array &assign_temporary (bounded_array
&a) |
Assigns a temporary. May change the array a . |
void swap (bounded_array &a) |
Swaps the contents of the arrays. |
pointer insert (pointer it, const value_type &t) |
Inserts the value t at it . |
void erase (pointer it) |
Erases the value at it . |
void clear () |
Clears the array. |
const_iterator begin () const |
Returns a const_iterator pointing to the beginning
of the bounded_array . |
const_iterator end () const |
Returns a const_iterator pointing to the end
of the bounded_array . |
iterator begin () |
Returns a iterator pointing to the beginning
of the bounded_array . |
iterator end () |
Returns a iterator pointing to the end of
the bounded_array . |
const_reverse_iterator rbegin () const |
Returns a const_reverse_iterator pointing to
the beginning of the reversed bounded_array . |
const_reverse_iterator rend () const |
Returns a const_reverse_iterator pointing to
the end of the reversed bounded_array . |
reverse_iterator rbegin () |
Returns a reverse_iterator pointing to the
beginning of the reversed bounded_array . |
reverse_iterator rend () |
Returns a reverse_iterator pointing to the
end of the reversed bounded_array . |
// Bounded array
template<class T, std::size_t N>
class bounded_array {
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T value_type;
typedef const T &const_reference;
typedef T &reference;
typedef const T *const_pointer;
typedef T *pointer;
// Construction and destruction
bounded_array ();
bounded_array (size_type size);
bounded_array (const bounded_array &a);
// Resizing
void resize (size_type size);
size_type size () const;
// Element access
const_reference operator [] (size_type i) const;
reference operator [] (size_type i);
// Assignment
bounded_array &operator = (const bounded_array &a);
bounded_array &assign_temporary (bounded_array &a);
// Swapping
void swap (bounded_array &a);
friend void swap (bounded_array &a1, bounded_array &a2);
// Element insertion and deletion
pointer insert (pointer it, const value_type &t);
void insert (pointer it, pointer it1, pointer it2);
void erase (pointer it);
void erase (pointer it1, pointer it2);
void clear ();
// Iterators simply are pointers.
typedef const_pointer const_iterator;
const_iterator begin () const;
const_iterator end () const;
typedef pointer iterator;
iterator begin ();
iterator end ();
// Reverse iterators
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
typedef std::reverse_iterator<iterator, value_type, reference> reverse_iterator;
reverse_iterator rbegin ();
reverse_iterator rend ();
};
template<class T, std::size_t N>
bounded_array<T, N> &assign_temporary (bounded_array<T, N> &a1, bounded_array<T, N> &a2);
The class range
implements base functionality needed to address
ranges of vectors and matrices.
#include <boost/numeric/ublas/storage.hpp>
int main () {
using namespace boost::numeric::ublas;
range r (0, 3);
for (unsigned i = 0; i < r.size (); ++ i) {
std::cout << r (i) << std::endl;
}
}
Defined in the header storage.hpp.
Reversible Container.
None, except for those imposed by the requirements of Reversible Container.
None.
Member | Description |
---|---|
range (size_type start, size_type stop) |
Constructs a range from start to stop
. |
size_type start () const |
Returns the beginning of the range . |
size_type size () const |
Returns the size of the range . |
const_reference operator [] (size_type i) const |
Returns the value start + i of the i -th
element. |
range compose (const range &r) const |
Returns the composite range from start + r.start ()
to start + r.start () + r.size () . |
bool operator == (const range &r) const |
Tests two ranges for equality. |
bool operator != (const range &r) const |
Tests two ranges for inequality. |
const_iterator begin () const |
Returns a const_iterator pointing to the beginning
of the range . |
const_iterator end () const |
Returns a const_iterator pointing to the end
of the range . |
const_reverse_iterator rbegin () const |
Returns a const_reverse_iterator pointing to
the beginning of the reversed range . |
const_reverse_iterator rend () const |
Returns a const_reverse_iterator pointing to
the end of the reversed range . |
// Range class
class range {
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef difference_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
typedef const difference_type *const_pointer;
typedef difference_type *pointer;
typedef size_type const_iterator_type;
// Construction and destruction
range ();
range (size_type start, size_type stop);
size_type start () const;
size_type size () const;
// Element access
const_reference operator () (size_type i) const;
// Composition
range compose (const range &r) const;
// Comparison
bool operator == (const range &r) const;
bool operator != (const range &r) const;
// Iterator simply is a index.
class const_iterator:
public container_const_reference<range>,
public random_access_iterator_base<const_iterator, value_type> {
public:
// Construction and destruction
const_iterator ();
const_iterator (const range &r, const const_iterator_type &it);
// Arithmetic
const_iterator &operator ++ ();
const_iterator &operator -- ();
const_iterator &operator += (difference_type n);
const_iterator &operator -= (difference_type n);
difference_type operator - (const const_iterator &it) const;
// Dereference
const_reference operator * () const;
// Index
size_type index () const;
// Assignment
const_iterator &operator = (const const_iterator &it);
// Comparison
bool operator == (const const_iterator &it) const;
};
const_iterator begin () const;
const_iterator end () const;
// Reverse iterator
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
};
The class slice
implements base functionality needed to address
slices of vectors and matrices.
#include <boost/numeric/ublas/storage.hpp>
int main () {
using namespace boost::numeric::ublas;
slice s (0, 1, 3);
for (unsigned i = 0; i < s.size (); ++ i) {
std::cout << s (i) << std::endl;
}
}
Defined in the header storage.hpp.
Reversible Container.
None, except for those imposed by the requirements of Reversible Container.
None.
Member | Description |
---|---|
slice (size_type start, size_type stride, size_type
size) |
Constructs a slice from start to start
+ size with stride stride . |
size_type start () const |
Returns the beginning of the slice . |
size_type stride () const |
Returns the stride of the slice . |
size_type size () const |
Returns the size of the slice . |
const_reference operator [] (size_type i) const |
Returns the value start + i * stride of the
i -th element. |
slice compose (const range &r) const |
Returns the composite slice from start + stride *
r.start () to start + stride * (r.start () + r.size ())
with stride stride . |
slice compose (const slice &s) const |
Returns the composite slice from start + stride *
s.start () to start + stride * s.stride () * (s.start
() + s.size ()) with stride stride * s.stride ()
. |
bool operator == (const slice &s) const |
Tests two slices for equality. |
bool operator != (const slice &s) const |
Tests two slices for inequality. |
const_iterator begin () const |
Returns a const_iterator pointing to the beginning
of the slice . |
const_iterator end () const |
Returns a const_iterator pointing to the end
of the slice . |
const_reverse_iterator rbegin () const |
Returns a const_reverse_iterator pointing to
the beginning of the reversed slice . |
const_reverse_iterator rend () const |
Returns a const_reverse_iterator pointing to
the end of the reversed slice . |
// Slice class
class slice {
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef difference_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
typedef const difference_type *const_pointer;
typedef difference_type *pointer;
typedef size_type const_iterator_type;
// Construction and destruction
slice ();
slice (size_type start, size_type stride, size_type size);
size_type start () const;
size_type stride () const;
size_type size () const;
// Element access
const_reference operator () (size_type i) const;
// Composition
slice compose (const range &r) const;
slice compose (const slice &s) const;
// Comparison
bool operator == (const slice &s) const;
bool operator != (const slice &s) const;
// Iterator simply is a index.
class const_iterator:
public container_const_reference<slice>,
public random_access_iterator_base<const_iterator, value_type> {
public:
// Construction and destruction
const_iterator ();
const_iterator (const slice &s, const const_iterator_type &it);
// Arithmetic
const_iterator &operator ++ ();
const_iterator &operator -- ();
const_iterator &operator += (difference_type n);
const_iterator &operator -= (difference_type n);
difference_type operator - (const const_iterator &it) const;
// Dereference
const_reference operator * () const;
// Index
size_type index () const;
// Assignment
const_iterator &operator = (const const_iterator &it);
// Comparison
bool operator == (const const_iterator &it) const;
};
const_iterator begin () const;
const_iterator end () const;
// Reverse iterator
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
const_reverse_iterator rbegin () const;
const_reverse_iterator rend () const;
};
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Permission to copy, use, modify, sell and distribute this document is granted
provided this copyright notice appears in all copies. This document is provided
``as is'' without express or implied warranty, and with no claim as to its
suitability for any purpose.
Last revised: 1/15/2003