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

Function main

Examples/Modules/Chapter 20/Ex20_13/Ex20_13.cpp:10–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8void printVector(const std::vector<int>& v); // Print the contents of a vector to std::cout
9
10int main()
11{
12 const size_t num_numbers{20};
13
14 const auto numbers{ fillSet_1toN(num_numbers) };
15
16 std::vector<int> odd_numbers( numbers.size() ); // Caution: not { numbers.size() } here!
17 auto end_odd_numbers{ std::copy_if(begin(numbers), end(numbers), begin(odd_numbers),
18 [](int n) { return n % 2 == 1; }) };
19 odd_numbers.erase(end_odd_numbers, end(odd_numbers));
20
21 printVector(odd_numbers);
22}
23
24std::set<int> fillSet_1toN(size_t N) // Fill a set with 1, 2, ..., N
25{

Callers

nothing calls this directly

Calls 3

fillSet_1toNFunction · 0.70
printVectorFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected