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

Howard Hinnant hhinnant at apple.com
Tue Sep 7 16:11:28 PDT 2010


Author: hhinnant
Date: Tue Sep  7 18:11:28 2010
New Revision: 113304

URL: http://llvm.org/viewvc/llvm-project?rev=113304&view=rev
Log:
Made a stab at has_copy_constructor.  Got it mostly working for g++-4.0, but only works for scalar types on clang.  Ultimately this needs a compiler-supported is_constructible which clang is missing, and won't be able to use until it gets variadic templates.

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

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=113304&r1=113303&r2=113304&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Tue Sep  7 18:11:28 2010
@@ -761,10 +761,6 @@
 
 template <class _Tp> struct has_nothrow_move_constructor : public has_nothrow_copy_constructor<_Tp> {};
 
-// has_copy_constructor
-
-template <class _Tp> struct has_copy_constructor : public true_type {};
-
 // has_copy_assign
 
 template <class _Tp> struct has_copy_assign;
@@ -1732,6 +1728,24 @@
 
 #endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
 
+// has_copy_constructor
+
+#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
+
+template <class _Tp>
+struct has_copy_constructor
+    : public is_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
+    {};
+
+#else  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
+
+template <class _Tp>
+struct has_copy_constructor
+    : public has_nothrow_copy_constructor<_Tp>
+    {};
+
+#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
+
 template <class _Tp> struct __is_zero_default_constructible
     : public integral_constant<bool, is_scalar<_Tp>::value || is_empty<_Tp>::value> {};
 

Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_constructor.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_constructor.pass.cpp?rev=113304&r1=113303&r2=113304&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_constructor.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_constructor.pass.cpp Tue Sep  7 18:11:28 2010
@@ -13,7 +13,55 @@
 
 #include <type_traits>
 
+template <class T, bool Result>
+void test_has_copy_constructor()
+{
+    static_assert(std::has_copy_constructor<T>::value == Result, "");
+}
+
+class Empty
+{
+};
+
+class NotEmpty
+{
+public:
+    virtual ~NotEmpty();
+};
+
+union Union {};
+
+struct bit_zero
+{
+    int :  0;
+};
+
+class Abstract
+{
+public:
+    virtual ~Abstract() = 0;
+};
+
+struct A
+{
+    A(const A&);
+};
+
 int main()
 {
-#error has_copy_constructor not implemented
+    test_has_copy_constructor<char[3], false>();
+    test_has_copy_constructor<char[], false>();
+    test_has_copy_constructor<void, false>();
+    test_has_copy_constructor<Abstract, false>();
+
+    test_has_copy_constructor<A, true>();
+    test_has_copy_constructor<int&, true>();
+    test_has_copy_constructor<Union, true>();
+    test_has_copy_constructor<Empty, true>();
+    test_has_copy_constructor<int, true>();
+    test_has_copy_constructor<double, true>();
+    test_has_copy_constructor<int*, true>();
+    test_has_copy_constructor<const int*, true>();
+    test_has_copy_constructor<NotEmpty, true>();
+    test_has_copy_constructor<bit_zero, true>();
 }

Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_constructor.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_constructor.pass.cpp?rev=113304&r1=113303&r2=113304&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_constructor.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_nothrow_copy_constructor.pass.cpp Tue Sep  7 18:11:28 2010
@@ -61,11 +61,11 @@
 
 int main()
 {
-//    test_has_not_nothrow_copy_constructor<void>();
+    test_has_not_nothrow_copy_constructor<void>();
     test_has_not_nothrow_copy_constructor<A>();
     test_has_not_nothrow_copy_constructor<Abstract>();
-//    test_has_not_nothrow_copy_constructor<char[3]>();
-//    test_has_not_nothrow_copy_constructor<char[]>();
+    test_has_not_nothrow_copy_constructor<char[3]>();
+    test_has_not_nothrow_copy_constructor<char[]>();
 
     test_has_nothrow_copy_constructor<int&>();
     test_has_nothrow_copy_constructor<Union>();
@@ -74,6 +74,6 @@
     test_has_nothrow_copy_constructor<double>();
     test_has_nothrow_copy_constructor<int*>();
     test_has_nothrow_copy_constructor<const int*>();
-//    test_has_nothrow_copy_constructor<NotEmpty>();
+    test_has_nothrow_copy_constructor<NotEmpty>();
     test_has_nothrow_copy_constructor<bit_zero>();
 }





More information about the cfe-commits mailing list