fixed many conversion warnings on clang

This commit is contained in:
Wenzel Jakob
2016-05-29 13:40:40 +02:00
parent c48da92561
commit 0a07805ab6
8 changed files with 69 additions and 52 deletions

View File

@@ -133,22 +133,22 @@ void init_ex6(py::module &m) {
.def("__reversed__", [](const Sequence &s) -> Sequence { return s.reversed(); })
/// Slicing protocol (optional)
.def("__getitem__", [](const Sequence &s, py::slice slice) -> Sequence* {
py::ssize_t start, stop, step, slicelength;
size_t start, stop, step, slicelength;
if (!slice.compute(s.size(), &start, &stop, &step, &slicelength))
throw py::error_already_set();
Sequence *seq = new Sequence(slicelength);
for (int i=0; i<slicelength; ++i) {
for (size_t i=0; i<slicelength; ++i) {
(*seq)[i] = s[start]; start += step;
}
return seq;
})
.def("__setitem__", [](Sequence &s, py::slice slice, const Sequence &value) {
py::ssize_t start, stop, step, slicelength;
size_t start, stop, step, slicelength;
if (!slice.compute(s.size(), &start, &stop, &step, &slicelength))
throw py::error_already_set();
if ((size_t) slicelength != value.size())
if (slicelength != value.size())
throw std::runtime_error("Left and right hand size of slice assignment have different sizes!");
for (int i=0; i<slicelength; ++i) {
for (size_t i=0; i<slicelength; ++i) {
s[start] = value[i]; start += step;
}
})