add signed overload for py::slice::compute

This commit is contained in:
sizmailov
2018-05-11 21:30:15 +03:00
committed by Wenzel Jakob
parent 22859bb8fc
commit 21c3911bd3
3 changed files with 39 additions and 0 deletions

View File

@@ -71,6 +71,25 @@ py::list test_random_access_iterator(PythonType x) {
}
TEST_SUBMODULE(sequences_and_iterators, m) {
// test_sliceable
class Sliceable{
public:
Sliceable(int n): size(n) {}
int start,stop,step;
int size;
};
py::class_<Sliceable>(m,"Sliceable")
.def(py::init<int>())
.def("__getitem__",[](const Sliceable &s, py::slice slice) {
ssize_t start, stop, step, slicelength;
if (!slice.compute(s.size, &start, &stop, &step, &slicelength))
throw py::error_already_set();
int istart = static_cast<int>(start);
int istop = static_cast<int>(stop);
int istep = static_cast<int>(step);
return std::make_tuple(istart,istop,istep);
})
;
// test_sequence
class Sequence {