Originally posted by PJYelton
Okay, that makes more sense although and I understand now how to get around it, but I'm still dumbfounded as to why the STL creators didn't make popping the back of the container automatic with unique and remove. I can't think of a reason why someone WOULDN't want this done, although is somebody knows I would love to be told!
Thanks for pointing out the member function clear(), I haven't gotten to many of the member functions yet and that is definately a useful one! And as far as the constant reference, I usually do, just didn't this time because I was in a hurry to make this post and I forgot :D
The reason why is simple - flexability.......Look at this
Code:
#include <iostream>
#include <vector>
#include <algorithm>
int main(void){
int Arr[] = {3,2,4,5,3,1,2,3};//My array
//print array
copy(Arr,Arr+sizeof(Arr)/sizeof(Arr[0]),std::ostream_iterator<int>(std::cout, " "));
std::remove(Arr,Arr+sizeof(Arr)/sizeof(Arr[0]),3);//remove 3
std::cout << std::endl;
//print array
copy(Arr,Arr+sizeof(Arr)/sizeof(Arr[0]),std::ostream_iterator<int>(std::cout, " "));
}
2 STL algorithms but using a std C typr array....
The reason why I can do this is that the algorithm doesnt care about the data struct......why should it? - it treats an iterator for a container just as an array, and so I can use any container I wish....but the trade off is that the algorithm doesnt know if the container is a true object, or what member functions it may have.......that's why it doesnt delete at the end.....it cant do so with arrays, so it cant do so ever