[cfe-commits] [libcxx] r170662 - /libcxx/trunk/include/type_traits

Richard Smith richard-llvm at metafoo.co.uk
Wed Dec 19 20:20:28 PST 2012


Author: rsmith
Date: Wed Dec 19 22:20:28 2012
New Revision: 170662

URL: http://llvm.org/viewvc/llvm-project?rev=170662&view=rev
Log:
Implement std::is_base_of for the case where we don't have a compiler
intrinsic. This relies upon the fact that overload resolution does not check
access and ambiguity for a derived-to-base conversion. This passes all
is_base_of tests in the test suite.

Modified:
    libcxx/trunk/include/type_traits

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=170662&r1=170661&r2=170662&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Wed Dec 19 22:20:28 2012
@@ -617,7 +617,28 @@
 
 #else  // __has_feature(is_base_of)
 
-#error is_base_of not implemented.
+namespace __is_base_of_imp
+{
+template <class _Tp>
+struct _Dst
+{
+    _Dst(const volatile _Tp &);
+};
+template <class _Tp>
+struct _Src
+{
+    operator const volatile _Tp &();
+    template <class _Up> operator const _Dst<_Up> &();
+};
+template <size_t> struct __one { typedef char type; };
+template <class _Bp, class _Dp> typename __one<sizeof(_Dst<_Bp>(declval<_Src<_Dp> >()))>::type __test(int);
+template <class _Bp, class _Dp> __two __test(...);
+}
+
+template <class _Bp, class _Dp>
+struct _LIBCPP_VISIBLE is_base_of
+    : public integral_constant<bool, is_class<_Bp>::value &&
+                                     sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {};
 
 #endif  // __has_feature(is_base_of)
 





More information about the cfe-commits mailing list