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

Represents a half-open strided range of indices. More...

#include <Slice.hpp>

Public Member Functions

 Slice (std::ptrdiff_t start, std::ptrdiff_t stop, std::ptrdiff_t step=1)
 Creates a half-open strided slice range.
std::ptrdiff_t start () const noexcept
 Returns the first index in the slice.
std::ptrdiff_t stop () const noexcept
 Returns the index one past the end of the slice.
std::ptrdiff_t step () const noexcept
 Returns the stride between selected indices.
std::size_t size () const noexcept
 Returns the number of indices covered by the slice.
bool empty () const noexcept
 Returns whether the slice selects no elements.
bool operator== (const Slice &other) const noexcept
 Compares two slices for identical bounds and step.
bool operator!= (const Slice &other) const noexcept
 Returns whether two slices have different bounds.

Detailed Description

Represents a half-open strided range of indices.

Slice stores an inclusive start, exclusive stop, and non-zero step. It is used by slicing helpers to describe one-dimensional index intervals.

Definition at line 15 of file Slice.hpp.

Constructor & Destructor Documentation

◆ Slice()

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

Creates a half-open strided slice range.

A slice includes the start index and excludes the stop index.

Parameters
startFirst index included in the slice.
stopIndex one past the last included element.
stepNon-zero stride between selected indices.
Exceptions
Exceptions::IndexErrorIf step is zero.

Definition at line 34 of file Slice.hpp.

Member Function Documentation

◆ empty()

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

Returns whether the slice selects no elements.

Returns
true when the slice is empty.

Definition at line 107 of file Slice.hpp.

◆ operator!=()

bool stratax::core::Slice::operator!= ( const Slice & other) const
inlinenodiscardnoexcept

Returns whether two slices have different bounds.

Parameters
otherSlice to compare against.
Returns
true when the slices are not equal.

Definition at line 131 of file Slice.hpp.

◆ operator==()

bool stratax::core::Slice::operator== ( const Slice & other) const
inlinenodiscardnoexcept

Compares two slices for identical bounds and step.

Parameters
otherSlice to compare against.
Returns
true when start, stop, and step all match.

Definition at line 119 of file Slice.hpp.

◆ size()

std::size_t stratax::core::Slice::size ( ) const
inlinenodiscardnoexcept

Returns the number of indices covered by the slice.

Returns
Number of selected indices.

Definition at line 79 of file Slice.hpp.

◆ start()

std::ptrdiff_t stratax::core::Slice::start ( ) const
inlinenodiscardnoexcept

Returns the first index in the slice.

Returns
The inclusive start index.

Definition at line 49 of file Slice.hpp.

◆ step()

std::ptrdiff_t stratax::core::Slice::step ( ) const
inlinenodiscardnoexcept

Returns the stride between selected indices.

Returns
Positive slice step.

Definition at line 69 of file Slice.hpp.

◆ stop()

std::ptrdiff_t stratax::core::Slice::stop ( ) const
inlinenodiscardnoexcept

Returns the index one past the end of the slice.

Returns
The exclusive stop index.

Definition at line 59 of file Slice.hpp.


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