[llvm-commits] [llvm] r78076 - /llvm/trunk/include/llvm/Support/type_traits.h

Douglas Gregor dgregor at apple.com
Tue Aug 4 10:04:54 PDT 2009


Author: dgregor
Date: Tue Aug  4 12:04:52 2009
New Revision: 78076

URL: http://llvm.org/viewvc/llvm-project?rev=78076&view=rev
Log:
Add some type traits that are used for Clang's statically-checked
canonical types.

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

Modified: llvm/trunk/include/llvm/Support/type_traits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/type_traits.h?rev=78076&r1=78075&r2=78076&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/type_traits.h (original)
+++ llvm/trunk/include/llvm/Support/type_traits.h Tue Aug  4 12:04:52 2009
@@ -49,6 +49,33 @@
     enum { value = sizeof(char) == sizeof(dont_use::is_class_helper<T>(0)) };
 };
 
+  
+// enable_if_c - Enable/disable a template based on a metafunction
+template<bool Cond, typename T = void>
+struct enable_if_c {
+  typedef T type;
+};
+
+template<typename T> struct enable_if_c<false, T> { };
+  
+// enable_if - Enable/disable a template based on a metafunction
+template<typename Cond, typename T = void>
+struct enable_if : public enable_if_c<Cond::value, T> { };
+
+namespace dont_use {
+  template<typename Base> char base_of_helper(const volatile Base*);
+  template<typename Base> double base_of_helper(...);
+}
+
+/// is_base_of - Metafunction to determine whether one type is a base class of
+/// (or identical to) another type.
+template<typename Base, typename Derived>
+struct is_base_of {
+  static const bool value 
+    = is_class<Base>::value && is_class<Derived>::value &&
+      sizeof(char) == sizeof(dont_use::base_of_helper<Base>((Derived*)0));
+};
+
 }
 
 #endif





More information about the llvm-commits mailing list