feat(vector_indexing_suite): implement reverse

This commit is contained in:
Eisuke Kawashima
2026-04-05 16:29:32 +09:00
committed by Stefan Seefeld
parent 660e8944ff
commit fe087f9c2f
2 changed files with 18 additions and 0 deletions
@@ -66,6 +66,7 @@ namespace boost { namespace python {
.def("count", &base_count)
.def("extend", &base_extend)
.def("remove", &base_remove)
.def("reverse", &base_reverse)
;
}
@@ -302,6 +303,15 @@ namespace boost { namespace python {
}
}
}
static void
base_reverse(Container& container)
{
using std::swap;
const unsigned n = size(container);
for (unsigned i = 0; i < n / 2; i++)
swap(container[i], container[n - i - 1]);
}
};
}} // namespace boost::python
+8
View File
@@ -312,6 +312,14 @@ e
>>> v.count(12345)
0
#####################################################################
# Reverse
#####################################################################
>>> v.reverse()
>>> print_xvec(v)
[ e d c b a ]
#####################################################################
# Show that iteration allows mutable access to the elements
#####################################################################
>>> v[:] = ['a','b','c','d','e'] # reset again