[llvm] [ADT] Introduce bind_{front, back}, [not_]equal_to (PR #175056)
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 14 14:22:59 PST 2026
================
@@ -185,6 +186,140 @@ struct from_range_t {
explicit from_range_t() = default;
};
inline constexpr from_range_t from_range{};
+
+//===----------------------------------------------------------------------===//
+// Bind functions from C++20 / C++23 / C++26
+//===----------------------------------------------------------------------===//
+
+namespace detail {
+// Tag for constructing with a runtime callable.
+struct RuntimeFnTag {};
+// Tag for constructing with a compile-time constant callable.
+struct ConstantFnTag {};
+
+/// Stores a callable as a data member.
+template <typename FnT> struct FnHolder {
+ FnT Fn;
+
+ template <typename FnArgT>
+ constexpr explicit FnHolder(FnArgT &&F) : Fn(std::forward<FnArgT>(F)) {}
+
+ constexpr FnT &get() { return Fn; }
+ constexpr const FnT &get() const { return Fn; }
+};
+
+/// Holds a compile-time constant callable (empty storage).
+template <auto ConstFn> struct FnConstant {
+ constexpr decltype(auto) get() const { return ConstFn; }
+};
+
+// Storage class for bind_front/bind_back that properly handles const/non-const
+// qualification of the wrapper when invoking the stored callable.
+// If BindFront is true, bound args are prepended; otherwise appended.
+// FnStorageT is either FnHolder<FnT> (runtime) or FnConstant<ConstFn>.
+template <bool BindFront, typename BoundArgsTupleT, typename FnStorageT,
+ typename IndicesT>
+class BindStorage;
+
+template <bool BindFront, typename BoundArgsTupleT, typename FnStorageT,
+ size_t... Indices>
+class BindStorage<BindFront, BoundArgsTupleT, FnStorageT,
+ std::index_sequence<Indices...>> {
+ BoundArgsTupleT BoundArgs;
+ // This may be empty for const functions, hence the `no_unique_address`.
+ [[no_unique_address]] FnStorageT FnStorage;
----------------
kuhar wrote:
Feel free to drop the msvc `#elseif`, I don't care about it
https://github.com/llvm/llvm-project/pull/175056
More information about the llvm-commits
mailing list