From: Paolo Carlini Date: Sat, 25 Dec 2004 15:24:36 +0000 (+0000) Subject: type_traits: Implement is_enum (usual caveats about the nasty consequences of c+... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a9e7ba81398e8157a97d2d626509dd53ee7eed26;p=gcc.git type_traits: Implement is_enum (usual caveats about the nasty consequences of c++/19076...). 2004-12-25 Paolo Carlini * 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6e817284d36..b644e008c2f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,17 @@ +2004-12-25 Paolo Carlini + + * 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 * include/tr1/type_traits: Add missing undef. diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 42f9bac6af4..9816adafa52 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -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::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 + struct __convert + { operator _Up() const; }; + + public: + static const bool __value = sizeof(__test(__convert<_Tp>())) == 1; + }; + template + struct __is_enum_helper<_Tp, true> + { static const bool __value = false; }; + + template + struct is_enum + : integral_constant::__value> { }; + + template::value + || is_void<_Tp>::value)> struct __is_function_helper : public __sfinae_types { private: template static __one __test(...); - template static __two __test(_Up(*)[1]); @@ -164,12 +207,13 @@ namespace tr1 static const bool __value = sizeof(__test<_Tp>(0)) == 1; }; + template + struct __is_function_helper<_Tp, true> + { static const bool __value = false; }; + template struct is_function - : public integral_constant::__value - && !is_reference<_Tp>::value - && !is_void<_Tp>::value)> - { }; + : public integral_constant::__value> { }; /// @brief composite type traits [4.5.2]. template diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h index c9d8d235781..0ad8ac14313 100644 --- a/libstdc++-v3/testsuite/testsuite_tr1.h +++ b/libstdc++-v3/testsuite/testsuite_tr1.h @@ -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 diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/is_scalar.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/is_scalar.cc new file mode 100644 index 00000000000..37d6592f04f --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/is_scalar.cc @@ -0,0 +1,50 @@ +// 2004-12-25 Paolo Carlini +// +// 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 +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_scalar; + using namespace __gnu_test; + + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + // Temporarily disabled because of c++/19076 :-( + // VERIFY( (test_category(true)) ); + + // Sanity check. + VERIFY( (test_category(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/typedefs.cc new file mode 100644 index 00000000000..5a1740fc8ee --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-25 Paolo Carlini +// +// 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 + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::tr1::is_scalar 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; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/is_enum.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/is_enum.cc new file mode 100644 index 00000000000..3de48c4084f --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/is_enum.cc @@ -0,0 +1,60 @@ +// 2004-12-25 Paolo Carlini +// +// 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 +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_enum; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_category(true)) ); + + // Negative tests. + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + // Temporarily disabled because of c++/19076 :-( + // VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + + VERIFY( (test_category(false)) ); + + // Sanity check. + VERIFY( (test_category(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/typedefs.cc new file mode 100644 index 00000000000..eeb10936c58 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-25 Paolo Carlini +// +// 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 + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::tr1::is_enum 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; +}