[llvm] [ADT] Introduce Casting function objects (PR #165803)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 3 11:48:10 PST 2025


================
@@ -816,6 +816,42 @@ template <typename... Types> struct IsaAndPresentCheckPredicate {
     return isa_and_present<Types...>(Val);
   }
 };
+
+//===----------------------------------------------------------------------===//
+// Casting Function Objects
+//===----------------------------------------------------------------------===//
+
+/// Usable in generic algorithms like map_range
+template <typename U> struct StaticCastFunc {
+  template <typename T> decltype(auto) operator()(const T &Val) const {
+    return static_cast<U>(Val);
+  }
----------------
kuhar wrote:

I think this should take the arguments as `T&&` to allow casting to mutable references. Could we also add a test for this?

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


More information about the llvm-commits mailing list