Skip to content

Commit e97c735

Browse files
fwjavoxwjakob
authored andcommitted
stl_bind: add binding for std::vector::clear (#2074)
1 parent 07e2259 commit e97c735

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

include/pybind11/stl_bind.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ void vector_modifiers(enable_if_t<is_copy_constructible<typename Vector::value_t
136136
return v.release();
137137
}));
138138

139+
cl.def("clear",
140+
[](Vector &v) {
141+
v.clear();
142+
},
143+
"Clear the contents"
144+
);
145+
139146
cl.def("extend",
140147
[](Vector &v, const Vector &src) {
141148
v.insert(v.end(), src.begin(), src.end());

tests/test_stl_binders.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def test_vector_int():
6464
del v_int2[-1]
6565
assert v_int2 == m.VectorInt([0, 99, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 88])
6666

67+
v_int2.clear()
68+
assert len(v_int2) == 0
69+
6770
# related to the PyPy's buffer protocol.
6871
@pytest.unsupported_on_pypy
6972
def test_vector_buffer():

0 commit comments

Comments
 (0)