Add util::spatial_array asserts in case of wrong number of indices
This commit is contained in:
parent
2421dee3b7
commit
8f6bd5b5fc
1 changed files with 12 additions and 0 deletions
|
|
@ -50,6 +50,8 @@ namespace psemek::util
|
||||||
template <typename ... Ix>
|
template <typename ... Ix>
|
||||||
T & spatial_array<T, N, Index>::get(Ix ... index)
|
T & spatial_array<T, N, Index>::get(Ix ... index)
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof...(Ix) == N, "wrong number of indices");
|
||||||
|
|
||||||
if (!contains(index...))
|
if (!contains(index...))
|
||||||
expand(index...);
|
expand(index...);
|
||||||
|
|
||||||
|
|
@ -63,6 +65,8 @@ namespace psemek::util
|
||||||
template <typename ... Ix>
|
template <typename ... Ix>
|
||||||
T * spatial_array<T, N, Index>::get_if(Ix ... index)
|
T * spatial_array<T, N, Index>::get_if(Ix ... index)
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof...(Ix) == N, "wrong number of indices");
|
||||||
|
|
||||||
if (!contains(index...))
|
if (!contains(index...))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
|
@ -76,6 +80,8 @@ namespace psemek::util
|
||||||
template <typename ... Ix>
|
template <typename ... Ix>
|
||||||
T const * spatial_array<T, N, Index>::get_if(Ix ... index) const
|
T const * spatial_array<T, N, Index>::get_if(Ix ... index) const
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof...(Ix) == N, "wrong number of indices");
|
||||||
|
|
||||||
if (!contains(index...))
|
if (!contains(index...))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
|
@ -89,6 +95,8 @@ namespace psemek::util
|
||||||
template <typename ... Ix>
|
template <typename ... Ix>
|
||||||
T const & spatial_array<T, N, Index>::at(Ix ... index) const
|
T const & spatial_array<T, N, Index>::at(Ix ... index) const
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof...(Ix) == N, "wrong number of indices");
|
||||||
|
|
||||||
auto const size = array_.dims();
|
auto const size = array_.dims();
|
||||||
Index ix[N] {index...};
|
Index ix[N] {index...};
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
|
@ -104,6 +112,8 @@ namespace psemek::util
|
||||||
template <typename ... Ix>
|
template <typename ... Ix>
|
||||||
bool spatial_array<T, N, Index>::contains(Ix ... index) const
|
bool spatial_array<T, N, Index>::contains(Ix ... index) const
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof...(Ix) == N, "wrong number of indices");
|
||||||
|
|
||||||
auto const size = array_.dims();
|
auto const size = array_.dims();
|
||||||
Index ix[N] {index...};
|
Index ix[N] {index...};
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
|
@ -116,6 +126,8 @@ namespace psemek::util
|
||||||
template <typename ... Ix>
|
template <typename ... Ix>
|
||||||
void spatial_array<T, N, Index>::expand(Ix ... index)
|
void spatial_array<T, N, Index>::expand(Ix ... index)
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof...(Ix) == N, "wrong number of indices");
|
||||||
|
|
||||||
Index ix[N] {index...};
|
Index ix[N] {index...};
|
||||||
|
|
||||||
if (array_.empty())
|
if (array_.empty())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue