From 1387038988ea3c93c9f0adcb62d2725160f07cf2 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Mon, 6 Sep 2010 19:10:31 +0000 Subject: [PATCH] Working the type_traits area: Hooked up to clang's __is_union. Got has_trivial_copy_assign working. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@113162 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__config | 9 ++++++ include/type_traits | 31 +++++++++++++++---- .../meta/meta.hel/integral_constant.pass.cpp | 2 ++ .../meta.unary.prop/has_copy_assign.pass.cpp | 2 +- .../has_trivial_copy_assign.pass.cpp | 4 +-- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/include/__config b/include/__config index a5a2d1f0..87213fcb 100644 --- a/include/__config +++ b/include/__config @@ -152,6 +152,10 @@ using namespace _LIBCPP_NAMESPACE; #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 @@ using namespace _LIBCPP_NAMESPACE; #endif #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#define _LIBCPP_HAS_NO_CONSTEXPR #ifndef __GXX_EXPERIMENTAL_CXX0X__ @@ -231,4 +236,8 @@ template struct __static_assert_check {}; #define decltype(x) __typeof__(x) #endif +#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#define constexpr const +#endif + #endif // _LIBCPP_CONFIG diff --git a/include/type_traits b/include/type_traits index 5cdcf12f..5624c4ec 100644 --- a/include/type_traits +++ b/include/type_traits @@ -34,7 +34,6 @@ namespace std template struct is_pointer; template struct is_lvalue_reference; template struct is_rvalue_reference; - template struct is_reference; template struct is_member_object_pointer; template struct is_member_function_pointer; template struct is_enum; @@ -152,9 +151,12 @@ struct __two {char _[2];}; template 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 @@ -258,7 +260,7 @@ template struct is_reference<_Tp&&> : public true_type {}; // is_union -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__) template struct is_union : public integral_constant {}; @@ -725,13 +727,30 @@ template struct has_nothrow_move_constructor : public has_nothrow_co template struct has_copy_constructor : public true_type {}; +// has_copy_assign + +template struct has_copy_assign; + // has_trivial_copy_assign -template struct __libcpp_trivial_copy_assign : public integral_constant::value && - is_scalar<_Tp>::value> {}; +#if defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3) + +template ::value> +struct __has_trivial_copy_assign + : public integral_constant {}; + +template struct __has_trivial_copy_assign<_Tp, true> + : public false_type {}; template struct has_trivial_copy_assign - : public __libcpp_trivial_copy_assign::type> {}; + : __has_trivial_copy_assign<_Tp> {}; + +#else + +template struct has_trivial_copy_assign + : public integral_constant::value && !is_const<_Tp>::value> {}; + +#endif // defined(__clang__) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3) // has_nothrow_copy_assign diff --git a/test/utilities/meta/meta.hel/integral_constant.pass.cpp b/test/utilities/meta/meta.hel/integral_constant.pass.cpp index 47b8eaf1..8575cd33 100644 --- a/test/utilities/meta/meta.hel/integral_constant.pass.cpp +++ b/test/utilities/meta/meta.hel/integral_constant.pass.cpp @@ -12,6 +12,7 @@ // integral_constant #include +#include int main() { @@ -19,6 +20,7 @@ int main() 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::value), ""); diff --git a/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp b/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp index 787cd79c..83753752 100644 --- a/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp +++ b/test/utilities/meta/meta.unary/meta.unary.prop/has_copy_assign.pass.cpp @@ -15,5 +15,5 @@ int main() { -#error has_copy_assign not implemented + static_assert((std::has_copy_assign::value), ""); } diff --git a/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp b/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp index 762bd511..9993cbdc 100644 --- a/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp +++ b/test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_copy_assign.pass.cpp @@ -62,9 +62,10 @@ int main() test_has_not_trivial_assign(); test_has_not_trivial_assign(); test_has_not_trivial_assign(); + test_has_not_trivial_assign(); + test_has_not_trivial_assign(); test_has_trivial_assign(); - test_has_trivial_assign(); test_has_trivial_assign(); test_has_trivial_assign(); test_has_trivial_assign(); @@ -72,6 +73,5 @@ int main() test_has_trivial_assign(); test_has_trivial_assign(); test_has_trivial_assign(); - test_has_trivial_assign(); test_has_trivial_assign(); }