summaryrefslogtreecommitdiff
path: root/include/llvm/Support/type_traits.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-08-04 17:04:52 +0000
committerDouglas Gregor <dgregor@apple.com>2009-08-04 17:04:52 +0000
commitc7a6da6e1469100937851cc3741a36b5850e54da (patch)
tree129b3d7ccef573279856df2e04dd916e641abc1b /include/llvm/Support/type_traits.h
parent7d35249e897dc655c7c884b83d5cb39478ae497c (diff)
downloadllvm-c7a6da6e1469100937851cc3741a36b5850e54da.tar.gz
llvm-c7a6da6e1469100937851cc3741a36b5850e54da.tar.bz2
llvm-c7a6da6e1469100937851cc3741a36b5850e54da.tar.xz
Add some type traits that are used for Clang's statically-checked
canonical types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78076 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/type_traits.h')
-rw-r--r--include/llvm/Support/type_traits.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/llvm/Support/type_traits.h b/include/llvm/Support/type_traits.h
index 5000a8b859..32736b4141 100644
--- a/include/llvm/Support/type_traits.h
+++ b/include/llvm/Support/type_traits.h
@@ -49,6 +49,33 @@ struct is_class
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