llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-llvm-adt

Author: Krzysztof Parzyszek (kparzysz)

<details>
<summary>Changes</summary>

A basic implementation until we get it in `std` in C++20.

---
Full diff: https://github.com/llvm/llvm-project/pull/146390.diff


2 Files Affected:

- (modified) clang/include/clang/Tooling/Transformer/Transformer.h (+4-9) 
- (modified) llvm/include/llvm/ADT/STLForwardCompat.h (+10) 


``````````diff
diff --git a/clang/include/clang/Tooling/Transformer/Transformer.h 
b/clang/include/clang/Tooling/Transformer/Transformer.h
index 71b1fe81b9518..ecf7c0912d2d8 100644
--- a/clang/include/clang/Tooling/Transformer/Transformer.h
+++ b/clang/include/clang/Tooling/Transformer/Transformer.h
@@ -42,11 +42,6 @@ class TransformerImpl {
   virtual void
   onMatchImpl(const ast_matchers::MatchFinder::MatchResult &Result) = 0;
 };
-
-// FIXME: Use std::type_identity or backport when available.
-template <class T> struct type_identity {
-  using type = T;
-};
 } // namespace detail
 
 template <typename T> struct TransformerResult {
@@ -95,8 +90,8 @@ class Transformer : public 
ast_matchers::MatchFinder::MatchCallback {
   template <typename MetadataT>
   explicit Transformer(
       transformer::RewriteRuleWith<MetadataT> Rule,
-      std::function<void(llvm::Expected<TransformerResult<
-                             typename 
detail::type_identity<MetadataT>::type>>)>
+      std::function<void(
+          llvm::Expected<TransformerResult<llvm::type_identity_t<MetadataT>>>)>
           Consumer);
 
   /// N.B. Passes `this` pointer to `MatchFinder`.  So, this object should not
@@ -200,8 +195,8 @@ template <typename T> class WithMetadataImpl final : public 
TransformerImpl {
 template <typename MetadataT>
 Transformer::Transformer(
     transformer::RewriteRuleWith<MetadataT> Rule,
-    std::function<void(llvm::Expected<TransformerResult<
-                           typename detail::type_identity<MetadataT>::type>>)>
+    std::function<void(
+        llvm::Expected<TransformerResult<llvm::type_identity_t<MetadataT>>>)>
         Consumer)
     : Impl(std::make_unique<detail::WithMetadataImpl<MetadataT>>(
           std::move(Rule), std::move(Consumer))) {}
diff --git a/llvm/include/llvm/ADT/STLForwardCompat.h 
b/llvm/include/llvm/ADT/STLForwardCompat.h
index 75a0d4acf67f1..370caf5a897b5 100644
--- a/llvm/include/llvm/ADT/STLForwardCompat.h
+++ b/llvm/include/llvm/ADT/STLForwardCompat.h
@@ -36,6 +36,16 @@ template <typename T>
 using remove_cvref_t // NOLINT(readability-identifier-naming)
     = typename llvm::remove_cvref<T>::type;
 
+template <typename T>
+struct type_identity // NOLINT(readability-identifier-naming)
+{
+  using type = T;
+};
+
+template <typename T>
+using type_identity_t // NOLINT(readability-identifier-naming)
+    = typename llvm::type_identity<T>::type;
+
 
//===----------------------------------------------------------------------===//
 //     Features from C++23
 
//===----------------------------------------------------------------------===//

``````````

</details>


https://github.com/llvm/llvm-project/pull/146390
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to