Add util::array mirroring
This commit is contained in:
parent
1b8ef017ad
commit
d88799f308
1 changed files with 15 additions and 0 deletions
|
|
@ -376,6 +376,21 @@ namespace psemek::util
|
|||
data_ = std::move(data);
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
void mirror(array<T, N> & a, std::size_t i)
|
||||
{
|
||||
assert(i < N);
|
||||
|
||||
auto const s = a.dim(i);
|
||||
for (auto idx : a.indices())
|
||||
{
|
||||
auto jdx = idx;
|
||||
jdx[i] = s - 1 - jdx[i];
|
||||
if (jdx[i] < idx[i])
|
||||
std::swap(a(idx), a(jdx));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::size_t N>
|
||||
auto map(F && f, array<T, N> const & a)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue