add set __getitem__ method, this allows python iterator syntax to work, as in 'for i in a_set:...'
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7338 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
43bdb55a63
commit
877535badf
2 changed files with 14 additions and 0 deletions
|
|
@ -91,4 +91,14 @@ v3 = std_containers.vector_piA(v2)
|
||||||
v3[0][1].a
|
v3[0][1].a
|
||||||
v3[1][1].a
|
v3[1][1].a
|
||||||
|
|
||||||
|
s = std_containers.set_i()
|
||||||
|
s.append(1)
|
||||||
|
s.append(2)
|
||||||
|
s.append(3)
|
||||||
|
j=1
|
||||||
|
for i in s:
|
||||||
|
if i != j:
|
||||||
|
raise RuntimeError
|
||||||
|
j = j + 1
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,10 @@
|
||||||
bool __contains__(value_type x) {
|
bool __contains__(value_type x) {
|
||||||
return self->find(x) != self->end();
|
return self->find(x) != self->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_type __getitem__(difference_type i) const {
|
||||||
|
return *(swig::cgetpos(self, i));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue