MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / removeEvenNumbers

Function removeEvenNumbers

Examples/Modules/Chapter 20/Ex20_14/Ex20_14.cpp:11–18  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9void printVector(std::string_view message, const std::vector<int>& numbers);
10
11void removeEvenNumbers(std::vector<int>& numbers)
12{
13 // Use the remove_if() algorithm to remove all even numbers
14 auto first_to_erase{ std::remove_if(begin(numbers), end(numbers),
15 [](int number) { return number % 2 == 0; }) };
16 // Erase all elements including and beyond first_to_erase
17 numbers.erase(first_to_erase, end(numbers));
18}
19
20int main()
21{

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected