Thread: vector<object>::iterator Help

  1. #16
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    >> using std::remove() on an std::list won't use that advantage, it will be as slow as with an std::vector.

    Which is why you should use the list member function remove() instead of the generic algorithm if you do switch to lists.
    Wha?? Whose using std::remove()? No shuffling here:
    Code:
    myList.remove("Mary");
    Unhook the pointers to "Mary", redirect them to the previous and next elements in the list, bingo-bango-bongo..."Mary" is in the bin:
    Code:
    myList.remove("Mary");
    copy(myList.begin(), myList.end(), ostream_iterator<string>(cout, " "));
    cout<<endl;
    Compare to:
    Code:
    remove(myList.begin(), myList.end(), "Mary");
    myList.remove("Mary");
    copy(myList.begin(), myList.end(), ostream_iterator<string>(cout, " "));
    cout<<endl;
    Shuffle up and deal.
    Last edited by 7stud; 03-26-2006 at 07:45 PM.

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The point is that the solution to the original problem is to use std::remove from <algorithm> with the vector. It should be made clear that you should not just use list as a drop-in replacement because you should use its member function version of remove instead of the generic one.

Popular pages Recent additions subscribe to a feed