Commit 26aca3d8 by Sergey Lyskov Committed by Wenzel Jakob

Adding vector ’extend’ member function

parent 9ee4f92b
...@@ -103,7 +103,6 @@ void vector_maybe_has_equal_operator(Class_ &cl) { ...@@ -103,7 +103,6 @@ void vector_maybe_has_equal_operator(Class_ &cl) {
using T = typename Vector::value_type; using T = typename Vector::value_type;
cl.def(pybind11::self == pybind11::self); cl.def(pybind11::self == pybind11::self);
cl.def(pybind11::self != pybind11::self);
cl.def("count", [](Vector const &v, T const & value) { return std::count(v.begin(), v.end(), value); }, "counts the elements that are equal to value"); cl.def("count", [](Vector const &v, T const & value) { return std::count(v.begin(), v.end(), value); }, "counts the elements that are equal to value");
...@@ -186,6 +185,7 @@ pybind11::class_<std::vector<T, Allocator>, holder_type > vector_binder(pybind11 ...@@ -186,6 +185,7 @@ pybind11::class_<std::vector<T, Allocator>, holder_type > vector_binder(pybind11
// Modifiers, Python style // Modifiers, Python style
cl.def("append", (void (Vector::*)(const T&)) &Vector::push_back, "adds an element to the end"); cl.def("append", (void (Vector::*)(const T&)) &Vector::push_back, "adds an element to the end");
cl.def("insert", [](Vector &v, SizeType i, const T&t) {v.insert(v.begin()+i, t);}, "insert an item at a given position"); cl.def("insert", [](Vector &v, SizeType i, const T&t) {v.insert(v.begin()+i, t);}, "insert an item at a given position");
cl.def("extend", [](Vector &v, Vector &src) { v.reserve( v.size() + src.size() ); v.insert(v.end(), src.begin(), src.end()); }, "extend the list by appending all the items in the given vector");
cl.def("pop", [](Vector &v) { cl.def("pop", [](Vector &v) {
if(v.size()) { if(v.size()) {
T t = v.back(); T t = v.back();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment