mirror of https://github.com/pybind/pybind11.git
array_t: overload operator () for indexing
This commit is contained in:
parent
2fb3d7cbde
commit
4d785be984
|
@ -1110,6 +1110,20 @@ public:
|
||||||
+ byte_offset(ssize_t(index)...) / itemsize());
|
+ 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
|
* 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
|
* dimensionality checking. Will throw if the array is missing the `writeable` flag. Use with
|
||||||
|
|
Loading…
Reference in New Issue