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

Function main

Examples/NoModules/Chapter 20/Ex20_15/Ex20_15.cpp:7–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <algorithm>
6
7int main()
8{
9 std::vector<std::string> names{"Frodo Baggins", "Gandalf the Gray",
10 "Aragon", "Samwise Gamgee", "Peregrin Took", "Meriadoc Brandybuck",
11 "Gimli", "Legolas Greenleaf", "Boromir"};
12
13 // Sort the names lexicographically
14 std::sort(begin(names), end(names));
15 std::cout << "Names sorted lexicographically:" << std::endl;
16 for (const auto& name : names) std::cout << name << ", ";
17 std::cout << std::endl << std::endl;
18
19 // Sort the names by length
20 std::sort(begin(names), end(names),
21 [](const auto& left, const auto& right) {return left.length() < right.length(); });
22 std::cout << "Names sorted by length:" << std::endl;
23 for (const auto& name : names) std::cout << name << ", ";
24 std::cout << std::endl;
25}

Callers

nothing calls this directly

Calls 1

sortFunction · 0.50

Tested by

no test coverage detected