array_t: overload operator () for indexing

This commit is contained in:
Francesco Rizzi 2023-06-28 15:19:04 +02:00
parent 2fb3d7cbde
commit 4d785be984
1 changed files with 14 additions and 0 deletions

View File

@ -1110,6 +1110,20 @@ public:
+ byte_offset(ssize_t(index)...) / itemsize());
}
// const-reference to element at a given index without bounds checking
template <typename... Ix>
const T &operator()(Ix... index) const {
return *(static_cast<const T *>(array::data())
+ byte_offset(ssize_t(index)...) / itemsize());
}
// mutable reference to element at a given index without bounds checking
template <typename... Ix>
T &operator()(Ix... index) {
return *(static_cast<T *>(array::mutable_data())
+ byte_offset(ssize_t(index)...) / itemsize());
}
/**
* Returns a proxy object that provides access to the array's data without bounds or
* dimensionality checking. Will throw if the array is missing the `writeable` flag. Use with