[llvm] r297181 - 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.

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 10:47:50 PST 2017


Author: dannyb
Date: Tue Mar  7 12:47:50 2017
New Revision: 297181

URL: http://llvm.org/viewvc/llvm-project?rev=297181&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Support/PointerLikeTypeTraits.h

Modified: llvm/trunk/include/llvm/Support/PointerLikeTypeTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PointerLikeTypeTraits.h?rev=297181&r1=297180&r2=297181&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PointerLikeTypeTraits.h (original)
+++ llvm/trunk/include/llvm/Support/PointerLikeTypeTraits.h Tue Mar  7 12:47:50 2017
@@ -60,6 +60,20 @@ public:
   enum { NumLowBitsAvailable = 2 };
 };
 
+// Provide PointerLikeTypeTraits for const things.
+template <typename T> class PointerLikeTypeTraits<const T> {
+  typedef PointerLikeTypeTraits<T> 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<void *>(P));
+  }
+  enum { NumLowBitsAvailable = NonConst::NumLowBitsAvailable };
+};
+
 // Provide PointerLikeTypeTraits for const pointers.
 template <typename T> class PointerLikeTypeTraits<const T *> {
   typedef PointerLikeTypeTraits<T *> NonConst;




More information about the llvm-commits mailing list