mirror of
https://github.com/boostorg/python.git
synced 2026-07-21 13:33:40 +00:00
feat(vector_indexing_suite): implement reverse
This commit is contained in:
committed by
Stefan Seefeld
parent
660e8944ff
commit
fe087f9c2f
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user