Page MenuHomePhabricator

Introduce TypeNameTraits for llvm::getTypeName()
Needs ReviewPublic

Authored by logan on Fri, May 13, 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.Fri, May 13, 10:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, May 13, 10:26 PM
logan requested review of this revision.Fri, May 13, 10:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, May 13, 10:26 PM