src/ds/ndvec/lib.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../../util/alias/others/lib.hpp" | ||
| 4 | |||
| 5 | namespace tifa_libs { | ||
| 6 | |||
| 7 | template <u32 N, class T> | ||
| 8 | struct ndvec : vec<T> { | ||
| 9 | static_assert(N, "N should be positive"); | ||
| 10 | arr<u32, N + 1> idxs; | ||
| 11 | |||
| 12 | template <class... Ts> | ||
| 13 | 40 | CEXPE ndvec(Ts&&... args) NE { resize(args...); } | |
| 14 | template <class... Ts> | ||
| 15 | 40 | CEXP void resize(Ts&&... args) NE { | |
| 16 | static_assert(sizeof...(args) == N); | ||
| 17 | 40 | u32 n = 0; | |
| 18 | 40 | ((idxs[n++] = (u32)args), ...), idxs[N] = 1; | |
| 19 | 40 | inclusive_scan(idxs.rbegin(), idxs.rend(), idxs.rbegin(), std::multiplies<>{}), vec<T>::resize(idxs[0]); | |
| 20 | 40 | } | |
| 21 | template <class... Ts> | ||
| 22 | 207492 | CEXP T& operator()(Ts&&... args) NE { | |
| 23 | static_assert(sizeof...(args) == N); | ||
| 24 | 207492 | u32 n = 0, idx = 0; | |
| 25 | 207492 | ((idx += (u32)args * idxs[++n]), ...); | |
| 26 | 207492 | return this->operator[](idx); | |
| 27 | } | ||
| 28 | template <class... Ts> | ||
| 29 | CEXP T CR operator()(Ts&&... args) CNE { | ||
| 30 | static_assert(sizeof...(args) == N); | ||
| 31 | u32 n = 0, idx = 0; | ||
| 32 | ((idx += (u32)args * idxs[++n]), ...); | ||
| 33 | return this->operator[](idx); | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | } // namespace tifa_libs | ||
| 38 |