diff options
| author | Howard Hinnant <hhinnant@apple.com> | 2010-09-07 17:47:31 +0000 |
|---|---|---|
| committer | Howard Hinnant <hhinnant@apple.com> | 2010-09-07 17:47:31 +0000 |
| commit | ba6f71b0309d1389aa0774be08aaf3064f6437e2 (patch) | |
| tree | cdde0bc476dfed87c58f24bb2c6c39c4413343ae /libcxx/include | |
| parent | f0ea2222553ee4acea42c6ef3799eca6240d60ee (diff) | |
| download | bcm5719-llvm-ba6f71b0309d1389aa0774be08aaf3064f6437e2.tar.gz bcm5719-llvm-ba6f71b0309d1389aa0774be08aaf3064f6437e2.zip | |
Made a stab at has_default_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.
llvm-svn: 113225
Diffstat (limited to 'libcxx/include')
| -rw-r--r-- | libcxx/include/type_traits | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index 7a3b81fc6e3..cf6d091d2ef 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -1637,6 +1637,80 @@ struct __is_constructible<false, _A[], _Args...> : public false_type {}; +template <class _Tp> +struct has_default_constructor + : public is_constructible<_Tp> + {}; + +#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE + +// template <class T> struct is_constructible0; + +// main is_constructible0 test + +template <class _Tp> +decltype((_STD::move(_Tp()), true_type())) +__is_constructible0_test(_Tp&); + +false_type +__is_constructible0_test(__any); + +template <bool, class _Tp> +struct __is_constructible0_imp // false, _Tp is not a scalar + : public common_type + < + decltype(__is_constructible0_test(declval<_Tp&>())) + >::type + {}; + +// handle scalars and reference types + +// Scalars are default constructible, references are not + +template <class _Tp> +struct __is_constructible0_imp<true, _Tp> + : public is_scalar<_Tp> + {}; + +// Treat scalars and reference types separately + +template <bool, class _Tp> +struct __is_constructible0_void_check + : public __is_constructible0_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, + _Tp> + {}; + +// If any of T or Args is void, is_constructible should be false + +template <class _Tp> +struct __is_constructible0_void_check<true, _Tp> + : public false_type + {}; + +// has_default_constructor entry point + +template <class _Tp> +struct has_default_constructor + : public __is_constructible0_void_check<is_void<_Tp>::value + || is_abstract<_Tp>::value, + _Tp> + {}; + +// Array types are default constructible if their element type +// is default constructible + +template <class _A, size_t _N> +struct __is_constructible0_imp<false, _A[_N]> + : public has_default_constructor<typename remove_all_extents<_A>::type> + {}; + +// Incomplete array types are not constructible + +template <class _A> +struct __is_constructible0_imp<false, _A[]> + : public false_type + {}; + #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE template <class _Tp> struct __is_zero_default_constructible |

