diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4de8634dc42..b79cee21fd0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,21 @@ +2004-12-12 Paolo Carlini + + * include/tr1/type_traits: Implement is_pointer, remove_pointer, + and add_pointer; reformat. + (_DEFINE_PRIMARY_SPEC_HELPER, _DEFINE_PRIMARY_SPEC): Generalize + and rename to _DEFINE_SPEC_HELPER and _DEFINE_SPEC; update uses. + * testsuite/tr1/4_metaprogramming/pointer_modifications/ + add_pointer.cc: New. + * testsuite/tr1/4_metaprogramming/pointer_modifications/ + remove_pointer.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_pointer/is_pointer.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_pointer/typedefs.cc: Likewise. + + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_reference/is_reference.cc: Slightly tweak consistently. + 2004-12-11 Paolo Carlini * include/tr1/type_traits: Implement rank. diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 5e16637e46d..6fef185b5b3 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -43,49 +43,49 @@ namespace tr1 }; typedef integral_constant true_type; typedef integral_constant false_type; - -#define _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type) \ - template<> \ - struct _Primary<_Type> \ - : public true_type { }; -#define _DEFINE_PRIMARY_SPEC(_Primary, _Type) \ - _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type) \ - _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type const) \ - _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type volatile) \ - _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type const volatile) - +#define _DEFINE_SPEC_HELPER(_Header, _Spec) \ + template _Header \ + struct _Spec \ + : public true_type { }; + +#define _DEFINE_SPEC(_Header, _Primary, _Type) \ + _DEFINE_SPEC_HELPER(_Header, _Primary<_Type>) \ + _DEFINE_SPEC_HELPER(_Header, _Primary<_Type const>) \ + _DEFINE_SPEC_HELPER(_Header, _Primary<_Type volatile>) \ + _DEFINE_SPEC_HELPER(_Header, _Primary<_Type const volatile>) + /// @brief primary type categories [4.5.1]. template struct is_void : public false_type { }; - _DEFINE_PRIMARY_SPEC(is_void, void) + _DEFINE_SPEC(<>, is_void, void) template struct is_integral : public false_type { }; - _DEFINE_PRIMARY_SPEC(is_integral, bool) - _DEFINE_PRIMARY_SPEC(is_integral, char) - _DEFINE_PRIMARY_SPEC(is_integral, signed char) - _DEFINE_PRIMARY_SPEC(is_integral, unsigned char) + _DEFINE_SPEC(<>, is_integral, bool) + _DEFINE_SPEC(<>, is_integral, char) + _DEFINE_SPEC(<>, is_integral, signed char) + _DEFINE_SPEC(<>, is_integral, unsigned char) #ifdef _GLIBCXX_USE_WCHAR_T - _DEFINE_PRIMARY_SPEC(is_integral, wchar_t) + _DEFINE_SPEC(<>, is_integral, wchar_t) #endif - _DEFINE_PRIMARY_SPEC(is_integral, short) - _DEFINE_PRIMARY_SPEC(is_integral, unsigned short) - _DEFINE_PRIMARY_SPEC(is_integral, int) - _DEFINE_PRIMARY_SPEC(is_integral, unsigned int) - _DEFINE_PRIMARY_SPEC(is_integral, long) - _DEFINE_PRIMARY_SPEC(is_integral, unsigned long) - _DEFINE_PRIMARY_SPEC(is_integral, long long) - _DEFINE_PRIMARY_SPEC(is_integral, unsigned long long) + _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) template struct is_floating_point : public false_type { }; - _DEFINE_PRIMARY_SPEC(is_floating_point, float) - _DEFINE_PRIMARY_SPEC(is_floating_point, double) - _DEFINE_PRIMARY_SPEC(is_floating_point, long double) + _DEFINE_SPEC(<>, is_floating_point, float) + _DEFINE_SPEC(<>, is_floating_point, double) + _DEFINE_SPEC(<>, is_floating_point, long double) template struct is_array @@ -99,9 +99,11 @@ namespace tr1 struct is_array<_Tp[]> : public true_type { }; - template - struct is_pointer; - + template + struct is_pointer + : public false_type { }; + _DEFINE_SPEC(, is_pointer, _Tp*) + template struct is_reference : public false_type { }; @@ -128,9 +130,6 @@ namespace tr1 template struct is_function; -#undef _DEFINE_PRIMARY_SPEC_HELPER -#undef _DEFINE_PRIMARY_SPEC - /// @brief composite type traits [4.5.2]. template struct is_arithmetic @@ -266,27 +265,19 @@ namespace tr1 /// @brief const-volatile modifications [4.7.1]. template struct remove_const - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct remove_const<_Tp const> - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct remove_volatile - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct remove_volatile<_Tp volatile> - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct remove_cv @@ -307,75 +298,68 @@ namespace tr1 /// @brief reference modifications [4.7.2]. template struct remove_reference - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct remove_reference<_Tp&> - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct add_reference - { - typedef _Tp& type; - }; + { typedef _Tp& type; }; template struct add_reference<_Tp&> - { - typedef _Tp& type; - }; + { typedef _Tp& type; }; /// @brief array modififications [4.7.3]. template struct remove_extent - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct remove_extent<_Tp[_Size]> - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct remove_extent<_Tp[]> - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct remove_all_extents - { - typedef _Tp type; - }; + { typedef _Tp type; }; template struct remove_all_extents<_Tp[_Size]> - { - typedef typename remove_all_extents<_Tp>::type type; - }; + { typedef typename remove_all_extents<_Tp>::type type; }; template struct remove_all_extents<_Tp[]> - { - typedef typename remove_all_extents<_Tp>::type type; - }; + { 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 \ + { typedef _Tp type; }; + template - struct remove_pointer; + struct remove_pointer + { typedef _Tp type; }; + _DEFINE_SPEC(, remove_pointer, _Tp*) template - struct add_pointer; + struct add_pointer + { typedef typename remove_reference<_Tp>::type* type; }; /// @brief other transformations [4.8]. template struct aligned_storage; + +#undef _DEFINE_SPEC_HELPER +#undef _DEFINE_SPEC + } } diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/add_pointer.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/add_pointer.cc new file mode 100644 index 00000000000..71d1719de99 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/add_pointer.cc @@ -0,0 +1,46 @@ +// 2004-12-12 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.7.2 Reference modifications + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::add_pointer; + using std::tr1::is_same; + using namespace __gnu_test; + + VERIFY( (is_same::type, int*>::value) ); + VERIFY( (is_same::type, int**>::value) ); + VERIFY( (is_same::type, const int*>::value) ); + VERIFY( (is_same::type, int*>::value) ); + VERIFY( (is_same::type, ClassType**>::value) ); + VERIFY( (is_same::type, ClassType*>::value) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/remove_pointer.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/remove_pointer.cc new file mode 100644 index 00000000000..b3ba25bd324 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/remove_pointer.cc @@ -0,0 +1,46 @@ +// 2004-12-12 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.7.2 Reference modifications + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::remove_pointer; + using std::tr1::is_same; + using namespace __gnu_test; + + VERIFY( (is_same::type, int>::value) ); + VERIFY( (is_same::type, int>::value) ); + VERIFY( (is_same::type, const int>::value) ); + VERIFY( (is_same::type, int*>::value) ); + VERIFY( (is_same::type, ClassType>::value) ); + VERIFY( (is_same::type, ClassType>::value) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/is_pointer.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/is_pointer.cc new file mode 100644 index 00000000000..fd9a33a6cac --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/is_pointer.cc @@ -0,0 +1,45 @@ +// 2004-12-12 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_pointer; + using namespace __gnu_test; + + 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/primary_type_categories/is_pointer/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/typedefs.cc new file mode 100644 index 00000000000..69141b27c19 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-12 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_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_reference/is_reference.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc index 7409368c9b6..d3c6b95e66b 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc @@ -30,13 +30,9 @@ void test01() using std::tr1::is_reference; using namespace __gnu_test; - typedef int& int_ref; - typedef ClassType& ClassType_ref; - typedef int (&fun_ref) (int); - - VERIFY( (test_category(true)) ); - VERIFY( (test_category(true)) ); - VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); // Sanity check. VERIFY( (test_category(false)) );