[cfe-commits] [libcxx] r113162 - in /libcxx/trunk: include/__config include/type_traits test/utilities/meta/meta.hel/integral_constant.pass.cpp test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp
Howard Hinnant
hhinnant at apple.com
Mon Sep 6 12:10:32 PDT 2010
Author: hhinnant
Date: Mon Sep 6 14:10:31 2010
New Revision: 113162
URL: http://llvm.org/viewvc/llvm-project?rev=113162&view=rev
Log:
Working the type_traits area: Hooked up to clang's __is_union. Got has_trivial_copy_assign working.
Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/type_traits
libcxx/trunk/test/utilities/meta/meta.hel/integral_constant.pass.cpp
libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp
libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp
Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=113162&r1=113161&r2=113162&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Mon Sep 6 14:10:31 2010
@@ -152,6 +152,10 @@
#define _STD std
#endif // __has_feature(cxx_inline_namespaces)
+#if !(__has_feature(cxx_constexpr))
+#define _LIBCPP_HAS_NO_CONSTEXPR
+#endif
+
// end defined(__clang__)
#elif defined(__GNUC__)
@@ -161,6 +165,7 @@
#endif
#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+#define _LIBCPP_HAS_NO_CONSTEXPR
#ifndef __GXX_EXPERIMENTAL_CXX0X__
@@ -231,4 +236,8 @@
#define decltype(x) __typeof__(x)
#endif
+#ifdef _LIBCPP_HAS_NO_CONSTEXPR
+#define constexpr const
+#endif
+
#endif // _LIBCPP_CONFIG
Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=113162&r1=113161&r2=113162&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Mon Sep 6 14:10:31 2010
@@ -34,7 +34,6 @@
template <class T> struct is_pointer;
template <class T> struct is_lvalue_reference;
template <class T> struct is_rvalue_reference;
- template <class T> struct is_reference;
template <class T> struct is_member_object_pointer;
template <class T> struct is_member_function_pointer;
template <class T> struct is_enum;
@@ -152,9 +151,12 @@
template <class _Tp, _Tp __v>
struct integral_constant
{
- static const _Tp value = __v;
+ static constexpr _Tp value = __v;
typedef _Tp value_type;
typedef integral_constant type;
+#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+ constexpr operator value_type() {return value;}
+#endif
};
template <class _Tp, _Tp __v>
@@ -258,7 +260,7 @@
// is_union
-#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3
+#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
template <class _Tp> struct is_union : public integral_constant<bool, __is_union(_Tp)> {};
@@ -725,13 +727,30 @@
template <class _Tp> struct has_copy_constructor : public true_type {};
+// has_copy_assign
+
+template <class _Tp> struct has_copy_assign;
+
// has_trivial_copy_assign
-template <class _Tp> struct __libcpp_trivial_copy_assign : public integral_constant<bool, !is_const<_Tp>::value &&
- is_scalar<_Tp>::value> {};
+#if defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+
+template <class _Tp, bool = is_void<_Tp>::value>
+struct __has_trivial_copy_assign
+ : public integral_constant<bool, __has_trivial_assign(_Tp)> {};
+
+template <class _Tp> struct __has_trivial_copy_assign<_Tp, true>
+ : public false_type {};
template <class _Tp> struct has_trivial_copy_assign
- : public __libcpp_trivial_copy_assign<typename remove_all_extents<_Tp>::type> {};
+ : __has_trivial_copy_assign<_Tp> {};
+
+#else
+
+template <class _Tp> struct has_trivial_copy_assign
+ : public integral_constant<bool, is_scalar<_Tp>::value && !is_const<_Tp>::value> {};
+
+#endif // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
// has_nothrow_copy_assign
Modified: libcxx/trunk/test/utilities/meta/meta.hel/integral_constant.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.hel/integral_constant.pass.cpp?rev=113162&r1=113161&r2=113162&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.hel/integral_constant.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.hel/integral_constant.pass.cpp Mon Sep 6 14:10:31 2010
@@ -12,6 +12,7 @@
// integral_constant
#include <type_traits>
+#include <cassert>
int main()
{
@@ -19,6 +20,7 @@
static_assert(_5::value == 5, "");
static_assert((std::is_same<_5::value_type, int>::value), "");
static_assert((std::is_same<_5::type, _5>::value), "");
+ static_assert((_5() == 5), "");
static_assert(std::false_type::value == false, "");
static_assert((std::is_same<std::false_type::value_type, bool>::value), "");
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=113162&r1=113161&r2=113162&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 Mon Sep 6 14:10:31 2010
@@ -15,5 +15,5 @@
int main()
{
-#error has_copy_assign not implemented
+ static_assert((std::has_copy_assign<int>::value), "");
}
Modified: libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp?rev=113162&r1=113161&r2=113162&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp Mon Sep 6 14:10:31 2010
@@ -62,9 +62,10 @@
test_has_not_trivial_assign<void>();
test_has_not_trivial_assign<A>();
test_has_not_trivial_assign<int&>();
+ test_has_not_trivial_assign<NotEmpty>();
+ test_has_not_trivial_assign<Abstract>();
test_has_trivial_assign<Union>();
- test_has_trivial_assign<Abstract>();
test_has_trivial_assign<Empty>();
test_has_trivial_assign<int>();
test_has_trivial_assign<double>();
@@ -72,6 +73,5 @@
test_has_trivial_assign<const int*>();
test_has_trivial_assign<char[3]>();
test_has_trivial_assign<char[3]>();
- test_has_trivial_assign<NotEmpty>();
test_has_trivial_assign<bit_zero>();
}
More information about the cfe-commits
mailing list