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

@@ -13,7 +13,58 @@
#include <type_traits>
template <class T, bool Result>
void test_has_default_constructor()
{
static_assert(std::has_default_constructor<T>::value == Result, "");
static_assert(std::has_default_constructor<const T>::value == Result, "");
static_assert(std::has_default_constructor<volatile T>::value == Result, "");
static_assert(std::has_default_constructor<const volatile T>::value == Result, "");
}
class Empty
{
};
class NotEmpty
{
public:
virtual ~NotEmpty();
};
union Union {};
struct bit_zero
{
int : 0;
};
class Abstract
{
public:
virtual ~Abstract() = 0;
};
struct A
{
A();
};
int main()
{
#error has_default_constructor not implemented
test_has_default_constructor<void, false>();
test_has_default_constructor<int&, false>();
test_has_default_constructor<char[], false>();
test_has_default_constructor<Abstract, false>();
test_has_default_constructor<A, true>();
test_has_default_constructor<Union, true>();
test_has_default_constructor<Empty, true>();
test_has_default_constructor<int, true>();
test_has_default_constructor<double, true>();
test_has_default_constructor<int*, true>();
test_has_default_constructor<const int*, true>();
test_has_default_constructor<char[3], true>();
test_has_default_constructor<NotEmpty, true>();
test_has_default_constructor<bit_zero, true>();
}

View File

@@ -37,6 +37,7 @@ class Empty
class NotEmpty
{
public:
virtual ~NotEmpty();
};
@@ -49,6 +50,7 @@ struct bit_zero
class Abstract
{
public:
virtual ~Abstract() = 0;
};