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

Method findNearest

Examples/NoModules/Chapter 19/Ex19_07/Finder.cpp:6–14  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.45

Calls 2

findOptimumFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected