Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Latest commit

History

History
25 lines (19 loc) 路 701 Bytes

remove_if.md

File metadata and controls

25 lines (19 loc) 路 701 Bytes

remove_if

Description : Removes elementes from range [first, last) that satisfy a condition and returns a new past-the-end iterator for the new end of range.

Example:

    auto isOdd = [](int i) {
        return ((i%2) == 1);
    };

    std::vector<int> v {1, 2, 3, 4, 5};

    // Remove all elements that returns true for isOdd
    auto newEndIt = std::remove_if(v.begin(), v.end(), isOdd);
    
    // Erase elements from [newEndIt, v.end()]
    v.erase(newEndIt, v.end());

    // v is now {2, 4}
    for (auto value : v) { 
        std::cout << value << " "; 
    }

See Sample code Run Code