fix(math): fix calculate_offset
This commit is contained in:
@@ -76,10 +76,12 @@ public:
|
||||
|
||||
template <std::size_t Start = 0, typename... Offs>
|
||||
std::size_t calculate_offset(const std::tuple<Offs...>& offs) const {
|
||||
static_assert(sizeof...(Offs) > 0);
|
||||
static_assert(sizeof...(Offs) <= sizeof...(Dims));
|
||||
constexpr std::size_t off_count = sizeof...(Offs);
|
||||
|
||||
return calculate_offset_impl<Start, sizeof...(Dims) - sizeof...(Offs)>(offs);
|
||||
static_assert(off_count > 0);
|
||||
static_assert(Start + off_count <= sizeof...(Dims));
|
||||
|
||||
return calculate_offset_impl<off_count - 1, Start>(offs) * trailing_product<Start + off_count>();
|
||||
}
|
||||
private:
|
||||
template <std::size_t I, std::size_t Start, typename... Offs>
|
||||
@@ -90,6 +92,15 @@ private:
|
||||
return (calculate_offset_impl<I - 1, Start>(offs) * get<Start + I>()) + std::get<I>(offs);
|
||||
}
|
||||
}
|
||||
|
||||
template <std::size_t I>
|
||||
std::size_t trailing_product() const {
|
||||
if constexpr (I == sizeof...(Dims)) {
|
||||
return 1;
|
||||
} else {
|
||||
return get<I>() * trailing_product<I + 1>();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t... Dims>
|
||||
@@ -171,10 +182,12 @@ public:
|
||||
|
||||
template <std::size_t Start = 0, typename... Offs>
|
||||
std::size_t calculate_offset(const std::tuple<Offs...>& offs) const {
|
||||
static_assert(sizeof...(Offs) > 0);
|
||||
static_assert(sizeof...(Offs) <= sizeof...(Dims));
|
||||
constexpr std::size_t off_count = sizeof...(Offs);
|
||||
|
||||
return calculate_offset_impl<Start, sizeof...(Dims) - sizeof...(Offs)>(offs);
|
||||
static_assert(off_count > 0);
|
||||
static_assert(Start + off_count <= sizeof...(Dims));
|
||||
|
||||
return calculate_offset_impl<off_count - 1, Start>(offs) * trailing_product<Start + off_count>();
|
||||
}
|
||||
private:
|
||||
template <std::size_t I, std::size_t Start, typename... Offs>
|
||||
@@ -185,6 +198,15 @@ private:
|
||||
return (calculate_offset_impl<I - 1, Start>(offs) * get<Start + I>()) + std::get<I>(offs);
|
||||
}
|
||||
}
|
||||
|
||||
template <std::size_t I>
|
||||
std::size_t trailing_product() const {
|
||||
if constexpr (I == sizeof...(Dims)) {
|
||||
return 1;
|
||||
} else {
|
||||
return get<I>() * trailing_product<I + 1>();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
Reference in New Issue
Block a user