Commit d75f957a authored by Xavier Thompson's avatar Xavier Thompson

Implement list.pop()

parent 731f1925
...@@ -42,6 +42,31 @@ cdef cypclass List[V]: ...@@ -42,6 +42,31 @@ cdef cypclass List[V]:
with gil: with gil:
raise IndexError("Deleting list index out of range") raise IndexError("Deleting list index out of range")
V pop(self) except ~:
if self._elements.size() == 0:
with gil:
raise IndexError("Pop from empty list")
if self._active_iterators != 0:
with gil:
raise RuntimeError("Modifying a list with active iterators")
value = self._elements.back()
self._elements.pop_back()
return value
V pop(self, size_type index) except ~:
if index < self._elements.size():
if self._active_iterators == 0:
value = self._elements[index]
it = self._elements.begin() + index
self._elements.erase(it)
return value
else:
with gil:
raise RuntimeError("Modifying a list with active iterators")
else:
with gil:
raise IndexError("Pop index out of range")
void append(self, const value_type value) except ~: void append(self, const value_type value) except ~:
if self._active_iterators == 0: if self._active_iterators == 0:
self._elements.push_back(value) self._elements.push_back(value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment