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

Function main

Exercises/Modules/Chapter 19/Soln19_04/Soln19_04.cpp:38–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38int main()
39{
40 const std::vector numbers{ -2, 4, -5, 6, 10, -40, 56, 4, 67, 45 };
41 std::cout << "\nAll numbers:\n";
42 list(numbers);
43
44 int threshold {};
45 std::cout << "\nPlease enter a threshold: ";
46 std::cin >> threshold;
47
48 const auto greater{ collect(numbers, [threshold](int i) { return i > threshold; }) };
49 std::cout << "Numbers greater than " << threshold << ":\n";
50 list(greater);
51
52 const std::vector letters{ 'C', 'd', 'a', 'z', 't', 'S', 'p', 'm', 'D', 'f' };
53 std::cout << "\nAll characters:\n";
54 list(letters, 2);
55 //const auto capitals{ collect(letters, std::isupper) }; // <-- This should but does not work with all compilers
56 const auto capitals{ collect(letters, isupper) };
57 std::cout << "\nCapital letters:\n";
58 list(capitals, 2);
59
60 const std::vector<std::string> strings{ "palindrome", "racecar", "rubarb", "noon", "kayak", "ananas", "madam", "backwards" };
61 std::cout << "\nAll strings:\n";
62 list(strings, 12);
63 const auto palindromes{ collect(strings, is_palindrome) };
64 std::cout << "\nPalindromes:\n";
65 list(palindromes, 10);
66}

Callers

nothing calls this directly

Calls 2

collectFunction · 0.85
listFunction · 0.70

Tested by

no test coverage detected