Check if there's exactly one match in a vector
The standard library find functions return the .end() iterator for the container if they fail to find anything. We could follow the same convention, instead of using std::optional.

Rather than nesting the checks, we could split it into two separate loops, and use  std::find_if from the &lt;algorithm&gt; header, something like this:

auto const is_in_range = [&amp;] (int item) { return std::abs(item - zero) &lt; range; };

auto const first = std::find_if(data.begin(), data.end(), is_in_range);

if (first == data.end())
    return data.end(); // found nothing

auto const second = std::find_if(std::next(first), data.end(), is_in_range);

if (second != data.end())
    return data.end(); // found a second entry

return first;