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.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@113225 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant
2010-09-07 17:47:31 +00:00
parent 6fd2e09b36
commit bb73d762b2
3 changed files with 128 additions and 1 deletions

View File

@@ -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