[cfe-commits] [libcxx] r113373 - in /libcxx/trunk: include/type_traits test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp

Howard Hinnant hhinnant at apple.com
Wed Sep 8 10:55:32 PDT 2010


Author: hhinnant
Date: Wed Sep  8 12:55:32 2010
New Revision: 113373

URL: http://llvm.org/viewvc/llvm-project?rev=113373&view=rev
Log:
Hooked the following up to clang:  is_class, is_enum, has_nothrow_copy_assign, has_trivial_destructor, has_virtual_destructor, is_pod.  Implemented has_copy_assign.

Modified:
    libcxx/trunk/include/type_traits
    libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=113373&r1=113372&r2=113373&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Wed Sep  8 12:55:32 2010
@@ -90,24 +90,31 @@
     template <class T> struct is_empty;
     template <class T> struct is_polymorphic;
     template <class T> struct is_abstract;
+
     template <class T, class... Args> struct is_constructible;
     template <class T, class... Args> struct is_nothrow_constructible;
-    template <class T> struct has_default_constructor;
-    template <class T> struct has_copy_constructor;
-    template <class T> struct has_move_constructor;
-    template <class T> struct has_copy_assign;
-    template <class T> struct has_move_assign;
+
     template <class T> struct has_trivial_default_constructor
-    template <class T> struct has_trivial_copy_constructor;
-    template <class T> struct has_trivial_move_constructor;
-    template <class T> struct has_trivial_copy_assign;
-    template <class T> struct has_trivial_move_assign;
-    template <class T> struct has_trivial_destructor;
     template <class T> struct has_nothrow_default_constructor;
+    template <class T> struct has_default_constructor;
+
+    template <class T> struct has_trivial_copy_constructor;
     template <class T> struct has_nothrow_copy_constructor;
+    template <class T> struct has_copy_constructor;
+
+    template <class T> struct has_trivial_move_constructor;
     template <class T> struct has_nothrow_move_constructor;
+    template <class T> struct has_move_constructor;
+
+    template <class T> struct has_trivial_copy_assign;
     template <class T> struct has_nothrow_copy_assign;
+    template <class T> struct has_copy_assign;
+
+    template <class T> struct has_trivial_move_assign;
     template <class T> struct has_nothrow_move_assign;
+    template <class T> struct has_move_assign;
+
+    template <class T> struct has_trivial_destructor;
     template <class T> struct has_virtual_destructor;
 
     // Relationships between types:
@@ -261,17 +268,25 @@
 
 #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
 
-template <class _Tp> struct is_union : public integral_constant<bool, __is_union(_Tp)> {};
+template <class _Tp> struct is_union
+    : public integral_constant<bool, __is_union(_Tp)> {};
 
-#else  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3
+#else  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
 
 template <class _Tp> struct __libcpp_union : public false_type {};
 template <class _Tp> struct is_union : public __libcpp_union<typename remove_cv<_Tp>::type> {};
 
-#endif  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3
+#endif  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
 
 // is_class
 
+#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
+
+template <class _Tp> struct is_class
+    : public integral_constant<bool, __is_class(_Tp)> {};
+
+#else  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
+
 namespace __is_class_imp
 {
 template <class _Tp> char  __test(int _Tp::*);
@@ -281,6 +296,8 @@
 template <class _Tp> struct is_class
     : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
 
+#endif  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
+
 // is_function
 
 namespace __is_function_imp
@@ -325,6 +342,13 @@
 
 // is_enum
 
+#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
+
+template <class _Tp> struct is_enum
+    : public integral_constant<bool, __is_enum(_Tp)> {};
+
+#else  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
+
 template <class _Tp> struct is_enum
     : public integral_constant<bool, !is_void<_Tp>::value             &&
                                      !is_integral<_Tp>::value         &&
@@ -337,6 +361,8 @@
                                      !is_class<_Tp>::value            &&
                                      !is_function<_Tp>::value         > {};
 
+#endif  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
+
 // is_arithmetic
 
 template <class _Tp> struct is_arithmetic
@@ -424,6 +450,25 @@
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp>
+typename add_rvalue_reference<_Tp>::type
+declval();
+
+#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp>
+typename add_lvalue_reference<_Tp>::type
+declval();
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+struct __any
+{
+    __any(...);
+};
+
 // remove_pointer
 
 template <class _Tp> struct remove_pointer                      {typedef _Tp type;};
@@ -761,10 +806,6 @@
 
 template <class _Tp> struct has_nothrow_move_constructor : public has_nothrow_copy_constructor<_Tp> {};
 
-// has_copy_assign
-
-template <class _Tp> struct has_copy_assign;
-
 // has_trivial_copy_assign
 
 #if defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
@@ -782,27 +823,65 @@
 
 // has_nothrow_copy_assign
 
-template <class _Tp> struct has_nothrow_copy_assign: public has_trivial_copy_assign<_Tp> {};
+#if defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
+template <class _Tp> struct has_nothrow_copy_assign
+    : public integral_constant<bool, __has_nothrow_assign(_Tp)> {};
+
+#else  // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
+template <class _Tp> struct has_nothrow_copy_assign
+    : public has_trivial_copy_assign<_Tp> {};
+
+#endif  // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
 
 // has_trivial_destructor
 
-template <class _Tp> struct __libcpp_trivial_destructor : public integral_constant<bool, is_scalar<_Tp>::value ||
-                                                                                      is_reference<_Tp>::value> {};
+#if defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
+template <class _Tp> struct has_trivial_destructor
+    : public integral_constant<bool, __has_trivial_destructor(_Tp)> {};
+
+#else  // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
+template <class _Tp> struct __libcpp_trivial_destructor
+    : public integral_constant<bool, is_scalar<_Tp>::value ||
+                                     is_reference<_Tp>::value> {};
 
 template <class _Tp> struct has_trivial_destructor
     : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
 
+#endif  // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
 // has_virtual_destructor
 
+#if defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
+template <class _Tp> struct has_virtual_destructor
+    : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
+
+#else  // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
 template <class _Tp> struct has_virtual_destructor : public false_type {};
 
+#endif  // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
 // is_pod
 
+#if defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
+template <class _Tp> struct is_pod
+    : public integral_constant<bool, __is_pod(_Tp)> {};
+
+#else  // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
 template <class _Tp> struct is_pod : public integral_constant<bool, has_trivial_default_constructor<_Tp>::value   &&
                                                                     has_trivial_copy_constructor<_Tp>::value      &&
                                                                     has_trivial_copy_assign<_Tp>::value    &&
                                                                     has_trivial_destructor<_Tp>::value> {};
 
+#endif  // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
 // alignment_of
 
 template <class _Tp> struct __alignment_of {_Tp _;};
@@ -1171,6 +1250,44 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
+template <class _Tp, class _Arg>
+decltype((_STD::declval<_Tp>() = _STD::declval<_Arg>(), true_type()))
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+__is_assignable_test(_Tp&&, _Arg&&);
+#else
+__is_assignable_test(_Tp&, _Arg&);
+#endif
+
+template <class _Arg>
+false_type
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+__is_assignable_test(__any, _Arg&&);
+#else
+__is_assignable_test(__any, _Arg&);
+#endif
+
+template <class _Tp, class _Arg>
+struct __is_assignable_imp
+    : public common_type
+        <
+            decltype(__is_assignable_test(declval<_Tp>(), declval<_Arg>()))
+        >::type {};
+
+template <class _Tp, class _Arg>
+struct __is_assignable
+    : public __is_assignable_imp<_Tp, _Arg> {};
+
+// has_copy_assign
+
+template <class _Tp> struct has_copy_assign
+    : public __is_assignable<_Tp&, const _Tp&> {};
+
+template <class _Tp> struct has_copy_assign<_Tp[]>
+    : public false_type {};
+
+template <class _Tp> struct has_copy_assign<_Tp&>
+    : public false_type {};
+
 // move
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1313,20 +1430,6 @@
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-template <class _Tp>
-typename add_rvalue_reference<_Tp>::type
-declval();
-
-#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-template <class _Tp>
-typename add_lvalue_reference<_Tp>::type
-declval();
-
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
 template <class _Tp>
 struct decay
 {
@@ -1521,11 +1624,6 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-struct __any
-{
-    __any(...);
-};
-
 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
 
 // template <class T, class... Args> struct is_constructible;

Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp?rev=113373&r1=113372&r2=113373&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp Wed Sep  8 12:55:32 2010
@@ -13,7 +13,38 @@
 
 #include <type_traits>
 
+class Empty
+{
+};
+
+class NotEmpty
+{
+public:
+    virtual ~NotEmpty();
+};
+
+union Union {};
+
+struct bit_zero
+{
+    int :  0;
+};
+
+struct A
+{
+    A();
+};
+
 int main()
 {
-    static_assert((std::has_copy_assign<int>::value), "");
+    static_assert(( std::has_copy_assign<int>::value), "");
+    static_assert((!std::has_copy_assign<const int>::value), "");
+    static_assert((!std::has_copy_assign<int[]>::value), "");
+    static_assert((!std::has_copy_assign<int[3]>::value), "");
+    static_assert((!std::has_copy_assign<int&>::value), "");
+    static_assert(( std::has_copy_assign<A>::value), "");
+    static_assert(( std::has_copy_assign<bit_zero>::value), "");
+    static_assert(( std::has_copy_assign<Union>::value), "");
+    static_assert(( std::has_copy_assign<NotEmpty>::value), "");
+    static_assert(( std::has_copy_assign<Empty>::value), "");
 }





More information about the cfe-commits mailing list