Stratax 0.4.0rc1
Loading...
Searching...
No Matches
Normalize.hpp File Reference

Checked signed index normalization. More...

#include <cstddef>
#include <stratax/exceptions/Exceptions.hpp>
Include dependency graph for Normalize.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

using stratax::indexing::size_type = std::size_t
 Unsigned extent and normalized-index type.
 
using stratax::indexing::difference_type = std::ptrdiff_t
 Signed type for Python-style indices.
 

Functions

size_type stratax::indexing::normalize_index (difference_type index, size_type size)
 Validates a signed index and converts it to a non-negative offset.
 

Detailed Description

Checked signed index normalization.

Definition in file Normalize.hpp.

Typedef Documentation

◆ difference_type

typedef std::ptrdiff_t stratax::indexing::difference_type

Signed type for Python-style indices.

Signed type used for normalized slice positions and steps.

Definition at line 15 of file Normalize.hpp.

◆ size_type

typedef std::size_t stratax::indexing::size_type

Unsigned extent and normalized-index type.

Unsigned type used for extents, counts, and flat offsets.

Definition at line 13 of file Normalize.hpp.

Function Documentation

◆ normalize_index()

size_type stratax::indexing::normalize_index ( difference_type  index,
size_type  size 
)
inline

Validates a signed index and converts it to a non-negative offset.

Parameters
indexIndex in [-size, size); negative values count from the end.
sizeNumber of elements in the indexed dimension.
Returns
The non-negative index; -1 selects size - 1 when nonempty.
Exceptions
Exceptions::IndexErrorIf the index is out of bounds, including every index when size is zero.
Note
The minimum representable signed index is handled without signed overflow.
Complexity
O(1).

Definition at line 26 of file Normalize.hpp.