#include <iostream>
#include <array>
namespace indexer_detail {
template <class T>
struct ArrayWrapper {
T obj;
};
template <class T>
ArrayWrapper(T&&) -> ArrayWrapper<T&&>;
template <class T>
auto operator & (ArrayWrapper<T> const &aw, std::size_t N) {
return ArrayWrapper{aw.obj[N]};
}
}
template <std::size_t Size, class Array, std::size_t... Idx>
decltype(auto) index(Array &&array, std::array<std::size_t, Size> const &indices, std::index_sequence<Idx...>) {
return (indexer_detail::ArrayWrapper{std::forward<Array>(array)} & ... & indices[Idx]).obj;
}
template <std::size_t Size, class Array>
decltype(auto) index(Array &&array, std::array<std::size_t, Size> const &indices) {
return index(std::forward<Array>(array), indices, std::make_index_sequence<Size>{});
}
int main() {
int arr[1][2][3] {{{1}}};
std::cout << index<3>(arr, {{0, 0, 0}}) << index<3>(arr, {{0, 1, 0}}) << '\n';;
}