From 186e6683b09474fa421314f683f7385585ec0d58 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 24 Dec 2004 20:33:56 +0000 Subject: [PATCH] type_traits: Implement is_member_object_pointer, is_member_function_pointer. 2004-12-24 Paolo Carlini * include/tr1/type_traits: Implement is_member_object_pointer, is_member_function_pointer. N.B. Due to c++/19076, the latter doesn't really work at the moment (a rather ugly work around will be provided in case the front-end bug doesn't get fixed soon); generalize and extend the _DEFINE_SPEC macros. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_member_pointer/is_member_pointer.cc: New. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_member_pointer/typedefs.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_member_function_pointer/is_member_function_pointer.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_member_function_pointer/typedefs.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_member_object_pointer/is_member_object_pointer.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_member_object_pointer/typedefs.cc: Likewise. From-SVN: r92593 --- libstdc++-v3/ChangeLog | 20 ++++ libstdc++-v3/include/tr1/type_traits | 99 ++++++++++++------- .../is_member_pointer/is_member_pointer.cc | 56 +++++++++++ .../is_member_pointer/typedefs.cc | 36 +++++++ .../is_member_function_pointer.cc | 62 ++++++++++++ .../is_member_function_pointer/typedefs.cc | 36 +++++++ .../is_member_object_pointer.cc | 59 +++++++++++ .../is_member_object_pointer/typedefs.cc | 36 +++++++ 8 files changed, 370 insertions(+), 34 deletions(-) create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_member_pointer/is_member_pointer.cc create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_member_pointer/typedefs.cc create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_function_pointer/is_member_function_pointer.cc create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_function_pointer/typedefs.cc create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_object_pointer/is_member_object_pointer.cc create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_object_pointer/typedefs.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f7fcd3dddecc..167faa82cc86 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2004-12-24 Paolo Carlini + + * include/tr1/type_traits: Implement is_member_object_pointer, + is_member_function_pointer. N.B. Due to c++/19076, the latter + doesn't really work at the moment (a rather ugly work around + will be provided in case the front-end bug doesn't get fixed + soon); generalize and extend the _DEFINE_SPEC macros. + * testsuite/tr1/4_metaprogramming/composite_type_traits/ + is_member_pointer/is_member_pointer.cc: New. + * testsuite/tr1/4_metaprogramming/composite_type_traits/ + is_member_pointer/typedefs.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_member_function_pointer/is_member_function_pointer.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_member_function_pointer/typedefs.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_member_object_pointer/is_member_object_pointer.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_member_object_pointer/typedefs.cc: Likewise. + 2004-12-22 Paolo Carlini * include/tr1/type_traits_fwd.h: New, forward declarations. diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 3381ccb57ecf..4da6b3ca1786 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -40,16 +40,26 @@ namespace tr1 typedef struct { char __arr[2]; } __two; }; -#define _DEFINE_SPEC_HELPER(_Header, _Spec) \ - template _Header \ - struct _Spec \ +#define _DEFINE_SPEC_0_HELPER(_Spec) \ + template<> \ + struct _Spec \ : public true_type { }; + +#define _DEFINE_SPEC_1_HELPER(_Spec) \ + template \ + struct _Spec \ + _DEFINE_SPEC_1_VAR -#define _DEFINE_SPEC(_Header, _Trait, _Type) \ - _DEFINE_SPEC_HELPER(_Header, _Trait<_Type>) \ - _DEFINE_SPEC_HELPER(_Header, _Trait<_Type const>) \ - _DEFINE_SPEC_HELPER(_Header, _Trait<_Type volatile>) \ - _DEFINE_SPEC_HELPER(_Header, _Trait<_Type const volatile>) +#define _DEFINE_SPEC_2_HELPER(_Spec) \ + template \ + struct _Spec \ + _DEFINE_SPEC_2_VAR + +#define _DEFINE_SPEC(_Order, _Trait, _Type) \ + _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type>) \ + _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const>) \ + _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type volatile>) \ + _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const volatile>) /// @brief helper classes [4.3]. template @@ -66,33 +76,33 @@ namespace tr1 template struct is_void : public false_type { }; - _DEFINE_SPEC(<>, is_void, void) + _DEFINE_SPEC(0, is_void, void) template struct is_integral : public false_type { }; - _DEFINE_SPEC(<>, is_integral, bool) - _DEFINE_SPEC(<>, is_integral, char) - _DEFINE_SPEC(<>, is_integral, signed char) - _DEFINE_SPEC(<>, is_integral, unsigned char) + _DEFINE_SPEC(0, is_integral, bool) + _DEFINE_SPEC(0, is_integral, char) + _DEFINE_SPEC(0, is_integral, signed char) + _DEFINE_SPEC(0, is_integral, unsigned char) #ifdef _GLIBCXX_USE_WCHAR_T - _DEFINE_SPEC(<>, is_integral, wchar_t) + _DEFINE_SPEC(0, is_integral, wchar_t) #endif - _DEFINE_SPEC(<>, is_integral, short) - _DEFINE_SPEC(<>, is_integral, unsigned short) - _DEFINE_SPEC(<>, is_integral, int) - _DEFINE_SPEC(<>, is_integral, unsigned int) - _DEFINE_SPEC(<>, is_integral, long) - _DEFINE_SPEC(<>, is_integral, unsigned long) - _DEFINE_SPEC(<>, is_integral, long long) - _DEFINE_SPEC(<>, is_integral, unsigned long long) + _DEFINE_SPEC(0, is_integral, short) + _DEFINE_SPEC(0, is_integral, unsigned short) + _DEFINE_SPEC(0, is_integral, int) + _DEFINE_SPEC(0, is_integral, unsigned int) + _DEFINE_SPEC(0, is_integral, long) + _DEFINE_SPEC(0, is_integral, unsigned long) + _DEFINE_SPEC(0, is_integral, long long) + _DEFINE_SPEC(0, is_integral, unsigned long long) template struct is_floating_point : public false_type { }; - _DEFINE_SPEC(<>, is_floating_point, float) - _DEFINE_SPEC(<>, is_floating_point, double) - _DEFINE_SPEC(<>, is_floating_point, long double) + _DEFINE_SPEC(0, is_floating_point, float) + _DEFINE_SPEC(0, is_floating_point, double) + _DEFINE_SPEC(0, is_floating_point, long double) template struct is_array @@ -105,11 +115,14 @@ namespace tr1 template struct is_array<_Tp[]> : public true_type { }; + +#define _DEFINE_SPEC_1_VAR \ + : public true_type { }; template struct is_pointer : public false_type { }; - _DEFINE_SPEC(, is_pointer, _Tp*) + _DEFINE_SPEC(1, is_pointer, _Tp*) template struct is_reference @@ -118,7 +131,24 @@ namespace tr1 template struct is_reference<_Tp&> : public true_type { }; - + +#define _DEFINE_SPEC_2_VAR \ + : public integral_constant::value> { }; + + template + struct is_member_object_pointer + : public false_type { }; + _DEFINE_SPEC(2, is_member_object_pointer, _Tp _Cp::*) + +#undef _DEFINE_SPEC_2_VAR +#define _DEFINE_SPEC_2_VAR \ + : public integral_constant::value> { }; + + template + struct is_member_function_pointer + : public false_type { }; + _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*) + template struct __is_function_helper : public __sfinae_types @@ -322,16 +352,14 @@ namespace tr1 { typedef typename remove_all_extents<_Tp>::type type; }; /// @brief pointer modifications [4.7.4]. -#undef _DEFINE_SPEC_HELPER -#define _DEFINE_SPEC_HELPER(_Header, _Spec) \ - template _Header \ - struct _Spec \ +#undef _DEFINE_SPEC_1_VAR +#define _DEFINE_SPEC_1_VAR \ { typedef _Tp type; }; template struct remove_pointer { typedef _Tp type; }; - _DEFINE_SPEC(, remove_pointer, _Tp*) + _DEFINE_SPEC(1, remove_pointer, _Tp*) template struct add_pointer @@ -339,8 +367,11 @@ namespace tr1 /// @brief other transformations [4.8]. -#undef _DEFINE_SPEC_HELPER -#undef _DEFINE_SPEC +#undef _DEFINE_SPEC_0_HELPER +#undef _DEFINE_SPEC_1_HELPER +#undef _DEFINE_SPEC_2_HELPER +#undef _DEFINE_SPEC_1_VAR +#undef _DEFINE_SPEC_2_VAR } } diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_member_pointer/is_member_pointer.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_member_pointer/is_member_pointer.cc new file mode 100644 index 000000000000..918417e4ed2f --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_member_pointer/is_member_pointer.cc @@ -0,0 +1,56 @@ +// 2004-12-24 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_member_pointer; + using namespace __gnu_test; + + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + + // Temporarily disabled because of c++/19076 :-( + + //VERIFY( (test_category(true)) ); + //VERIFY( (test_category(true)) ); + //VERIFY( (test_category(true)) ); + //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_member_pointer/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_member_pointer/typedefs.cc new file mode 100644 index 000000000000..90cb87433a28 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_member_pointer/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-24 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_member_pointer 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_member_function_pointer/is_member_function_pointer.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_function_pointer/is_member_function_pointer.cc new file mode 100644 index 000000000000..9652e1943e7a --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_function_pointer/is_member_function_pointer.cc @@ -0,0 +1,62 @@ +// 2004-12-24 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_member_function_pointer; + using namespace __gnu_test; + + // Positive tests. + + // Temporarily disabled because of c++/19076 :-( + + //VERIFY( (test_category(true)) ); + //VERIFY( (test_category(true)) ); + //VERIFY( (test_category(true)) ); + //VERIFY( (test_category(true)) ); + + // Negative tests. + 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_member_function_pointer/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_function_pointer/typedefs.cc new file mode 100644 index 000000000000..89112e3608f8 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_function_pointer/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-24 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_member_function_pointer 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_member_object_pointer/is_member_object_pointer.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_object_pointer/is_member_object_pointer.cc new file mode 100644 index 000000000000..986eee1173ca --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_object_pointer/is_member_object_pointer.cc @@ -0,0 +1,59 @@ +// 2004-12-24 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_member_object_pointer; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + + // Negative tests. + VERIFY( (test_category(false)) ); + 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_member_object_pointer/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_object_pointer/typedefs.cc new file mode 100644 index 000000000000..414c2ea16242 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_member_object_pointer/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-24 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_member_object_pointer 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; +}