Ruby STL container ranges and slices fixes.
Access via ranges and slices now behave identically to Ruby arrays. The fixes are mostly for out of range indices and lengths. - Zero length slice requests return an empty container instead of nil. - Slices which request a length greater than the size of the container no longer chop off the last element. - Ranges which used to return nil now return an empty array when the the start element is a valid index.
This commit is contained in:
parent
97b129de6c
commit
cd33aba427
3 changed files with 114 additions and 42 deletions
|
|
@ -41,7 +41,7 @@
|
|||
getslice(const std::array<T, N>* self, Difference i, Difference j) {
|
||||
using Sequence = std::array<T, N>;
|
||||
typename Sequence::size_type size = self->size();
|
||||
typename Sequence::size_type ii = swig::check_index(i, size);
|
||||
typename Sequence::size_type ii = (i == size && j == size) ? i : swig::check_index(i, size);
|
||||
typename Sequence::size_type jj = swig::slice_index(j, size);
|
||||
|
||||
if (ii == 0 && jj == size) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue