Skip to content

Instantly share code, notes, and snippets.

@JohanMabille
Created January 1, 2020 20:38
Show Gist options
  • Save JohanMabille/12b43f5cf64559436a2b76505ff38c8b to your computer and use it in GitHub Desktop.
Save JohanMabille/12b43f5cf64559436a2b76505ff38c8b to your computer and use it in GitHub Desktop.
template <class S>
auto data_offset(const S&) noexcept
{
return typename S::value_type(0);
}
template <class S, class I, class... Args>
auto data_offset(const S& strides, I i, Args... args) noexcept
{
constexpr std::size_t nargs = sizeof...(Args) + 1;
if (nargs == strides.size())
{
// Correct number of arguments: iterate
return raw_data_offset<0>(strides, arg, args...));
}
else if (nargs > strides.size())
{
// Too many arguments: drop the first
return data_offset(strides, args...);
}
else
{
// Too few arguments: right to left scalar product
auto view = strides.cend() - nargs;
return raw_data_offset<0>(view, arg, args...));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment