diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 10d7832bc89d..2c285e58aa65 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,22 @@ +2004-12-08 Paolo Carlini + + * include/tr1/type_traits: Implement is_same, add_reference and + remove_reference. + * testsuite/testsuite_tr1.h (test_relationship): New. + * testsuite/tr1/4_metaprogramming/reference_modifications/ + add_reference.cc: New. + * testsuite/tr1/4_metaprogramming/reference_modifications/ + remove_reference.cc: Likewise. + * testsuite/tr1/4_metaprogramming/relationships_between_types/ + is_same/is_same.cc: Likewise. + * testsuite/tr1/4_metaprogramming/relationships_between_types/ + is_same/typedefs.cc: Likewise. + + * testsuite/tr1/4_metaprogramming/type_properties/is_const/ + is_const.cc: Minor tweaks. + * testsuite/tr1/4_metaprogramming/type_properties/is_volatile/ + is_volatile.cc: Likewise. + 2004-12-08 David Edelsohn * Makefile.am (AM_MAKEFLAGS): Remove duplicate LIBCFLAGS and diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 928e2aa36e5d..742536cb76a5 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -240,8 +240,13 @@ namespace tr1 struct extent; /// @brief relationships between types [4.6]. - template - struct is_same; + template + struct is_same + : public false_type { }; + + template + struct is_same<_Tp, _Tp> + : public true_type { }; template struct is_convertible; @@ -270,10 +275,28 @@ namespace tr1 /// @brief reference modifications [4.7.2]. template - struct remove_reference; + struct remove_reference + { + typedef _Tp type; + }; + + template + struct remove_reference<_Tp&> + { + typedef _Tp type; + }; template - struct add_reference; + struct add_reference + { + typedef _Tp& type; + }; + + template + struct add_reference<_Tp&> + { + typedef _Tp& type; + }; /// @brief array modififications [4.7.3]. template diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h index 18563f48e4cc..b3d4cf94f17c 100644 --- a/libstdc++-v3/testsuite/testsuite_tr1.h +++ b/libstdc++-v3/testsuite/testsuite_tr1.h @@ -41,13 +41,13 @@ namespace __gnu_test { bool ret = true; ret &= Category::value == Tv; - ret &= Category::value == Tv; - ret &= Category::value == Tv; - ret &= Category::value == Tv; + ret &= Category::value == Tv; + ret &= Category::value == Tv; + ret &= Category::value == Tv; ret &= Category::type::value == Tv; - ret &= Category::type::value == Tv; - ret &= Category::type::value == Tv; - ret &= Category::type::value == Tv; + ret &= Category::type::value == Tv; + ret &= Category::type::value == Tv; + ret &= Category::type::value == Tv; return ret; } @@ -62,11 +62,22 @@ namespace __gnu_test return ret; } + template class Relationship, + typename Type1, typename Type2, bool Tv> + bool + test_relationship() + { + bool ret = true; + ret &= Relationship::value == Tv; + ret &= Relationship::type::value == Tv; + return ret; + } + // Test types. class ClassType { }; - typedef ClassType const cClassType; - typedef ClassType volatile vClassType; - typedef ClassType const volatile cvClassType; + typedef const ClassType cClassType; + typedef volatile ClassType vClassType; + typedef const volatile ClassType cvClassType; }; // namespace __gnu_test #endif // _GLIBCXX_TESTSUITE_TR1_H diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc new file mode 100644 index 000000000000..7674689433a6 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc @@ -0,0 +1,46 @@ +// 2004-12-08 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_reference; + 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/reference_modifications/remove_reference.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/remove_reference.cc new file mode 100644 index 000000000000..f21d1a07cfc3 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/remove_reference.cc @@ -0,0 +1,46 @@ +// 2004-12-08 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_reference; + 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/relationships_between_types/is_same/is_same.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/is_same.cc new file mode 100644 index 000000000000..32d65af4a6db --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/is_same.cc @@ -0,0 +1,50 @@ +// 2004-12-08 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.6 Relationships between types + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_same; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_relationship()) ); + VERIFY( (test_relationship()) ); + VERIFY( (test_relationship()) ); + VERIFY( (test_relationship()) ); + + // Negative tests. + VERIFY( (test_relationship()) ); + VERIFY( (test_relationship()) ); + VERIFY( (test_relationship()) ); + VERIFY( (test_relationship()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc new file mode 100644 index 000000000000..39c47e242860 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-08 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_same 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/type_properties/is_const/is_const.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc index 5202161a1323..82de4285aae4 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc @@ -31,14 +31,14 @@ void test01() using namespace __gnu_test; // Positive tests. - VERIFY( (test_property()) ); - VERIFY( (test_property()) ); + VERIFY( (test_property()) ); + VERIFY( (test_property()) ); VERIFY( (test_property()) ); VERIFY( (test_property()) ); // Negative tests. VERIFY( (test_property()) ); - VERIFY( (test_property()) ); + VERIFY( (test_property()) ); VERIFY( (test_property()) ); VERIFY( (test_property()) ); } diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc index 4dc791f9c0c3..c47ec786aeb2 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc @@ -31,14 +31,14 @@ void test01() using namespace __gnu_test; // Positive tests. - VERIFY( (test_property()) ); - VERIFY( (test_property()) ); + VERIFY( (test_property()) ); + VERIFY( (test_property()) ); VERIFY( (test_property()) ); VERIFY( (test_property()) ); // Negative tests. VERIFY( (test_property()) ); - VERIFY( (test_property()) ); + VERIFY( (test_property()) ); VERIFY( (test_property()) ); VERIFY( (test_property()) ); }