vector<object>::iterator Help

This is a discussion on vector<object>::iterator Help within the C++ Programming forums, part of the General Programming Boards category; >> using std::remove() on an std::list won't use that advantage, it will be as slow as with an std::vector. Which ...

  1. #16
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    >> 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 06:45 PM.

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    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.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21