Ruby STL container negative indexing support improved

Using negative indexes to set values works the same as Ruby arrays, eg

%template(IntVector) std::vector<int>;

iv = IntVector.new([1,2,3,4])
iv[-4] = 9 # => [1,2,3,9]
iv[-5] = 9 # => IndexError
This commit is contained in:
William S Fulton 2015-11-22 10:16:28 +00:00
commit fe09f05beb
2 changed files with 20 additions and 7 deletions

View file

@ -80,6 +80,21 @@ iv[1,3] = [6,7,8,9]
#__setitem__ needs fixing
#swig_assert_equal(iv.to_s, '16789', binding)
iv = IntVector.new([1,2,3,4])
iv[-1] = 9
iv[-4] = 6
swig_assert_equal(iv.to_s, '6239', binding)
begin
iv[-5] = 99
raise "exception missed"
rescue IndexError
end
iv[6] = 5
swig_assert_equal(iv.to_s, '6239555', binding)
dv = DoubleVector.new(10)
swig_assert( "dv.respond_to? :each_with_index", binding )