Skip to content

Commit

Permalink
stl_bind: add binding for std::vector::clear (pybind#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwjavox authored and wjakob committed Jan 17, 2020
1 parent 07e2259 commit e97c735
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/pybind11/stl_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ void vector_modifiers(enable_if_t<is_copy_constructible<typename Vector::value_t
return v.release();
}));

cl.def("clear",
[](Vector &v) {
v.clear();
},
"Clear the contents"
);

cl.def("extend",
[](Vector &v, const Vector &src) {
v.insert(v.end(), src.begin(), src.end());
Expand Down
3 changes: 3 additions & 0 deletions tests/test_stl_binders.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def test_vector_int():
del v_int2[-1]
assert v_int2 == m.VectorInt([0, 99, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 88])

v_int2.clear()
assert len(v_int2) == 0

# related to the PyPy's buffer protocol.
@pytest.unsupported_on_pypy
def test_vector_buffer():
Expand Down

0 comments on commit e97c735

Please sign in to comment.