Introduce (Function|Object|Value)Lifetimes.HasAny.

To properly support HRTB, Traverse needs to be removed or heavily modified.
This removes one of its uses, replacing it with a significantly more limited
interface that is less problematic in that context.

PiperOrigin-RevId: 440298949
diff --git a/lifetime_annotations/function_lifetimes.cc b/lifetime_annotations/function_lifetimes.cc
index 60bae09..a37b3c4 100644
--- a/lifetime_annotations/function_lifetimes.cc
+++ b/lifetime_annotations/function_lifetimes.cc
@@ -117,6 +117,16 @@
   return ret;
 }
 
+bool FunctionLifetimes::HasAny(
+    const std::function<bool(Lifetime)>& predicate) const {
+  return std::any_of(param_lifetimes_.begin(), param_lifetimes_.end(),
+                     [&predicate](const ValueLifetimes& v) {
+                       return v.HasAny(predicate);
+                     }) ||
+         return_lifetimes_.HasAny(predicate) ||
+         (this_lifetimes_.has_value() && this_lifetimes_->HasAny(predicate));
+}
+
 void FunctionLifetimes::Traverse(
     std::function<void(Lifetime&, Variance)> visitor) {
   for (auto& param : param_lifetimes_) {