SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sydevs::range Class Reference

A data type which represents a range of array indices along a single dimension. More...

#include <range.h>

Public Member Functions

constexpr range ()
 Constructs a range object representing a sequence that starts at 0 and increases by 1. More...
 
constexpr range (const range &)=default
 Copy constructor. More...
 
rangeoperator= (const range &)=default
 Copy assignment. More...
 
 range (range &&)=default
 Move constructor. More...
 
rangeoperator= (range &&)=default
 Move assignment. More...
 
 ~range ()=default
 Destructor. More...
 
constexpr int64 start () const
 Returns the first index in the sequence. More...
 
constexpr int64 stop () const
 Returns the last possible index in the sequence. More...
 
constexpr int64 stride () const
 Returns the increment between sequence indices. More...
 
constexpr range start_at (int64 limit) const
 Returns a new range object starting at limit. More...
 
constexpr range start_after (int64 limit) const
 Returns a new range object starting immediate after limit. More...
 
constexpr range stop_at (int64 limit) const
 Returns a new range object stopping at limit. More...
 
constexpr range stop_before (int64 limit) const
 Returns a new range object stopping immediate before limit. More...
 
constexpr range stride_by (int64 stride) const
 Returns a new range object incremending by stride. More...
 

Detailed Description

A data type which represents a range of array indices along a single dimension.

A range object can be used to create a slice of a multidimensional array (arraynd) according to an arithmetic sequence of indices along a single dimension.

The arithmetic sequence represented by a range object starts either at or immediately after a start index, increments according to a given stride, and terminates either at or immediately before a stop index. The stop index is permitted to be the maximum 64-bit signed integer (increasing sequences) or the minimum 64-bit signed integer (decreasing sequences), indicating that the sequence continues until the end of the array.

A range object is defined using a chain of member function calls, as demonstrated below.

range() // 0, 1, 2, 3, ...
range().stop_before(7) // 0, 1, 2, 3, 4, 5, 6
range().start_at(2).stop_before(7) // 2, 3, 4, 5, 6
range().start_at(2).stop_before(7).stride_by(2) // 2, 4, 6
range().start_after(7).stride_by(-1) // 6, 5, 4, 3, ...
range().start_after(7).stop_at(0).stride_by(-1) // 6, 5, 4, 3, 2, 1, 0
range().start_after(7).stop_at(0).stride_by(-3) // 6, 3, 0

As in the above examples, it is recommended to use start_at and stop_before for increasing sequences and start_after and stop_at for decreasing sequences. However, as demonstrated below, it is possible to deviate from this convention.

range().start_after(4).stop_before(6) // 5
range().start_at(9).stop_at(1).stride_by_(-5) // 9, 5, 1

Constructor & Destructor Documentation

constexpr sydevs::range::range ( )

Constructs a range object representing a sequence that starts at 0 and increases by 1.

constexpr sydevs::range::range ( const range )
default

Copy constructor.

sydevs::range::range ( range &&  )
default

Move constructor.

sydevs::range::~range ( )
default

Destructor.

Member Function Documentation

range& sydevs::range::operator= ( const range )
default

Copy assignment.

range& sydevs::range::operator= ( range &&  )
default

Move assignment.

constexpr int64 sydevs::range::start ( ) const

Returns the first index in the sequence.

constexpr range sydevs::range::start_after ( int64  limit) const

Returns a new range object starting immediate after limit.

constexpr range sydevs::range::start_at ( int64  limit) const

Returns a new range object starting at limit.

constexpr int64 sydevs::range::stop ( ) const

Returns the last possible index in the sequence.

constexpr range sydevs::range::stop_at ( int64  limit) const

Returns a new range object stopping at limit.

constexpr range sydevs::range::stop_before ( int64  limit) const

Returns a new range object stopping immediate before limit.

constexpr int64 sydevs::range::stride ( ) const

Returns the increment between sequence indices.

constexpr range sydevs::range::stride_by ( int64  stride) const

Returns a new range object incremending by stride.


The documentation for this class was generated from the following file: