questions about STL erase example

Discussion in 'C++' started by Allerdyce.John@gmail.com, Mar 8, 2006.

  1. Guest

    I am reading a STL example:

    bool badValue(int x); // return whether x is 'bad'.
    vector<int> c;
    c.erase( remove_if(c.begin(), c.end(), badValue), c.end());

    My question is the above code, does it remove ONLY THE FIRST item where
    badValue return false or
    ALL ITEMs where badValue return false.

    Thank you.
     
    , Mar 8, 2006
    #1
    1. Advertising

  2. wrote:
    > vector<int> c;
    > c.erase( remove_if(c.begin(), c.end(), badValue), c.end());
    >
    > My question is the above code, does it remove ONLY THE FIRST item where
    > badValue return false or
    > ALL ITEMs where badValue return false.


    It returns all items for which the predicate yields 'true'.
    --
    <mailto:> <http://www.dietmar-kuehl.de/>
    <http://www.eai-systems.com> - Efficient Artificial Intelligence
     
    Dietmar Kuehl, Mar 8, 2006
    #2
    1. Advertising

  3. red floyd Guest

    wrote:
    > I am reading a STL example:
    >
    > bool badValue(int x); // return whether x is 'bad'.
    > vector<int> c;
    > c.erase( remove_if(c.begin(), c.end(), badValue), c.end());
    >
    > My question is the above code, does it remove ONLY THE FIRST item where
    > badValue return false or
    > ALL ITEMs where badValue return false.
    >


    I believe it removes all "bad" items.
     
    red floyd, Mar 8, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Harrison

    Re: STL insert/erase behaviour

    John Harrison, Aug 13, 2003, in forum: C++
    Replies:
    0
    Views:
    639
    John Harrison
    Aug 13, 2003
  2. Andrew Koenig

    Re: STL insert/erase behaviour

    Andrew Koenig, Aug 13, 2003, in forum: C++
    Replies:
    0
    Views:
    382
    Andrew Koenig
    Aug 13, 2003
  3. Paras

    stl list erase

    Paras, Aug 20, 2003, in forum: C++
    Replies:
    13
    Views:
    3,797
    Alan Chen
    Aug 21, 2003
  4. s

    STL list::erase()

    s, Sep 15, 2003, in forum: C++
    Replies:
    2
    Views:
    7,283
    Rob Williscroft
    Sep 15, 2003
  5. erase vs. erase

    , Mar 25, 2006, in forum: C++
    Replies:
    7
    Views:
    369
    Pete Becker
    Mar 30, 2006
Loading...

Share This Page