diff --git a/llvm/include/llvm/ADT/identity.h b/llvm/include/llvm/ADT/identity.h index 88d033fc01141..9d599c6c192d8 100644 --- a/llvm/include/llvm/ADT/identity.h +++ b/llvm/include/llvm/ADT/identity.h @@ -15,10 +15,12 @@ #ifndef LLVM_ADT_IDENTITY_H #define LLVM_ADT_IDENTITY_H +#include + namespace llvm { -// Similar to `std::identity` from C++20. -template struct identity { +// Our legacy llvm::identity, not quite the same as std::identity. +template struct identity { using is_transparent = void; using argument_type = Ty; @@ -26,6 +28,19 @@ template struct identity { const Ty &operator()(const Ty &self) const { return self; } }; +// Forward-ported from C++20. +// +// While we are migrating from the legacy version, we must refer to this +// template as identity<>. Once the legacy version is removed, we can +// make this a non-template struct and remove the <>. +template <> struct identity { + using is_transparent = void; + + template constexpr T &&operator()(T &&self) const { + return std::forward(self); + } +}; + } // namespace llvm #endif // LLVM_ADT_IDENTITY_H