diff options
author | Paolo Carlini <pcarlini@suse.de> | 2004-12-24 20:33:56 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2004-12-24 20:33:56 +0000 |
commit | 186e6683b09474fa421314f683f7385585ec0d58 (patch) | |
tree | d217ce89eec0b444475b125e962085a761a003cd /libstdc++-v3 | |
parent | fab072b528f505aa6f4fcc8372ef15902b633c04 (diff) | |
download | gcc-186e6683b09474fa421314f683f7385585ec0d58.tar.gz |
type_traits: Implement is_member_object_pointer, is_member_function_pointer.
2004-12-24 Paolo Carlini <pcarlini@suse.de>
* 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
Diffstat (limited to 'libstdc++-v3')
8 files changed, 370 insertions, 34 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f7fcd3dddec..167faa82cc8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2004-12-24 Paolo Carlini <pcarlini@suse.de> + + * 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 <pcarlini@suse.de> * 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 3381ccb57ec..4da6b3ca178 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<typename _Tp> \ + 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<typename _Tp, typename _Cp> \ + 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<typename _Tp, _Tp __v> @@ -66,33 +76,33 @@ namespace tr1 template<typename> struct is_void : public false_type { }; - _DEFINE_SPEC(<>, is_void, void) + _DEFINE_SPEC(0, is_void, void) template<typename> 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<typename> 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<typename> struct is_array @@ -105,11 +115,14 @@ namespace tr1 template<typename _Tp> struct is_array<_Tp[]> : public true_type { }; + +#define _DEFINE_SPEC_1_VAR \ + : public true_type { }; template<typename> struct is_pointer : public false_type { }; - _DEFINE_SPEC(<typename _Tp>, is_pointer, _Tp*) + _DEFINE_SPEC(1, is_pointer, _Tp*) template<typename> struct is_reference @@ -118,7 +131,24 @@ namespace tr1 template<typename _Tp> struct is_reference<_Tp&> : public true_type { }; - + +#define _DEFINE_SPEC_2_VAR \ + : public integral_constant<bool, !is_function<_Tp>::value> { }; + + template<typename> + 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<bool, is_function<_Tp>::value> { }; + + template<typename> + struct is_member_function_pointer + : public false_type { }; + _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*) + template<typename _Tp> 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<typename _Tp> struct remove_pointer { typedef _Tp type; }; - _DEFINE_SPEC(<typename _Tp>, remove_pointer, _Tp*) + _DEFINE_SPEC(1, remove_pointer, _Tp*) template<typename _Tp> 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 00000000000..918417e4ed2 --- /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 <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_member_pointer; + using namespace __gnu_test; + + VERIFY( (test_category<is_member_pointer, int (ClassType::*)>(true)) ); + VERIFY( (test_category<is_member_pointer, const int (ClassType::*)>(true)) ); + VERIFY( (test_category<is_member_pointer, ClassType (ClassType::*)>(true)) ); + + // Temporarily disabled because of c++/19076 :-( + + //VERIFY( (test_category<is_member_pointer, + // int (ClassType::*) (int)>(true)) ); + //VERIFY( (test_category<is_member_pointer, + // int (ClassType::*) (int) const>(true)) ); + //VERIFY( (test_category<is_member_function_pointer, + // ClassType (ClassType::*) (ClassType)>(true)) ); + //VERIFY( (test_category<is_member_pointer, + // float (ClassType::*) (int, float, int[], int&)>(true)) ); + + // Sanity check. + VERIFY( (test_category<is_member_pointer, ClassType>(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 00000000000..90cb87433a2 --- /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 <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_member_pointer<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; +} 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 00000000000..9652e1943e7 --- /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 <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_member_function_pointer; + using namespace __gnu_test; + + // Positive tests. + + // Temporarily disabled because of c++/19076 :-( + + //VERIFY( (test_category<is_member_function_pointer, + // int (ClassType::*) (int)>(true)) ); + //VERIFY( (test_category<is_member_function_pointer, + // int (ClassType::*) (int) const>(true)) ); + //VERIFY( (test_category<is_member_function_pointer, + // ClassType (ClassType::*) (ClassType)>(true)) ); + //VERIFY( (test_category<is_member_function_pointer, + // float (ClassType::*) (int, float, int[], int&)>(true)) ); + + // Negative tests. + VERIFY( (test_category<is_member_function_pointer, + int (ClassType::*)>(false)) ); + VERIFY( (test_category<is_member_function_pointer, + const int (ClassType::*)>(false)) ); + VERIFY( (test_category<is_member_function_pointer, + ClassType (ClassType::*)>(false)) ); + + // Sanity check. + VERIFY( (test_category<is_member_function_pointer, ClassType>(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 00000000000..89112e3608f --- /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 <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_member_function_pointer<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; +} 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 00000000000..986eee1173c --- /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 <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_member_object_pointer; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_category<is_member_object_pointer, + int (ClassType::*)>(true)) ); + VERIFY( (test_category<is_member_object_pointer, + const int (ClassType::*)>(true)) ); + VERIFY( (test_category<is_member_object_pointer, + ClassType (ClassType::*)>(true)) ); + + // Negative tests. + VERIFY( (test_category<is_member_object_pointer, + int (ClassType::*) (int)>(false)) ); + VERIFY( (test_category<is_member_object_pointer, + int (ClassType::*) (int) const>(false)) ); + VERIFY( (test_category<is_member_object_pointer, + ClassType (ClassType::*) (ClassType)>(false)) ); + VERIFY( (test_category<is_member_object_pointer, + float (ClassType::*) (int, float, int[], int&)>(false)) ); + + // Sanity check. + VERIFY( (test_category<is_member_object_pointer, ClassType>(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 00000000000..414c2ea1624 --- /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 <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_member_object_pointer<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; +} |