diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f7867cb8c12..732bb4e1990 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,31 @@ +2004-12-07 Paolo Carlini + + * include/tr1/type_traits: Implement is_const and is_volatile. + * testsuite/testsuite_tr1.h (test_property): New. + * testsuite/tr1/4_metaprogramming/type_properties/ + is_const/is_const.c: New. + * testsuite/tr1/4_metaprogramming/type_properties/ + is_const/typedefs.cc: Likewise. + * testsuite/tr1/4_metaprogramming/type_properties/ + is_volatile/is_volatile.cc: Likewise. + * testsuite/tr1/4_metaprogramming/type_properties/ + is_volatile/typedefs.cc: Likewise. + * testsuite/tr1/4_metaprogramming/composite_type_traits/ + is_arithmetic/is_arithmetic.cc: Slightly tweak to use ClassType + from testsuite_tr1.h. + * testsuite/tr1/4_metaprogramming/composite_type_traits/ + is_fundamental/is_fundamental.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_array/is_array.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_floating_point/is_floating_point.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_integral/is_integral.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_reference/is_reference.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_void/is_void.cc: Likewise. + 2004-12-06 Paolo Carlini * include/tr1/type_traits: Implement is_reference. diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 44d8a4e3583..928e2aa36e5 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -171,11 +171,21 @@ namespace tr1 : public integral_constant::value> { }; /// @brief type properties [4.5.3]. + template + struct is_const + : public false_type { }; + template - struct is_const; + struct is_const<_Tp const> + : public true_type { }; + template + struct is_volatile + : public false_type { }; + template - struct is_volatile; + struct is_volatile<_Tp volatile> + : public true_type { }; template struct is_pod; diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h index 70695684024..18563f48e4c 100644 --- a/libstdc++-v3/testsuite/testsuite_tr1.h +++ b/libstdc++-v3/testsuite/testsuite_tr1.h @@ -50,6 +50,23 @@ namespace __gnu_test ret &= Category::type::value == Tv; return ret; } + + template class Property, + typename Type, bool Tv> + bool + test_property() + { + bool ret = true; + ret &= Property::value == Tv; + ret &= Property::type::value == Tv; + return ret; + } + + // Test types. + class ClassType { }; + typedef ClassType const cClassType; + typedef ClassType volatile vClassType; + typedef ClassType const volatile cvClassType; }; // namespace __gnu_test #endif // _GLIBCXX_TESTSUITE_TR1_H diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_arithmetic/is_arithmetic.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_arithmetic/is_arithmetic.cc index f27ad75fe81..a507d860979 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_arithmetic/is_arithmetic.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_arithmetic/is_arithmetic.cc @@ -24,13 +24,11 @@ #include #include -class ClassType { }; - void test01() { bool test __attribute__((unused)) = true; using std::tr1::is_arithmetic; - using __gnu_test::test_category; + using namespace __gnu_test; VERIFY( (test_category()) ); diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_fundamental/is_fundamental.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_fundamental/is_fundamental.cc index 2858de469ac..9106ee504ff 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_fundamental/is_fundamental.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_fundamental/is_fundamental.cc @@ -24,13 +24,11 @@ #include #include -class ClassType { }; - void test01() { bool test __attribute__((unused)) = true; using std::tr1::is_fundamental; - using __gnu_test::test_category; + using namespace __gnu_test; VERIFY( (test_category()) ); VERIFY( (test_category()) ); diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc index 66b1894a353..69777209ba2 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc @@ -24,13 +24,11 @@ #include #include -class ClassType { }; - void test01() { bool test __attribute__((unused)) = true; using std::tr1::is_array; - using __gnu_test::test_category; + using namespace __gnu_test; typedef int int_array[5]; typedef int empty_int_array[]; diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_floating_point/is_floating_point.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_floating_point/is_floating_point.cc index deed15dbe6c..c24de1a5d5a 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_floating_point/is_floating_point.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_floating_point/is_floating_point.cc @@ -24,13 +24,11 @@ #include #include -class ClassType { }; - void test01() { bool test __attribute__((unused)) = true; using std::tr1::is_floating_point; - using __gnu_test::test_category; + using namespace __gnu_test; VERIFY( (test_category()) ); VERIFY( (test_category()) ); diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_integral/is_integral.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_integral/is_integral.cc index d746edb8992..812ff080b81 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_integral/is_integral.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_integral/is_integral.cc @@ -24,13 +24,11 @@ #include #include -class ClassType { }; - void test01() { bool test __attribute__((unused)) = true; using std::tr1::is_integral; - using __gnu_test::test_category; + using namespace __gnu_test; VERIFY( (test_category()) ); 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 2442edb3b05..cd59f4d6ac1 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 @@ -24,13 +24,11 @@ #include #include -class ClassType { }; - void test01() { bool test __attribute__((unused)) = true; using std::tr1::is_reference; - using __gnu_test::test_category; + using namespace __gnu_test; typedef int& int_ref; typedef ClassType& ClassType_ref; diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_void/is_void.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_void/is_void.cc index 46b8629ade9..e65208c821e 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_void/is_void.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_void/is_void.cc @@ -24,13 +24,11 @@ #include #include -class ClassType { }; - void test01() { bool test __attribute__((unused)) = true; using std::tr1::is_void; - using __gnu_test::test_category; + using namespace __gnu_test; VERIFY( (test_category()) ); 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 new file mode 100644 index 00000000000..5202161a132 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc @@ -0,0 +1,50 @@ +// 2004-12-07 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.3 Type properties + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_const; + using namespace __gnu_test; + + // Positive tests. + 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()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/typedefs.cc new file mode 100644 index 00000000000..9910698b0fa --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-07 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_const 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_volatile/is_volatile.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc new file mode 100644 index 00000000000..4dc791f9c0c --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc @@ -0,0 +1,50 @@ +// 2004-12-07 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.3 Type properties + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_volatile; + using namespace __gnu_test; + + // Positive tests. + 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()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/typedefs.cc new file mode 100644 index 00000000000..5104163955e --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-07 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_volatile 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; +}