[PATCH] D125599: Introduce TypeNameTraits for llvm::getTypeName()

Logan Chien via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 13 22:26:19 PDT 2022


logan created this revision.
logan added reviewers: chandlerc, mehdi_amini.
Herald added a project: All.
logan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125599

Files:
  llvm/include/llvm/Support/TypeName.h
  llvm/unittests/Support/TypeNameTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125599.429412.patch
Type: text/x-patch
Size: 4620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220514/1f58f042/attachment.bin>


More information about the llvm-commits mailing list