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

Method findNearest

Examples/Modules/Chapter 19/Ex19_07/Finder.cpp:8–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6import optimum;
7
8std::optional<double> Finder::findNearest(const std::vector<double>& values) const
9{
10 if (values.empty())
11 return std::nullopt;
12 else
13 return *findOptimum(values, [this](double x, double y) {
14 return std::abs(x - m_number_to_search_for) < std::abs(y - m_number_to_search_for);
15 });
16}
17
18double Finder::getNumberToSearchFor() const
19{

Callers 1

mainFunction · 0.45

Calls 2

findOptimumFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected