Added template function alignof() which provides a clean
authorTed Kremenek <kremenek@apple.com>
Wed, 17 Oct 2007 22:08:55 +0000 (22:08 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 17 Oct 2007 22:08:55 +0000 (22:08 +0000)
function-based interface to getting the alignment of a type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43096 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/AlignOf.h

index f27ecdd7130ffd929846ed9b28a71e7ac10326f4..0911bb84b36d4bb22263c6ccf9ff3f49b04c51c1 100644 (file)
@@ -38,6 +38,13 @@ template <typename T>
 struct AlignOf {
   enum { Alignment = sizeof(AlignmentCalcImpl<T>) - sizeof(T) };
 };
+
+/// alignof - A templated function that returns the mininum alignment of
+///  of a type.  This provides no extra functionality beyond the AlignOf
+///  class besides some cosmetic cleanliness.  Example usage:
+///  alignof<int>() returns the alignment of an int.
+template <typename T>
+static inline unsigned alignof() { return AlignOf<T>::Alignment; }
   
 } // end namespace llvm
 #endif