algorithms
check(std::ranges::find(ports, 443) != ports.end(), "find");
Ranges avoid passing begin and end separately They compose better and read closer to the question you are asking
find and sort
std::ranges::find returns an iterator or the end
Compare against end before dereferencing
std::sort needs random access iterators, so it works on vector and array
Predicates
auto is_high = [](int port) { return port > 1000; };
Lambdas are the normal predicate form Keep them small Name the lambda when the condition needs a paragraph of explanation
Own loops
An algorithm is not always clearer When the body has several steps, a range for loop wins Readability is the metric
Next
Exceptions in 10 exceptions
Posted