From: Daniel Berlin Date: Tue, 7 Mar 2017 18:47:50 +0000 (+0000) Subject: Add PointerLikeTypeTraits for const things, as long as there is one for the non-const... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=434e38630cd0f2477166907514ad420fe5489588;p=llvm Add PointerLikeTypeTraits for const things, as long as there is one for the non-const version. Clang and other users have a number of types they use as pointers, and this avoids having to define both const and non-const versions of PointerLikeTraits. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297181 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/PointerLikeTypeTraits.h b/include/llvm/Support/PointerLikeTypeTraits.h index 9ff894edbeb..521a49684e4 100644 --- a/include/llvm/Support/PointerLikeTypeTraits.h +++ b/include/llvm/Support/PointerLikeTypeTraits.h @@ -60,6 +60,20 @@ public: enum { NumLowBitsAvailable = 2 }; }; +// Provide PointerLikeTypeTraits for const things. +template class PointerLikeTypeTraits { + typedef PointerLikeTypeTraits NonConst; + +public: + static inline const void *getAsVoidPointer(const T P) { + return NonConst::getAsVoidPointer(P); + } + static inline const T getFromVoidPointer(const void *P) { + return NonConst::getFromVoidPointer(const_cast(P)); + } + enum { NumLowBitsAvailable = NonConst::NumLowBitsAvailable }; +}; + // Provide PointerLikeTypeTraits for const pointers. template class PointerLikeTypeTraits { typedef PointerLikeTypeTraits NonConst;