mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
reduce redundancy
This commit is contained in:
parent
17912ba667
commit
136c664b5a
@ -1093,18 +1093,14 @@ public:
|
||||
// Reference to element at a given index
|
||||
template <typename... Ix>
|
||||
const T &at(Ix... index) const {
|
||||
if ((ssize_t) sizeof...(index) != ndim()) {
|
||||
fail_dim_check(sizeof...(index), "index dimension mismatch");
|
||||
}
|
||||
check_dim_precondition(sizeof...(index));
|
||||
return const_reference(index...);
|
||||
}
|
||||
|
||||
// Mutable reference to element at a given index
|
||||
template <typename... Ix>
|
||||
T &mutable_at(Ix... index) {
|
||||
if ((ssize_t) sizeof...(index) != ndim()) {
|
||||
fail_dim_check(sizeof...(index), "index dimension mismatch");
|
||||
}
|
||||
check_dim_precondition(sizeof...(index));
|
||||
return mutable_reference(index...);
|
||||
}
|
||||
|
||||
@ -1112,9 +1108,7 @@ public:
|
||||
template <typename... Ix>
|
||||
const T &operator()(Ix... index) const {
|
||||
#if !defined(NDEBUG)
|
||||
if ((ssize_t) sizeof...(index) != ndim()) {
|
||||
fail_dim_check(sizeof...(index), "index dimension mismatch");
|
||||
}
|
||||
check_dim_precondition(sizeof...(index));
|
||||
#endif
|
||||
return const_reference(index...);
|
||||
}
|
||||
@ -1123,9 +1117,7 @@ public:
|
||||
template <typename... Ix>
|
||||
T &operator()(Ix... index) {
|
||||
#if !defined(NDEBUG)
|
||||
if ((ssize_t) sizeof...(index) != ndim()) {
|
||||
fail_dim_check(sizeof...(index), "index dimension mismatch");
|
||||
}
|
||||
check_dim_precondition(sizeof...(index));
|
||||
#endif
|
||||
return mutable_reference(index...);
|
||||
}
|
||||
@ -1199,6 +1191,12 @@ private:
|
||||
return *(static_cast<T *>(array::mutable_data())
|
||||
+ byte_offset(ssize_t(index)...) / itemsize());
|
||||
}
|
||||
|
||||
void check_dim_precondition(ssize_t dim) const {
|
||||
if (dim != ndim()) {
|
||||
fail_dim_check(dim, "index dimension mismatch");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
Loading…
Reference in New Issue
Block a user