mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-14 08:09:33 +08:00
type_traits: Implement is_enum (usual caveats about the nasty consequences of c++/19076...).
2004-12-25 Paolo Carlini <pcarlini@suse.de> * include/tr1/type_traits: Implement is_enum (usual caveats about the nasty consequences of c++/19076...). * testsuite/testsuite_tr1.h: Add ConvType. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_scalar/is_scalar.cc: New. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_scalar/typedefs.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_enum/is_enum.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_enum/typedefs.cc: Likewise. From-SVN: r92604
This commit is contained in:
parent
7f514158b2
commit
a9e7ba8139
@ -1,3 +1,17 @@
|
||||
2004-12-25 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/tr1/type_traits: Implement is_enum (usual caveats about
|
||||
the nasty consequences of c++/19076...).
|
||||
* testsuite/testsuite_tr1.h: Add ConvType.
|
||||
* testsuite/tr1/4_metaprogramming/composite_type_traits/
|
||||
is_scalar/is_scalar.cc: New.
|
||||
* testsuite/tr1/4_metaprogramming/composite_type_traits/
|
||||
is_scalar/typedefs.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/primary_type_categories/
|
||||
is_enum/is_enum.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/primary_type_categories/
|
||||
is_enum/typedefs.cc: Likewise.
|
||||
|
||||
2004-12-24 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/tr1/type_traits: Add missing undef.
|
||||
|
@ -33,7 +33,7 @@ namespace std
|
||||
{
|
||||
namespace tr1
|
||||
{
|
||||
// For use in is_function and elsewhere.
|
||||
// For use in is_enum, is_function, and elsewhere.
|
||||
struct __sfinae_types
|
||||
{
|
||||
typedef char __one;
|
||||
@ -149,14 +149,57 @@ namespace tr1
|
||||
: public false_type { };
|
||||
_DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*)
|
||||
|
||||
template<typename _Tp, bool = (is_fundamental<_Tp>::value
|
||||
|| is_array<_Tp>::value
|
||||
|| is_pointer<_Tp>::value
|
||||
|| is_reference<_Tp>::value
|
||||
|| is_member_pointer<_Tp>::value
|
||||
|| is_function<_Tp>::value)>
|
||||
struct __is_enum_helper
|
||||
: public __sfinae_types
|
||||
{
|
||||
private:
|
||||
static __one __test(bool);
|
||||
static __one __test(char);
|
||||
static __one __test(signed char);
|
||||
static __one __test(unsigned char);
|
||||
#ifdef _GLIBCXX_USE_WCHAR_T
|
||||
static __one __test(wchar_t);
|
||||
#endif
|
||||
static __one __test(short);
|
||||
static __one __test(unsigned short);
|
||||
static __one __test(int);
|
||||
static __one __test(unsigned int);
|
||||
static __one __test(long);
|
||||
static __one __test(unsigned long);
|
||||
static __one __test(long long);
|
||||
static __one __test(unsigned long long);
|
||||
static __two __test(...);
|
||||
|
||||
template<typename _Up>
|
||||
struct __convert
|
||||
{ operator _Up() const; };
|
||||
|
||||
public:
|
||||
static const bool __value = sizeof(__test(__convert<_Tp>())) == 1;
|
||||
};
|
||||
|
||||
template<typename _Tp>
|
||||
struct __is_enum_helper<_Tp, true>
|
||||
{ static const bool __value = false; };
|
||||
|
||||
template<typename _Tp>
|
||||
struct is_enum
|
||||
: integral_constant<bool, __is_enum_helper<_Tp>::__value> { };
|
||||
|
||||
template<typename _Tp, bool = (is_reference<_Tp>::value
|
||||
|| is_void<_Tp>::value)>
|
||||
struct __is_function_helper
|
||||
: public __sfinae_types
|
||||
{
|
||||
private:
|
||||
template<typename>
|
||||
static __one __test(...);
|
||||
|
||||
template<typename _Up>
|
||||
static __two __test(_Up(*)[1]);
|
||||
|
||||
@ -164,12 +207,13 @@ namespace tr1
|
||||
static const bool __value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
|
||||
template<typename _Tp>
|
||||
struct __is_function_helper<_Tp, true>
|
||||
{ static const bool __value = false; };
|
||||
|
||||
template<typename _Tp>
|
||||
struct is_function
|
||||
: public integral_constant<bool, (__is_function_helper<_Tp>::__value
|
||||
&& !is_reference<_Tp>::value
|
||||
&& !is_void<_Tp>::value)>
|
||||
{ };
|
||||
: public integral_constant<bool, __is_function_helper<_Tp>::__value> { };
|
||||
|
||||
/// @brief composite type traits [4.5.2].
|
||||
template<typename _Tp>
|
||||
|
@ -78,6 +78,12 @@ namespace __gnu_test
|
||||
typedef const ClassType cClassType;
|
||||
typedef volatile ClassType vClassType;
|
||||
typedef const volatile ClassType cvClassType;
|
||||
|
||||
enum EnumType { };
|
||||
|
||||
struct ConvType
|
||||
{ operator int() const; };
|
||||
|
||||
}; // namespace __gnu_test
|
||||
|
||||
#endif // _GLIBCXX_TESTSUITE_TR1_H
|
||||
|
@ -0,0 +1,50 @@
|
||||
// 2004-12-25 Paolo Carlini <pcarlini@suse.de>
|
||||
//
|
||||
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// 4.5.2 Composite type traits
|
||||
|
||||
#include <tr1/type_traits>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_scalar;
|
||||
using namespace __gnu_test;
|
||||
|
||||
VERIFY( (test_category<is_scalar, int>(true)) );
|
||||
VERIFY( (test_category<is_scalar, float>(true)) );
|
||||
VERIFY( (test_category<is_scalar, EnumType>(true)) );
|
||||
VERIFY( (test_category<is_scalar, int*>(true)) );
|
||||
VERIFY( (test_category<is_scalar, int(*)(int)>(true)) );
|
||||
VERIFY( (test_category<is_scalar, int (ClassType::*)>(true)) );
|
||||
// Temporarily disabled because of c++/19076 :-(
|
||||
// VERIFY( (test_category<is_scalar, int (ClassType::*) (int)>(true)) );
|
||||
|
||||
// Sanity check.
|
||||
VERIFY( (test_category<is_scalar, ClassType>(false)) );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
// 2004-12-25 Paolo Carlini <pcarlini@suse.de>
|
||||
//
|
||||
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
//
|
||||
// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES.
|
||||
|
||||
#include <tr1/type_traits>
|
||||
|
||||
// { dg-do compile }
|
||||
|
||||
void test01()
|
||||
{
|
||||
// Check for required typedefs
|
||||
typedef std::tr1::is_scalar<int> test_type;
|
||||
typedef test_type::value_type value_type;
|
||||
typedef test_type::type type;
|
||||
typedef test_type::type::value_type type_value_type;
|
||||
typedef test_type::type::type type_type;
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
// 2004-12-25 Paolo Carlini <pcarlini@suse.de>
|
||||
//
|
||||
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// 4.5.1 Primary type categories
|
||||
|
||||
#include <tr1/type_traits>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_enum;
|
||||
using namespace __gnu_test;
|
||||
|
||||
// Positive tests.
|
||||
VERIFY( (test_category<is_enum, EnumType>(true)) );
|
||||
|
||||
// Negative tests.
|
||||
VERIFY( (test_category<is_enum, void>(false)) );
|
||||
VERIFY( (test_category<is_enum, int>(false)) );
|
||||
VERIFY( (test_category<is_enum, float>(false)) );
|
||||
VERIFY( (test_category<is_enum, int[2]>(false)) );
|
||||
VERIFY( (test_category<is_enum, int*>(false)) );
|
||||
VERIFY( (test_category<is_enum, int(*)(int)>(false)) );
|
||||
VERIFY( (test_category<is_enum, float&>(false)) );
|
||||
VERIFY( (test_category<is_enum, float(&)(float)>(false)) );
|
||||
VERIFY( (test_category<is_enum, int (ClassType::*)>(false)) );
|
||||
// Temporarily disabled because of c++/19076 :-(
|
||||
// VERIFY( (test_category<is_enum, int (ClassType::*) (int)>(false)) );
|
||||
VERIFY( (test_category<is_enum, int (int)>(false)) );
|
||||
|
||||
VERIFY( (test_category<is_enum, ConvType>(false)) );
|
||||
|
||||
// Sanity check.
|
||||
VERIFY( (test_category<is_enum, ClassType>(false)) );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
// 2004-12-25 Paolo Carlini <pcarlini@suse.de>
|
||||
//
|
||||
// Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
//
|
||||
// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES.
|
||||
|
||||
#include <tr1/type_traits>
|
||||
|
||||
// { dg-do compile }
|
||||
|
||||
void test01()
|
||||
{
|
||||
// Check for required typedefs
|
||||
typedef std::tr1::is_enum<int> test_type;
|
||||
typedef test_type::value_type value_type;
|
||||
typedef test_type::type type;
|
||||
typedef test_type::type::value_type type_value_type;
|
||||
typedef test_type::type::type type_type;
|
||||
}
|
Loading…
Reference in New Issue
Block a user