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

Function largest

Exercises/Modules/Chapter 09/Soln9_04.cpp:30–38  ·  view source on GitHub ↗

Finds the largest of a span of values

Source from the content-addressed store, hash-verified

28
29// Finds the largest of a span of values
30std::optional<double> largest(std::span<const double> data)
31{
32 if (data.empty()) return {}; // Or return std::nullopt;
33
34 double max{ data[0] };
35 for (auto value : data)
36 if (max < value) max = value;
37 return max;
38}
39
40// Finds the largest of a vector of int values
41std::optional<int> largest(std::span<const int> data)

Callers 1

mainFunction · 0.70

Calls 1

emptyMethod · 0.45

Tested by

no test coverage detected