Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions llvm/include/llvm/ADT/identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,32 @@
#ifndef LLVM_ADT_IDENTITY_H
#define LLVM_ADT_IDENTITY_H

#include <utility>

namespace llvm {

// Similar to `std::identity` from C++20.
template <class Ty> struct identity {
// Our legacy llvm::identity, not quite the same as std::identity.
template <class Ty = void> struct identity {
using is_transparent = void;
using argument_type = Ty;

Ty &operator()(Ty &self) const { return self; }
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<void> {
using is_transparent = void;

template <typename T> constexpr T &&operator()(T &&self) const {
return std::forward<T>(self);
}
};

} // namespace llvm

#endif // LLVM_ADT_IDENTITY_H