[llvm] [STLExtras] Introduce bind_{front, back}, [not_]equal_to (PR #175056)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 11 18:32:39 PST 2026


================
@@ -147,6 +148,23 @@ template <class T> constexpr T *to_address(T *P) {
   return P;
 }
 
+// The behvaior is the same as std::bind_front, with the following differences:
+// - BindArgs are not perfect-forwarded
+// - The value catagory and const of the returned lambda are not considered when
+// calling it. An approach to handle them is using deducing this and
+// std::forward_like (C++23).
+template <typename FnT, typename... BindArgsT>
+constexpr auto bind_front(FnT &&Fn, // NOLINT(readability-identifier-naming)
+                          BindArgsT &&...BindArgs) {
+  if constexpr (std::is_pointer_v<FnT> or std::is_member_pointer_v<FnT>)
+    static_assert(Fn != nullptr);
+
+  return [&BindArgs..., Fn = std::forward<FnT>(Fn)](auto &&...CallArgs) {
+    return std::invoke(Fn, std::forward<BindArgsT>(BindArgs)...,
----------------
kuhar wrote:

I think this is incorrect because when you pass in a temporary bound argument it will be moved from each time you call this lambda. You can see how we solved something similar in `llvm::enumerate` where we store all passed in arguments in a tuple (of values or references). IIUC, temporaries should be moved to the lambda storage once and then passed to the function by reference.

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


More information about the llvm-commits mailing list