[llvm] [STLExtras] Introduce BinaryPredicateFunctor, [not_]equal_to (PR #175056)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 8 12:17:17 PST 2026


================
@@ -2157,6 +2157,30 @@ template <typename T> bool all_equal(std::initializer_list<T> Values) {
   return all_equal<std::initializer_list<T>>(std::move(Values));
 }
 
+template <typename ValT, typename RefT, typename BinaryPredicate>
+struct BinaryPredicateFunctor {
+  RefT Ref;
+  const BinaryPredicate &P;
+  BinaryPredicateFunctor(RefT Ref, const BinaryPredicate &P) : Ref(Ref), P(P) {}
+  bool operator()(ValT Val) const { return P(Val, Ref); }
+};
+
+/// Functor variant of std::equal_to that can be used as a UnaryPredicate in
+/// functional algorithms like all_of.
+template <typename T>
+BinaryPredicateFunctor<T, T, decltype(std::equal_to<T>())>
+equal_to(const T &Ref) {
+  return {Ref, std::equal_to<T>()};
+}
+
+/// Functor variant of std::not_equal_to that can be used as a UnaryPredicate in
+/// functional algorithms like all_of.
+template <typename T>
+BinaryPredicateFunctor<T, T, decltype(std::not_equal_to<T>())>
+not_equal_to(const T &Ref) {
+  return {Ref, std::not_equal_to<T>()};
----------------
kuhar wrote:

```suggestion
  return {Ref, std::not_equal_to<>()};
```

https://github.com/llvm/llvm-project/pull/175056


More information about the llvm-commits mailing list