// Not needed, the operator[] is already providing bounds checking cl.def("at", (T& (Vector::*)(SizeType i)) &Vector::at, "access specified element with bounds checking");
// Capacity, C++ style
cl.def("max_size",&Vector::max_size,"returns the maximum possible number of elements");
cl.def("capacity",&Vector::capacity,"returns the number of elements that can be held in currently allocated storage");
cl.def("shrink_to_fit",&Vector::shrink_to_fit,"reduces memory usage by freeing unused memory");
// Modifiers, C++ style
cl.def("clear",&Vector::clear,"clears the contents");
cl.def("swap",&Vector::swap,"swaps the contents");
// Modifiers, Python style
cl.def("append",(void(Vector::*)(constT&))&Vector::push_back,"adds an element to the end");
cl.def("insert",[](Vector&v,SizeTypei,constT&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){
if(v.size()){
Tt=v.back();
v.pop_back();
returnt;
}
elsethrowpybind11::index_error();
},"remove and return last item");
cl.def("pop",[](Vector&v,SizeTypei){
if(i>=v.size())throwpybind11::index_error();
Tt=v[i];
v.erase(v.begin()+i);
returnt;
},"remove and return item at index");
cl.def("erase",[](Vector&v,SizeTypei){
if(i>=v.size())throwpybind11::index_error();
v.erase(v.begin()+i);
},"erases element at index");
// Python friendly bindings
#ifdef PYTHON_ABI_VERSION // Python 3+
cl.def("__bool__",[](Vector&v)->bool{returnv.size()!=0;});// checks whether the container has any elements in it
#else
cl.def("__nonzero__",[](Vector&v)->bool{returnv.size()!=0;});// checks whether the container has any elements in it