Commit b0302c68 by Paolo Carlini Committed by Paolo Carlini

type_traits (__is_constructible_helper1): Rename to __is_constructible_helper1...

2009-12-31  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/std/type_traits (__is_constructible_helper1): Rename
	to __is_constructible_helper1, tweaked to a specialization of
	__is_constructible_helper.
	(is_constructible): Adjust; minor formatting and stylistic
	changes throughout.
	* testsuite/util/testsuite_tr1.h (test_relationship): Change
	variadic version to an overload of test_property.
	* testsuite/20_util/is_constructible/value.cc: Adjust.
	* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
	Adjust dg-error line numbers.
	* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
	Likewise.
	* testsuite/20_util/declval/requirements/1_neg.cc: Likewise.

From-SVN: r155536
parent 8c7dc6eb
2009-12-31 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/type_traits (__is_constructible_helper1): Rename
to __is_constructible_helper1, tweaked to a specialization of
__is_constructible_helper.
(is_constructible): Adjust; minor formatting and stylistic
changes throughout.
* testsuite/util/testsuite_tr1.h (test_relationship): Change
variadic version to an overload of test_property.
* testsuite/20_util/is_constructible/value.cc: Adjust.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
Adjust dg-error line numbers.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
Likewise.
* testsuite/20_util/declval/requirements/1_neg.cc: Likewise.
2009-12-30 Paolo Carlini <paolo.carlini@oracle.com> 2009-12-30 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/type_traits: Fix minor formatting nit. * include/std/type_traits: Fix minor formatting nit.
......
...@@ -173,6 +173,18 @@ namespace std ...@@ -173,6 +173,18 @@ namespace std
// Member introspection. // Member introspection.
/// is_trivial
template<typename _Tp>
struct is_trivial
: public integral_constant<bool, __is_trivial(_Tp)>
{ };
/// is_standard_layout
template<typename _Tp>
struct is_standard_layout
: public integral_constant<bool, __is_standard_layout(_Tp)>
{ };
/// is_pod /// is_pod
// Could use is_standard_layout && is_trivial instead of the builtin. // Could use is_standard_layout && is_trivial instead of the builtin.
template<typename _Tp> template<typename _Tp>
...@@ -180,10 +192,46 @@ namespace std ...@@ -180,10 +192,46 @@ namespace std
: public integral_constant<bool, __is_pod(_Tp)> : public integral_constant<bool, __is_pod(_Tp)>
{ }; { };
/// is_standard_layout
template<typename _Tp> template<typename _Tp>
struct is_standard_layout typename add_rvalue_reference<_Tp>::type declval();
: public integral_constant<bool, __is_standard_layout(_Tp)>
template<typename _Tp, typename... _Args>
class __is_constructible_helper
: public __sfinae_types
{
template<typename _Tp1, typename... __Args1>
static decltype(_Tp1(declval<__Args1>()...), __one()) __test(int);
template<typename, typename...>
static __two __test(...);
public:
static const bool __value = sizeof(__test<_Tp, _Args...>(0)) == 1;
};
template<typename _Tp, typename _Arg>
class __is_constructible_helper<_Tp, _Arg>
: public __sfinae_types
{
template<typename _Tp1, typename _Arg1>
static decltype(static_cast<_Tp1>(declval<_Arg1>()), __one())
__test(int);
template<typename, typename>
static __two __test(...);
public:
static const bool __value = sizeof(__test<_Tp, _Arg>(0)) == 1;
};
/// is_constructible
// XXX FIXME
// The C++0x specifications require front-end support, see N2255.
template<typename _Tp, typename... _Args>
struct is_constructible
: public integral_constant<bool,
__is_constructible_helper<_Tp,
_Args...>::__value>
{ }; { };
/// has_trivial_default_constructor /// has_trivial_default_constructor
...@@ -210,12 +258,6 @@ namespace std ...@@ -210,12 +258,6 @@ namespace std
: public integral_constant<bool, __has_trivial_destructor(_Tp)> : public integral_constant<bool, __has_trivial_destructor(_Tp)>
{ }; { };
/// is_trivial
template<typename _Tp>
struct is_trivial
: public integral_constant<bool, __is_trivial(_Tp)>
{ };
/// has_nothrow_default_constructor /// has_nothrow_default_constructor
template<typename _Tp> template<typename _Tp>
struct has_nothrow_default_constructor struct has_nothrow_default_constructor
...@@ -234,16 +276,14 @@ namespace std ...@@ -234,16 +276,14 @@ namespace std
: public integral_constant<bool, __has_nothrow_assign(_Tp)> : public integral_constant<bool, __has_nothrow_assign(_Tp)>
{ }; { };
// Relationships between types.
/// is_base_of /// is_base_of
template<typename _Base, typename _Derived> template<typename _Base, typename _Derived>
struct is_base_of struct is_base_of
: public integral_constant<bool, __is_base_of(_Base, _Derived)> : public integral_constant<bool, __is_base_of(_Base, _Derived)>
{ }; { };
template<typename _Tp>
typename add_rvalue_reference<_Tp>::type declval();
// Relationships between types.
template<typename _From, typename _To, template<typename _From, typename _To,
bool = (is_void<_From>::value || is_void<_To>::value bool = (is_void<_From>::value || is_void<_To>::value
|| is_function<_To>::value || is_array<_To>::value)> || is_function<_To>::value || is_array<_To>::value)>
...@@ -252,10 +292,9 @@ namespace std ...@@ -252,10 +292,9 @@ namespace std
&& is_void<_To>::value); }; && is_void<_To>::value); };
template<typename _From, typename _To> template<typename _From, typename _To>
struct __is_convertible_helper<_From, _To, false> class __is_convertible_helper<_From, _To, false>
: public __sfinae_types : public __sfinae_types
{ {
private:
static __one __test(_To); static __one __test(_To);
static __two __test(...); static __two __test(...);
...@@ -263,59 +302,16 @@ namespace std ...@@ -263,59 +302,16 @@ namespace std
static const bool __value = sizeof(__test(declval<_From>())) == 1; static const bool __value = sizeof(__test(declval<_From>())) == 1;
}; };
/// is_convertible
// XXX FIXME // XXX FIXME
// The C++0x specifications require front-end support, see N2255. // The C++0x specifications require front-end support, see N2255.
/// is_convertible
template<typename _From, typename _To> template<typename _From, typename _To>
struct is_convertible struct is_convertible
: public integral_constant<bool, : public integral_constant<bool,
__is_convertible_helper<_From, _To>::__value> __is_convertible_helper<_From, _To>::__value>
{ }; { };
template<typename _To, typename... _From> /// is_explicitly_convertible
struct __is_constructible_helper
: public __sfinae_types
{
private:
template<typename _To1, typename... _From1>
static decltype(_To1(declval<_From1>()...), __one()) __test(int);
template<typename, typename...>
static __two __test(...);
public:
static const bool __value = sizeof(__test<_To, _From...>(0)) == 1;
};
template<typename _To, typename... _From>
struct is_constructible
: public integral_constant<bool,
__is_constructible_helper<_To,
_From...>::__value>
{ };
template<typename _To, typename _From>
struct __is_constructible_helper1
: public __sfinae_types
{
private:
template<typename _To1, typename _From1>
static decltype(static_cast<_To1>(declval<_From1>()), __one())
__test(int);
template<typename, typename>
static __two __test(...);
public:
static const bool __value = sizeof(__test<_To, _From>(0)) == 1;
};
template<typename _To, typename _From>
struct is_constructible<_To, _From>
: public integral_constant<bool,
__is_constructible_helper1<_To, _From>::__value>
{ };
template<typename _From, typename _To> template<typename _From, typename _To>
struct is_explicitly_convertible struct is_explicitly_convertible
: public is_constructible<_To, _From> : public is_constructible<_To, _From>
...@@ -401,9 +397,8 @@ namespace std ...@@ -401,9 +397,8 @@ namespace std
/// decay /// decay
template<typename _Tp> template<typename _Tp>
struct decay class decay
{ {
private:
typedef typename remove_reference<_Tp>::type __remove_type; typedef typename remove_reference<_Tp>::type __remove_type;
public: public:
...@@ -434,9 +429,8 @@ namespace std ...@@ -434,9 +429,8 @@ namespace std
template<typename _Qualified, typename _Unqualified, template<typename _Qualified, typename _Unqualified,
bool _IsConst = is_const<_Qualified>::value, bool _IsConst = is_const<_Qualified>::value,
bool _IsVol = is_volatile<_Qualified>::value> bool _IsVol = is_volatile<_Qualified>::value>
struct __match_cv_qualifiers class __match_cv_qualifiers
{ {
private:
typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match; typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
public: public:
...@@ -478,12 +472,11 @@ namespace std ...@@ -478,12 +472,11 @@ namespace std
template<typename _Tp, template<typename _Tp,
bool _IsInt = is_integral<_Tp>::value, bool _IsInt = is_integral<_Tp>::value,
bool _IsEnum = is_enum<_Tp>::value> bool _IsEnum = is_enum<_Tp>::value>
struct __make_unsigned_selector; class __make_unsigned_selector;
template<typename _Tp> template<typename _Tp>
struct __make_unsigned_selector<_Tp, true, false> class __make_unsigned_selector<_Tp, true, false>
{ {
private:
typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt; typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
typedef typename __unsignedt::__type __unsigned_type; typedef typename __unsignedt::__type __unsigned_type;
typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned; typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
...@@ -493,9 +486,8 @@ namespace std ...@@ -493,9 +486,8 @@ namespace std
}; };
template<typename _Tp> template<typename _Tp>
struct __make_unsigned_selector<_Tp, false, true> class __make_unsigned_selector<_Tp, false, true>
{ {
private:
// With -fshort-enums, an enum may be as small as a char. // With -fshort-enums, an enum may be as small as a char.
typedef unsigned char __smallest; typedef unsigned char __smallest;
static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
...@@ -557,12 +549,11 @@ namespace std ...@@ -557,12 +549,11 @@ namespace std
template<typename _Tp, template<typename _Tp,
bool _IsInt = is_integral<_Tp>::value, bool _IsInt = is_integral<_Tp>::value,
bool _IsEnum = is_enum<_Tp>::value> bool _IsEnum = is_enum<_Tp>::value>
struct __make_signed_selector; class __make_signed_selector;
template<typename _Tp> template<typename _Tp>
struct __make_signed_selector<_Tp, true, false> class __make_signed_selector<_Tp, true, false>
{ {
private:
typedef __make_signed<typename remove_cv<_Tp>::type> __signedt; typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
typedef typename __signedt::__type __signed_type; typedef typename __signedt::__type __signed_type;
typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed; typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
...@@ -572,9 +563,8 @@ namespace std ...@@ -572,9 +563,8 @@ namespace std
}; };
template<typename _Tp> template<typename _Tp>
struct __make_signed_selector<_Tp, false, true> class __make_signed_selector<_Tp, false, true>
{ {
private:
// With -fshort-enums, an enum may be as small as a char. // With -fshort-enums, an enum may be as small as a char.
typedef signed char __smallest; typedef signed char __smallest;
static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
// with this library; see the file COPYING3. If not see // with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-error "static assertion failed" "" { target *-*-* } 636 } // { dg-error "static assertion failed" "" { target *-*-* } 626 }
// { dg-error "instantiated from here" "" { target *-*-* } 30 } // { dg-error "instantiated from here" "" { target *-*-* } 30 }
// { dg-excess-errors "In function" } // { dg-excess-errors "In function" }
......
...@@ -28,16 +28,13 @@ void test01() ...@@ -28,16 +28,13 @@ void test01()
using namespace __gnu_test; using namespace __gnu_test;
// Positive tests. // Positive tests.
VERIFY( (test_relationship<is_constructible, ExplicitClass, VERIFY( (test_property<is_constructible, ExplicitClass, double&>(true)) );
double&>(true)) ); VERIFY( (test_property<is_constructible, ExplicitClass, int&>(true)) );
VERIFY( (test_relationship<is_constructible, ExplicitClass,
int&>(true)) );
// Negative tests. // Negative tests.
VERIFY( (test_relationship<is_constructible, ExplicitClass, VERIFY( (test_property<is_constructible, ExplicitClass, void*>(false)) );
void*>(false)) ); VERIFY( (test_property<is_constructible, ExplicitClass>(false)) );
VERIFY( (test_relationship<is_constructible, ExplicitClass>(false)) ); VERIFY( (test_property<is_constructible, ExplicitClass,
VERIFY( (test_relationship<is_constructible, ExplicitClass,
int, double>(false)) ); int, double>(false)) );
} }
......
...@@ -48,8 +48,8 @@ void test01() ...@@ -48,8 +48,8 @@ void test01()
// { dg-error "instantiated from here" "" { target *-*-* } 40 } // { dg-error "instantiated from here" "" { target *-*-* } 40 }
// { dg-error "instantiated from here" "" { target *-*-* } 42 } // { dg-error "instantiated from here" "" { target *-*-* } 42 }
// { dg-error "invalid use of incomplete type" "" { target *-*-* } 598 } // { dg-error "invalid use of incomplete type" "" { target *-*-* } 588 }
// { dg-error "declaration of" "" { target *-*-* } 560 } // { dg-error "declaration of" "" { target *-*-* } 552 }
// { dg-excess-errors "At global scope" } // { dg-excess-errors "At global scope" }
// { dg-excess-errors "In instantiation of" } // { dg-excess-errors "In instantiation of" }
...@@ -48,8 +48,8 @@ void test01() ...@@ -48,8 +48,8 @@ void test01()
// { dg-error "instantiated from here" "" { target *-*-* } 40 } // { dg-error "instantiated from here" "" { target *-*-* } 40 }
// { dg-error "instantiated from here" "" { target *-*-* } 42 } // { dg-error "instantiated from here" "" { target *-*-* } 42 }
// { dg-error "invalid use of incomplete type" "" { target *-*-* } 519 } // { dg-error "invalid use of incomplete type" "" { target *-*-* } 511 }
// { dg-error "declaration of" "" { target *-*-* } 481 } // { dg-error "declaration of" "" { target *-*-* } 475 }
// { dg-excess-errors "At global scope" } // { dg-excess-errors "At global scope" }
// { dg-excess-errors "In instantiation of" } // { dg-excess-errors "In instantiation of" }
...@@ -56,8 +56,7 @@ namespace __gnu_test ...@@ -56,8 +56,7 @@ namespace __gnu_test
// For testing tr1/type_traits/extent, which has a second template // For testing tr1/type_traits/extent, which has a second template
// parameter. // parameter.
template<template<typename, unsigned> class Property, template<template<typename, unsigned> class Property,
typename Type, typename Type, unsigned Uint>
unsigned Uint>
bool bool
test_property(typename Property<Type, Uint>::value_type value) test_property(typename Property<Type, Uint>::value_type value)
{ {
...@@ -68,17 +67,17 @@ namespace __gnu_test ...@@ -68,17 +67,17 @@ namespace __gnu_test
} }
#ifdef __GXX_EXPERIMENTAL_CXX0X__ #ifdef __GXX_EXPERIMENTAL_CXX0X__
template<template<typename...> class Relationship, template<template<typename...> class Property, typename... Types>
typename... Types>
bool bool
test_relationship(bool value) test_property(typename Property<Types...>::value_type value)
{ {
bool ret = true; bool ret = true;
ret &= Relationship<Types...>::value == value; ret &= Property<Types...>::value == value;
ret &= Relationship<Types...>::type::value == value; ret &= Property<Types...>::type::value == value;
return ret; return ret;
} }
#else #endif
template<template<typename, typename> class Relationship, template<template<typename, typename> class Relationship,
typename Type1, typename Type2> typename Type1, typename Type2>
bool bool
...@@ -89,7 +88,6 @@ namespace __gnu_test ...@@ -89,7 +88,6 @@ namespace __gnu_test
ret &= Relationship<Type1, Type2>::type::value == value; ret &= Relationship<Type1, Type2>::type::value == value;
return ret; return ret;
} }
#endif
// Test types. // Test types.
class ClassType { }; class ClassType { };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment