Skip to content

Commit 70e518d

Browse files
committed
[std-array] various fixes
+ empty get_slice should return the slice type StdVec + set_slice with from >= to should throw + set_slice with incompatible iterator and slice sizes should throw
1 parent 2c18089 commit 70e518d

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

include/eigenpy/std-array.hpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ class array_indexing_suite
5656

5757
static void set_slice(Container &container, index_type from, index_type to,
5858
data_type const &v) {
59-
if (from > to) {
60-
return;
59+
if (from >= to) {
60+
PyErr_SetString(PyExc_NotImplementedError,
61+
"Setting this slice would insert into an std::array, "
62+
"which is not supported.");
63+
bp::throw_error_already_set();
6164
} else {
6265
std::fill(container.begin() + from, container.begin() + to, v);
6366
}
@@ -66,16 +69,26 @@ class array_indexing_suite
6669
template <class Iter>
6770
static void set_slice(Container &container, index_type from, index_type to,
6871
Iter first, Iter last) {
69-
if (from > to) {
70-
return;
72+
if (from >= to) {
73+
PyErr_SetString(PyExc_NotImplementedError,
74+
"Setting this slice would insert into an std::array, "
75+
"which is not supported.");
76+
bp::throw_error_already_set();
7177
} else {
72-
std::copy(first, last, container.begin() + from);
78+
if (long(to - from) == std::distance(first, last)) {
79+
std::copy(first, last, container.begin() + from);
80+
} else {
81+
PyErr_SetString(PyExc_NotImplementedError,
82+
"Size of std::array slice and size of right-hand side "
83+
"iterator are incompatible.");
84+
bp::throw_error_already_set();
85+
}
7386
}
7487
}
7588

7689
static bp::object get_slice(Container &container, index_type from,
7790
index_type to) {
78-
if (from > to) return bp::object(std::array<data_type, 0>());
91+
if (from > to) return bp::object(slice_vector_type());
7992
slice_vector_type out;
8093
for (size_t i = from; i < to; i++) {
8194
out.push_back(container[i]);

0 commit comments

Comments
 (0)