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