Stratax 0.2.0
Loading...
Searching...
No Matches
stratax::core::validation Namespace Reference

Functions

std::size_t nonnegative_size (std::ptrdiff_t value, const char *message)
 Converts a signed value to std::size_t after rejecting negatives.
void require_rank (std::size_t actual, std::size_t expected, const char *message)
 Requires a rank value to match an expected rank.
template<typename Ranked>
requires requires(const Ranked& object) { object.rank(); }
const Ranked & require_rank (const Ranked &object, std::size_t expected, const char *message)
 Requires an object with rank() to match an expected rank.
std::size_t checked_multiply (std::size_t lhs, std::size_t rhs, const char *message)
 Multiplies two sizes while checking for overflow.
std::size_t checked_add (std::size_t lhs, std::size_t rhs, const char *message)
 Adds two sizes while checking for overflow.
std::size_t nonnegative_index (std::ptrdiff_t value, const char *message)
 Converts a signed index to std::size_t after rejecting negatives.
std::size_t normalize_index (std::ptrdiff_t value, std::size_t size, const char *message)
 Normalizes a potentially negative index against a container size.
void require_index (std::size_t index, std::size_t size, const char *message)
 Requires an index to be less than a size.
void require_at_most (std::size_t value, std::size_t upper, const char *message)
 Requires a value to be less than or equal to an upper bound.
std::size_t nonnegative_shape_dimension (std::ptrdiff_t value, const char *message)
 Converts a signed shape dimension to std::size_t after rejecting negatives.
std::size_t positive_shape_dimension (std::ptrdiff_t value, const char *message)
 Converts a signed shape dimension to std::size_t after requiring it to be positive.
void require_positive_shape_dimension (std::size_t value, const char *message)
 Requires an unsigned shape dimension to be positive.
template<typename Lhs, typename Rhs>
bool same_shape (const Lhs &lhs, const Rhs &rhs)
 Returns whether two array-like objects have identical size and shape.
template<typename Lhs, typename Rhs>
void require_same_shape (const Lhs &lhs, const Rhs &rhs, const char *message)
 Requires two array-like objects to have identical size and shape.
void require_equal_size (std::size_t lhs, std::size_t rhs, const char *message)
 Requires two sizes to be equal.
template<typename Actual, typename Expected>
void require_type (const char *message)
 Requires a type to exactly match an expected type after cv/ref removal.
template<typename T>
void require_numeric_type (const char *message)
 Requires a type to satisfy Stratax's numeric type rules.
template<typename Lhs, typename Rhs>
requires requires { typename Lhs::value_type; typename Rhs::value_type; }
void require_same_value_type (const Lhs &lhs, const Rhs &rhs, const char *message)
 Requires two array-like objects to have the same value type.

Function Documentation

◆ checked_add()

std::size_t stratax::core::validation::checked_add ( std::size_t lhs,
std::size_t rhs,
const char * message )
inline

Adds two sizes while checking for overflow.

Parameters
lhsLeft operand.
rhsRight operand.
messageError message used on overflow.
Returns
Sum of lhs and rhs.
Exceptions
Exceptions::DimensionErrorIf the addition would overflow.

Definition at line 104 of file DimensionValidation.hpp.

◆ checked_multiply()

std::size_t stratax::core::validation::checked_multiply ( std::size_t lhs,
std::size_t rhs,
const char * message )
inline

Multiplies two sizes while checking for overflow.

Parameters
lhsLeft operand.
rhsRight operand.
messageError message used on overflow.
Returns
Product of lhs and rhs.
Exceptions
Exceptions::DimensionErrorIf the multiplication would overflow.

Definition at line 80 of file DimensionValidation.hpp.

◆ nonnegative_index()

std::size_t stratax::core::validation::nonnegative_index ( std::ptrdiff_t value,
const char * message )
inline

Converts a signed index to std::size_t after rejecting negatives.

Parameters
valueSigned index to validate.
messageError message used when value is negative.
Returns
value converted to std::size_t.
Exceptions
Exceptions::IndexErrorIf value is negative.

Definition at line 20 of file IndexValidation.hpp.

◆ nonnegative_shape_dimension()

std::size_t stratax::core::validation::nonnegative_shape_dimension ( std::ptrdiff_t value,
const char * message )
inline

Converts a signed shape dimension to std::size_t after rejecting negatives.

Parameters
valueSigned dimension to validate.
messageError message used when value is negative.
Returns
value converted to std::size_t.
Exceptions
Exceptions::ShapeErrorIf value is negative.

Definition at line 19 of file ShapeValidation.hpp.

◆ nonnegative_size()

std::size_t stratax::core::validation::nonnegative_size ( std::ptrdiff_t value,
const char * message )
inline

Converts a signed value to std::size_t after rejecting negatives.

Parameters
valueSigned value to validate.
messageError message used when value is negative.
Returns
value converted to std::size_t.
Exceptions
Exceptions::DimensionErrorIf value is negative.

Definition at line 20 of file DimensionValidation.hpp.

◆ normalize_index()

std::size_t stratax::core::validation::normalize_index ( std::ptrdiff_t value,
std::size_t size,
const char * message )
inline

Normalizes a potentially negative index against a container size.

Negative indices are interpreted from the end of the range, like Python.

Parameters
valueSigned index value.
sizeContainer size used for normalization.
messageError message used when the normalized index is out of bounds.
Returns
Normalized non-negative index.
Exceptions
Exceptions::IndexErrorIf the index is out of bounds.

Definition at line 43 of file IndexValidation.hpp.

◆ positive_shape_dimension()

std::size_t stratax::core::validation::positive_shape_dimension ( std::ptrdiff_t value,
const char * message )
inline

Converts a signed shape dimension to std::size_t after requiring it to be positive.

Parameters
valueSigned dimension to validate.
messageError message used when value <= 0.
Returns
value converted to std::size_t.
Exceptions
Exceptions::ShapeErrorIf value <= 0.

Definition at line 39 of file ShapeValidation.hpp.

◆ require_at_most()

void stratax::core::validation::require_at_most ( std::size_t value,
std::size_t upper,
const char * message )
inline

Requires a value to be less than or equal to an upper bound.

This is useful for half-open range stops, where stop == size is valid.

Parameters
valueValue to validate.
upperInclusive upper bound.
messageError message used when value > upper.
Exceptions
Exceptions::IndexErrorIf value > upper.

Definition at line 94 of file IndexValidation.hpp.

◆ require_equal_size()

void stratax::core::validation::require_equal_size ( std::size_t lhs,
std::size_t rhs,
const char * message )
inline

Requires two sizes to be equal.

Parameters
lhsLeft size.
rhsRight size.
messageError message used on mismatch.
Exceptions
Exceptions::ShapeErrorIf the sizes differ.

Definition at line 106 of file ShapeValidation.hpp.

◆ require_index()

void stratax::core::validation::require_index ( std::size_t index,
std::size_t size,
const char * message )
inline

Requires an index to be less than a size.

Parameters
indexIndex to validate.
sizeExclusive upper bound.
messageError message used when out of bounds.
Exceptions
Exceptions::IndexErrorIf index >= size.

Definition at line 75 of file IndexValidation.hpp.

◆ require_numeric_type()

template<typename T>
void stratax::core::validation::require_numeric_type ( const char * message)

Requires a type to satisfy Stratax's numeric type rules.

Template Parameters
TType being validated.
Parameters
messageError message used when the type is unsupported.
Exceptions
Exceptions::TypeErrorIf T is not a supported numeric type.

Definition at line 37 of file TypeValidation.hpp.

◆ require_positive_shape_dimension()

void stratax::core::validation::require_positive_shape_dimension ( std::size_t value,
const char * message )
inline

Requires an unsigned shape dimension to be positive.

Parameters
valueDimension to validate.
messageError message used when value == 0.
Exceptions
Exceptions::ShapeErrorIf value == 0.

Definition at line 57 of file ShapeValidation.hpp.

◆ require_rank() [1/2]

template<typename Ranked>
requires requires(const Ranked& object) { object.rank(); }
const Ranked & stratax::core::validation::require_rank ( const Ranked & object,
std::size_t expected,
const char * message )

Requires an object with rank() to match an expected rank.

Parameters
objectObject to validate.
expectedRequired rank.
messageError message used on mismatch.
Returns
Reference to object.
Exceptions
Exceptions::DimensionErrorIf the object rank differs.

Definition at line 63 of file DimensionValidation.hpp.

◆ require_rank() [2/2]

void stratax::core::validation::require_rank ( std::size_t actual,
std::size_t expected,
const char * message )
inline

Requires a rank value to match an expected rank.

Parameters
actualActual rank.
expectedRequired rank.
messageError message used on mismatch.
Exceptions
Exceptions::DimensionErrorIf the ranks differ.

Definition at line 39 of file DimensionValidation.hpp.

◆ require_same_shape()

template<typename Lhs, typename Rhs>
void stratax::core::validation::require_same_shape ( const Lhs & lhs,
const Rhs & rhs,
const char * message )

Requires two array-like objects to have identical size and shape.

Parameters
lhsLeft object.
rhsRight object.
messageError message used on mismatch.
Exceptions
Exceptions::ShapeErrorIf size or shape differ.

Definition at line 89 of file ShapeValidation.hpp.

◆ require_same_value_type()

template<typename Lhs, typename Rhs>
requires requires { typename Lhs::value_type; typename Rhs::value_type; }
void stratax::core::validation::require_same_value_type ( const Lhs & lhs,
const Rhs & rhs,
const char * message )

Requires two array-like objects to have the same value type.

Parameters
lhsLeft object.
rhsRight object.
messageError message used on mismatch.
Exceptions
Exceptions::TypeErrorIf the objects' normalized value_types differ.

Definition at line 60 of file TypeValidation.hpp.

◆ require_type()

template<typename Actual, typename Expected>
void stratax::core::validation::require_type ( const char * message)

Requires a type to exactly match an expected type after cv/ref removal.

Template Parameters
ActualType being validated.
ExpectedRequired type.
Parameters
messageError message used on mismatch.
Exceptions
Exceptions::TypeErrorIf the normalized types differ.

Definition at line 20 of file TypeValidation.hpp.

◆ same_shape()

template<typename Lhs, typename Rhs>
bool stratax::core::validation::same_shape ( const Lhs & lhs,
const Rhs & rhs )
nodiscard

Returns whether two array-like objects have identical size and shape.

Parameters
lhsLeft object.
rhsRight object.
Returns
true if size and shape match.

Definition at line 74 of file ShapeValidation.hpp.