This is an archive of the discontinued LLVM Phabricator instance.

Introduce TypeNameTraits for llvm::getTypeName()
Needs ReviewPublic

Authored by logan on May 13 2022, 10:26 PM.

Details

Summary

This commit introduces TypeNameTraits as a customization point for
llvm::getTypeName<T>().

Before this commit, developers can specialize llvm::getTypeName<T>()
function template to customize the behavior. However, C++ programming
language doesn't allow function template partial specialization.

After this commit, if someone wants to partial specialize
getTypeName() for a class template, they can define:

namespace llvm {

template <typename T>
class TypeNameTraits<SomeContainer<T>> {
public:
  static llvm::StringRef getTypeName() {
    // ... a different implementation ...
  }
};

}  // namespace llvm

And then, calling llvm::getTypeName<SomeContainer<int>>() will be
dispatched to the partial specialized version.

Diff Detail

Event Timeline

logan created this revision.May 13 2022, 10:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 10:26 PM
logan requested review of this revision.May 13 2022, 10:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 10:26 PM