Stratax
Scientific computing containers and operations
Loading...
Searching...
No Matches
stratax::core::Slice Class Reference

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

#include <Slice.hpp>

Public Member Functions

 Slice (std::size_t start, std::size_t stop)
 Creates a half-open slice range.
std::size_t start () const noexcept
 Returns the first index in the slice.
std::size_t stop () const noexcept
 Returns the index one past the end of the slice.
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.
bool operator!= (const Slice &other) const noexcept
 Returns whether two slices have different bounds.

Detailed Description

Represents a half-open range of indices.

Slice stores an inclusive start and exclusive stop bound and 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::size_t start,
std::size_t stop )
inline

Creates a half-open 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.
Exceptions
Exceptions::IndexErrorIf start is greater than stop.

Definition at line 32 of file Slice.hpp.

References start(), and stop().

Referenced by operator!=(), and operator==().

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 76 of file Slice.hpp.

References size().

◆ 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 100 of file Slice.hpp.

References Slice().

◆ operator==()

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

Compares two slices for identical bounds.

Parameters
otherSlice to compare against.
Returns
true when both the start and stop bounds match.

Definition at line 88 of file Slice.hpp.

References Slice().

◆ 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 66 of file Slice.hpp.

Referenced by empty(), and slice().

◆ start()

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

Returns the first index in the slice.

Returns
The inclusive start index.

Definition at line 46 of file Slice.hpp.

Referenced by Slice(), and slice().

◆ stop()

std::size_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 56 of file Slice.hpp.

Referenced by Slice(), and slice().


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