6#include <stratax/exceptions/Exceptions.hpp>
8using size_type = std::size_t;
9using difference_type = std::ptrdiff_t;
11namespace stratax::indexing {
13inline size_type normalize_index(
14 difference_type index,
20 const size_type normalized =
static_cast<size_type
>(index);
22 if (normalized >= size)
24 throw Exceptions::IndexError(
"Index " + std::to_string(index) +
25 " is out of bounds for array with size " + std::to_string(size) +
".");
31 const size_type magnitude =
32 static_cast<size_type
>(-(index + 1)) + 1;
36 throw Exceptions::IndexError(
"Index " + std::to_string(index) +
37 " is out of bounds for array with size " + std::to_string(size) +
".");
40 return size - magnitude;