Stratax
0.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
ShapeValidation.hpp
1
#pragma once
2
3
#include <cstddef>
4
5
#include <stratax/core/Exceptions.hpp>
6
7
namespace
stratax::core::validation {
8
19
inline
std::size_t nonnegative_shape_dimension(std::ptrdiff_t value,
const
char
* message)
20
{
21
if
(value < 0)
22
{
23
throw
Exceptions::ShapeError(message);
24
}
25
26
return
static_cast<
std::size_t
>
(value);
27
}
28
39
inline
std::size_t positive_shape_dimension(std::ptrdiff_t value,
const
char
* message)
40
{
41
if
(value <= 0)
42
{
43
throw
Exceptions::ShapeError(message);
44
}
45
46
return
static_cast<
std::size_t
>
(value);
47
}
48
57
inline
void
require_positive_shape_dimension(std::size_t value,
const
char
* message)
58
{
59
if
(value == 0)
60
{
61
throw
Exceptions::ShapeError(message);
62
}
63
}
64
73
template
<
typename
Lhs,
typename
Rhs>
74
[[nodiscard]]
bool
same_shape(
const
Lhs& lhs,
const
Rhs& rhs)
75
{
76
return
lhs.size() == rhs.size() && lhs.shape() == rhs.shape();
77
}
78
88
template
<
typename
Lhs,
typename
Rhs>
89
void
require_same_shape(
const
Lhs& lhs,
const
Rhs& rhs,
const
char
* message)
90
{
91
if
(!same_shape(lhs, rhs))
92
{
93
throw
Exceptions::ShapeError(message);
94
}
95
}
96
106
inline
void
require_equal_size(std::size_t lhs, std::size_t rhs,
const
char
* message)
107
{
108
if
(lhs != rhs)
109
{
110
throw
Exceptions::ShapeError(message);
111
}
112
}
113
114
}
include
stratax
core
validation
ShapeValidation.hpp
Generated by
1.17.0