9template <
typename... Inds>
10constexpr std::size_t
mul(Inds... inds)
noexcept {
11 return (std::size_t(inds) * ...);
15template <std::
size_t N>
16constexpr std::size_t
mul(
const std::array<std::size_t, N>& arr)
noexcept {
17 if constexpr (N == 0) {
21 for (
auto i : arr) out *= i;
27template <
typename... Inds>
29 std::array<std::size_t,
sizeof...(Inds)> out{};
30 std::array<std::size_t,
sizeof...(Inds)> arr{std::size_t(inds)...};
31 std::size_t i =
sizeof...(Inds)-1;
33 while (i <
sizeof...(Inds)) {
42template <std::
size_t N>
44 std::array<std::size_t, N> inds)
noexcept {
46 for (std::size_t i=0; i<N; i++) pos += gridsize[i] * inds[i];
51template <
typename b, std::
size_t n>
60 [[nodiscard]] std::size_t
size() const noexcept {
return ptr.size(); }
64 static constexpr std::size_t
N = n;
69 static_assert(
N,
"Must have size");
72 template <
typename... Inds>
74 static_assert(
sizeof...(Inds) ==
N,
75 "Must have same size for initialization");
83 ptr = std::move(g.ptr);
89 template <
typename... Inds>
95 template <
typename... Inds>
102 static_assert(
N == 1);
108 static_assert(
N == 1);
114 const std::size_t nel = g.
size();
115 for (std::size_t i = 0; i < nel; i++) {
117 if constexpr (
N > 1) {
118 if (i not_eq 0 and i not_eq nel and i % g.
gridsize[
N-2] == 0)
120 else if (i not_eq nel)
122 }
else if (i not_eq nel) {
131template <
typename b, std::size_t... Sizes>
138 static constexpr std::size_t
N =
sizeof...(Sizes);
143 static_assert(
N,
"Must have size");
146 template <
typename... Inds>
147 constexpr FixedGrid(Inds... inds [[maybe_unused]]) noexcept :
ptr({}) {
148 static_assert(
sizeof...(Inds) ==
N,
"Must have same size for initialization");
152 constexpr FixedGrid() noexcept :
ptr({}) {
static_assert(
mul(Sizes...),
"Must have size");}
159 ptr = std::move(g.ptr);
164 template <
typename... Inds>
170 template <
typename... Inds>
177 static_assert(
N == 1);
183 static_assert(
N == 1);
189 constexpr std::size_t nel =
mul(Sizes...);
190 constexpr std::size_t last_of = (std::array<std::size_t, N>{std::size_t(Sizes)...}).back();
191 for (std::size_t i = 0; i < nel; i++) {
193 if (i not_eq 0 and i not_eq nel and i % last_of == 0)
195 else if (i not_eq nel)
Row-major fixed grid creation.
std::array< b, mul(Sizes...)> ptr
constexpr FixedGrid & operator=(FixedGrid &&g) noexcept
constexpr FixedGrid() noexcept
constexpr FixedGrid(Inds... inds) noexcept
constexpr FixedGrid(FixedGrid &&g) noexcept
constexpr base & operator[](std::size_t ind) noexcept
constexpr const base & operator[](std::size_t ind) const noexcept
constexpr const base & operator()(Inds... inds) const noexcept
static constexpr std::size_t N
constexpr base & operator()(Inds... inds) noexcept
friend std::ostream & operator<<(std::ostream &os, const FixedGrid &g)
base & operator[](std::size_t ind) noexcept
Grid(Inds... inds) noexcept
static constexpr std::size_t N
const base & operator()(Inds... inds) const noexcept
friend std::ostream & operator<<(std::ostream &os, const Grid &g)
std::size_t size() const noexcept
std::array< std::size_t, n > gridsize
Grid & operator=(Grid &&g) noexcept
const base & operator[](std::size_t ind) const noexcept
base & operator()(Inds... inds) noexcept
constexpr std::size_t index_from_gridsize(std::array< std::size_t, N > gridsize, std::array< std::size_t, N > inds) noexcept
constexpr std::size_t mul(Inds... inds) noexcept
constexpr std::array< std::size_t, sizeof...(Inds)> gridsize_from_index(Inds... inds) noexcept