Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.

Range and Slice Storage

Range<SizeType,DistanceType>

Description

The class range specifies a range of indicies. The range is a sequence of indices from a start value to stop value. The indices increase by one and exlude the stop value. range can therefore be used to specify ranges of elements from vectors and matrices.

Example

#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;
    }
}

Definition

Defined in the header storage.hpp.

Model of

Reversible Container.

Type requirements

None, except for those imposed by the requirements of Reversible Container.

Public base classes

None.

Members

Member Description
range (size_type start, size_type stop) Constructs a range of indicies from start to stop (excluded) .
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.

Preconditions

Slice<SizeType,DistanceType>

Description

The class slice specifies a 'slice' of indicies. Slices are more general then ranges, the stride allows the sequence of indicies to increase and decrease by the specified amount between element. slice can therefore be used to specify slices of element from vectors and matrices.

Example

#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;
    }
}

Definition

Defined in the header storage.hpp.

Model of

Reversible Container.

Type requirements

None, except for those imposed by the requirements of Reversible Container.

Public base classes

None.

Members

Member Description
slice (size_type start, size_type stride, size_type size) Constructs a slice start,start+stride,start+2*stride... with size elements.
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.

Preconditions