Skip to content

Commit 2fc1cb7

Browse files
committed
feat(vector_indexing_suite): implement reverse
1 parent fb54967 commit 2fc1cb7

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

include/boost/python/suite/indexing/vector_indexing_suite.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ namespace boost { namespace python {
6666
.def("count", &base_count)
6767
.def("extend", &base_extend)
6868
.def("remove", &base_remove)
69+
.def("reverse", &base_reverse)
6970
;
7071
}
7172

@@ -302,6 +303,15 @@ namespace boost { namespace python {
302303
}
303304
}
304305
}
306+
307+
static void
308+
base_reverse(Container& container)
309+
{
310+
using std::swap;
311+
const unsigned n = size(container);
312+
for (unsigned i = 0; i < n / 2; i++)
313+
swap(container[i], container[n - i - 1]);
314+
}
305315
};
306316

307317
}} // namespace boost::python

test/vector_indexing_suite.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@
312312
>>> v.count(12345)
313313
0
314314
315+
#####################################################################
316+
# Reverse
317+
#####################################################################
318+
>>> v.reverse()
319+
>>> print_xvec(v)
320+
[ e d c b a ]
321+
322+
#####################################################################
315323
# Show that iteration allows mutable access to the elements
316324
#####################################################################
317325
>>> v[:] = ['a','b','c','d','e'] # reset again

0 commit comments

Comments
 (0)