Created
January 1, 2020 20:38
-
-
Save JohanMabille/12b43f5cf64559436a2b76505ff38c8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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