Skip to content

Commit 05a7849

Browse files
kazutakahirataLukacma
authored andcommitted
[ADT] Move llvm::identity into IndexedMap (NFC) (llvm#164568)
This patch moves llvm::identity to IndexedMap for two reasons: - llvm::identity is used only IndexedMap. - llvm::identity is not suitable for general use as it is not quite the same as std::identity despite the comments in identity.h. Also, this patch renames the class to IdentityIndex and places it in the "detail" namespace.
1 parent ef1e70d commit 05a7849

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

llvm/include/llvm/ADT/IndexedMap.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,21 @@
2222

2323
#include "llvm/ADT/STLExtras.h"
2424
#include "llvm/ADT/SmallVector.h"
25-
#include "llvm/ADT/identity.h"
2625
#include <cassert>
2726

2827
namespace llvm {
2928

30-
template <typename T, typename ToIndexT = identity<unsigned>> class IndexedMap {
29+
namespace detail {
30+
template <class Ty> struct IdentityIndex {
31+
using argument_type = Ty;
32+
33+
Ty &operator()(Ty &self) const { return self; }
34+
const Ty &operator()(const Ty &self) const { return self; }
35+
};
36+
} // namespace detail
37+
38+
template <typename T, typename ToIndexT = detail::IdentityIndex<unsigned>>
39+
class IndexedMap {
3140
using IndexT = typename ToIndexT::argument_type;
3241
// Prefer SmallVector with zero inline storage over std::vector. IndexedMaps
3342
// can grow very large and SmallVector grows more efficiently as long as T

llvm/include/llvm/ADT/identity.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)