Stratax 0.3.1
Loading...
Searching...
No Matches
stratax::core::Slice Class Reference

Describes a signed, strided half-open index range. More...

#include <Slice.hpp>

Public Types

using size_type = std::size_t
 Unsigned type used for the number of selected indices.
 
using difference_type = std::ptrdiff_t
 Signed type used for bounds and step values.
 

Public Member Functions

 Slice (difference_type start, difference_type stop, difference_type step=1)
 Constructs a slice from raw half-open bounds and a step.
 
difference_type start () const noexcept
 Returns the raw inclusive start bound.
 
difference_type stop () const noexcept
 Returns the raw exclusive stop bound.
 
difference_type step () const noexcept
 Returns the nonzero signed step.
 
size_type size () const noexcept
 Returns the number of indices described by the raw range.
 
bool empty () const noexcept
 Reports whether the raw range selects no indices.
 
bool operator== (const Slice &other) const noexcept
 Compares two slices by their stored bounds and step.
 

Detailed Description

Describes a signed, strided half-open index range.

Slice stores raw [start, stop) bounds and a nonzero step. A positive step selects values while they are less than stop; a negative step selects values while they are greater than stop. Bounds are not normalized or clamped by this class because normalization depends on the dimension being sliced.

Example
const stratax::core::Slice forward{1, 8, 2};
// Selects 1, 3, 5, 7; forward.size() == 4.
const stratax::core::Slice reverse{7, 0, -2};
// Selects 7, 5, 3, 1; reverse.size() == 4.
Describes a signed, strided half-open index range.
Definition Slice.hpp:31
See also
stratax::indexing::slice

Definition at line 30 of file Slice.hpp.

Member Typedef Documentation

◆ difference_type

using stratax::core::Slice::difference_type = std::ptrdiff_t

Signed type used for bounds and step values.

Definition at line 36 of file Slice.hpp.

◆ size_type

using stratax::core::Slice::size_type = std::size_t

Unsigned type used for the number of selected indices.

Definition at line 34 of file Slice.hpp.

Constructor & Destructor Documentation

◆ Slice()

stratax::core::Slice::Slice ( difference_type  start,
difference_type  stop,
difference_type  step = 1 
)
inline

Constructs a slice from raw half-open bounds and a step.

The values are stored unchanged. In particular, negative bounds are not converted relative to a container extent during construction.

Parameters
startFirst index in the range when the range is non-empty.
stopExclusive boundary that terminates the range.
stepNonzero increment between consecutive indices.
Exceptions
Exceptions::IndexErrorIf step is zero.
Complexity
O(1).

Definition at line 56 of file Slice.hpp.

Member Function Documentation

◆ empty()

bool stratax::core::Slice::empty ( ) const
inlinenoexcept

Reports whether the raw range selects no indices.

Complexity
O(1).

Definition at line 111 of file Slice.hpp.

◆ operator==()

bool stratax::core::Slice::operator== ( const Slice other) const
inlinenoexcept

Compares two slices by their stored bounds and step.

Parameters
otherSlice to compare with this slice.
Returns
true when start, stop, and step are all equal.
Complexity
O(1).

Definition at line 119 of file Slice.hpp.

◆ size()

size_type stratax::core::Slice::size ( ) const
inlinenoexcept

Returns the number of indices described by the raw range.

A positive-step slice is empty when start() >= stop(). A negative-step slice is empty when start() <= stop(). Otherwise the result is the ceiling of the directed distance divided by the absolute step.

This calculation does not normalize bounds against a container extent.

Returns
Number of generated indices.
Precondition
Intermediate signed distance and rounding arithmetic must be representable by difference_type.
Complexity
O(1).

Definition at line 87 of file Slice.hpp.

◆ start()

difference_type stratax::core::Slice::start ( ) const
inlinenoexcept

Returns the raw inclusive start bound.

Complexity
O(1).

Definition at line 67 of file Slice.hpp.

◆ step()

difference_type stratax::core::Slice::step ( ) const
inlinenoexcept

Returns the nonzero signed step.

Complexity
O(1).

Definition at line 71 of file Slice.hpp.

◆ stop()

difference_type stratax::core::Slice::stop ( ) const
inlinenoexcept

Returns the raw exclusive stop bound.

Complexity
O(1).

Definition at line 69 of file Slice.hpp.


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