From 5d37fb32d2a235381a6efe96ebbcfa5e79db97af Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Wed, 11 May 2011 20:19:40 +0000 Subject: [PATCH] Redid nothrow traits in terms of non-nothrow traits when noexcept is available git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@131198 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__config | 15 +++++++- include/type_traits | 88 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 97 insertions(+), 6 deletions(-) diff --git a/include/__config b/include/__config index c47029f6..5ccc5ec3 100644 --- a/include/__config +++ b/include/__config @@ -86,8 +86,9 @@ #if defined(__clang__) -#define _LIBCPP_HAS_NO_ADVANCED_SFINAE +//#if !__has_feature(cxx_alias_templates) #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES +//#endif #ifndef __GXX_EXPERIMENTAL_CXX0X__ #ifdef __linux__ @@ -138,6 +139,7 @@ typedef __char32_t char32_t; #if !(__has_feature(cxx_auto_type)) #define _LIBCPP_HAS_NO_AUTO_TYPE +#define _LIBCPP_HAS_NO_ADVANCED_SFINAE #endif #if !(__has_feature(cxx_variadic_templates)) @@ -162,6 +164,14 @@ namespace std { #define _LIBCPP_HAS_NO_CONSTEXPR #endif +#if (__has_feature(cxx_noexcept)) +# define _NOEXCEPT noexcept +# define _NOEXCEPT_(x) noexcept(x) +#else +# define _NOEXCEPT throw() +# define _NOEXCEPT_(x) +#endif + // end defined(__clang__) #elif defined(__GNUC__) @@ -173,6 +183,9 @@ namespace std { #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES #define _LIBCPP_HAS_NO_CONSTEXPR +#define _NOEXCEPT throw() +#define _NOEXCEPT_(x) + #ifndef __GXX_EXPERIMENTAL_CXX0X__ #define _LIBCPP_HAS_NO_ADVANCED_SFINAE diff --git a/include/type_traits b/include/type_traits index c0063616..819de786 100644 --- a/include/type_traits +++ b/include/type_traits @@ -490,7 +490,7 @@ template <> struct _LIBCPP_VISIBLE add_rvalue_reference typename add_rvalue_reference<_Tp>::type -declval(); +declval() _NOEXCEPT; #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -2121,6 +2121,30 @@ template struct _LIBCPP_VISIBLE is_trivially_destructible #ifndef _LIBCPP_HAS_NO_VARIADICS +#if __has_feature(cxx_noexcept) + +template struct __is_nothrow_constructible; + +template +struct __is_nothrow_constructible + : public integral_constant()...))> +{ +}; + +template +struct __is_nothrow_constructible + : public false_type +{ +}; + +template +struct _LIBCPP_VISIBLE is_nothrow_constructible + : __is_nothrow_constructible::value, _Tp, _Args...> +{ +}; + +#else // __has_feature(cxx_noexcept) + template struct _LIBCPP_VISIBLE is_nothrow_constructible : false_type @@ -2171,6 +2195,8 @@ struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&> { }; +#endif // __has_feature(cxx_noexcept) + #else // _LIBCPP_HAS_NO_VARIADICS template struct _LIBCPP_VISIBLE is_nothrow_move_constructible // is_nothrow_assignable +#if __has_feature(cxx_noexcept) + +template struct __is_nothrow_assignable; + template -struct is_nothrow_assignable +struct __is_nothrow_assignable + : public false_type +{ +}; + +template +struct __is_nothrow_assignable + : public integral_constant() = _STD::declval<_Arg>()) > +{ +}; + +template +struct _LIBCPP_VISIBLE is_nothrow_assignable + : public __is_nothrow_assignable::value, _Tp, _Arg> +{ +}; + +#else // __has_feature(cxx_noexcept) + +template +struct _LIBCPP_VISIBLE is_nothrow_assignable : public false_type {}; template -struct is_nothrow_assignable<_Tp&, _Tp> +struct _LIBCPP_VISIBLE is_nothrow_assignable<_Tp&, _Tp> #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) : integral_constant {}; #else @@ -2263,7 +2313,7 @@ struct is_nothrow_assignable<_Tp&, _Tp> #endif template -struct is_nothrow_assignable<_Tp&, _Tp&> +struct _LIBCPP_VISIBLE is_nothrow_assignable<_Tp&, _Tp&> #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) : integral_constant {}; #else @@ -2271,7 +2321,7 @@ struct is_nothrow_assignable<_Tp&, _Tp&> #endif template -struct is_nothrow_assignable<_Tp&, const _Tp&> +struct _LIBCPP_VISIBLE is_nothrow_assignable<_Tp&, const _Tp&> #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) : integral_constant {}; #else @@ -2290,6 +2340,8 @@ struct is_nothrow_assignable<_Tp&, _Tp&&> #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // __has_feature(cxx_noexcept) + // is_nothrow_copy_assignable template struct _LIBCPP_VISIBLE is_nothrow_copy_assignable @@ -2310,6 +2362,30 @@ template struct _LIBCPP_VISIBLE is_nothrow_move_assignable // is_nothrow_destructible +#if __has_feature(cxx_noexcept) + +template struct __is_nothrow_destructible; + +template +struct __is_nothrow_destructible + : public false_type +{ +}; + +template +struct __is_nothrow_destructible + : public integral_constant().~_Tp()) > +{ +}; + +template +struct _LIBCPP_VISIBLE is_nothrow_destructible + : public __is_nothrow_destructible::value, _Tp> +{ +}; + +#else + template struct __libcpp_nothrow_destructor : public integral_constant::value || is_reference<_Tp>::value> {}; @@ -2317,6 +2393,8 @@ template struct __libcpp_nothrow_destructor template struct _LIBCPP_VISIBLE is_nothrow_destructible : public __libcpp_nothrow_destructor::type> {}; +#endif + // is_pod #if __has_feature(is_pod) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)