diff options
author | Paolo Carlini <pcarlini@suse.de> | 2004-12-07 16:40:46 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2004-12-07 16:40:46 +0000 |
commit | 0f910b4f4f6978a033e5354fcc81fe9e79792d89 (patch) | |
tree | e9347f539406cb38a3947eeb6ee67777d01dc793 | |
parent | 5423d7ebe17465199c4c9c35167c8042dd47b911 (diff) | |
download | gcc-0f910b4f4f6978a033e5354fcc81fe9e79792d89.zip gcc-0f910b4f4f6978a033e5354fcc81fe9e79792d89.tar.gz gcc-0f910b4f4f6978a033e5354fcc81fe9e79792d89.tar.bz2 |
type_traits: Implement is_const and is_volatile.
2004-12-07 Paolo Carlini <pcarlini@suse.de>
* 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.
From-SVN: r91808
14 files changed, 236 insertions, 23 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f7867cb..732bb4e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,31 @@ +2004-12-07 Paolo Carlini <pcarlini@suse.de> + + * 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 <pcarlini@suse.de> * include/tr1/type_traits: Implement is_reference. diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 44d8a4e..928e2aa 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -171,11 +171,21 @@ namespace tr1 : public integral_constant<bool, !is_fundamental<_Tp>::value> { }; /// @brief type properties [4.5.3]. + template<typename> + struct is_const + : public false_type { }; + template<typename _Tp> - struct is_const; + struct is_const<_Tp const> + : public true_type { }; + template<typename> + struct is_volatile + : public false_type { }; + template<typename _Tp> - struct is_volatile; + struct is_volatile<_Tp volatile> + : public true_type { }; template<typename _Tp> struct is_pod; diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h index 7069568..18563f4 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 const volatile>::type::value == Tv; return ret; } + + template<template<typename> class Property, + typename Type, bool Tv> + bool + test_property() + { + bool ret = true; + ret &= Property<Type>::value == Tv; + ret &= Property<Type>::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 f27ad75..a507d86 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 <testsuite_hooks.h> #include <testsuite_tr1.h> -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<is_arithmetic, void, false>()) ); 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 2858de4..9106ee5 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 <testsuite_hooks.h> #include <testsuite_tr1.h> -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<is_fundamental, void, true>()) ); VERIFY( (test_category<is_fundamental, char, true>()) ); 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 66b1894..6977720 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 <testsuite_hooks.h> #include <testsuite_tr1.h> -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 deed15d..c24de1a 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 <testsuite_hooks.h> #include <testsuite_tr1.h> -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<is_floating_point, void, false>()) ); VERIFY( (test_category<is_floating_point, char, false>()) ); 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 d746edb..812ff08 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 <testsuite_hooks.h> #include <testsuite_tr1.h> -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<is_integral, void, false>()) ); 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 2442edb3..cd59f4d 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 <testsuite_hooks.h> #include <testsuite_tr1.h> -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 46b8629..e65208c 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 <testsuite_hooks.h> #include <testsuite_tr1.h> -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<is_void, void, true>()) ); 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 0000000..5202161 --- /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 <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.3 Type properties + +#include <tr1/type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_const; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_property<is_const, int const, true>()) ); + VERIFY( (test_property<is_const, int const volatile, true>()) ); + VERIFY( (test_property<is_const, cClassType, true>()) ); + VERIFY( (test_property<is_const, cvClassType, true>()) ); + + // Negative tests. + VERIFY( (test_property<is_const, int, false>()) ); + VERIFY( (test_property<is_const, int volatile, false>()) ); + VERIFY( (test_property<is_const, ClassType, false>()) ); + VERIFY( (test_property<is_const, vClassType, false>()) ); +} + +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 0000000..9910698 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-07 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_const<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/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 0000000..4dc791f --- /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 <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.3 Type properties + +#include <tr1/type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_volatile; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_property<is_volatile, int volatile, true>()) ); + VERIFY( (test_property<is_volatile, int const volatile, true>()) ); + VERIFY( (test_property<is_volatile, vClassType, true>()) ); + VERIFY( (test_property<is_volatile, cvClassType, true>()) ); + + // Negative tests. + VERIFY( (test_property<is_volatile, int, false>()) ); + VERIFY( (test_property<is_volatile, int const, false>()) ); + VERIFY( (test_property<is_volatile, ClassType, false>()) ); + VERIFY( (test_property<is_volatile, cClassType, false>()) ); +} + +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 0000000..5104163 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/typedefs.cc @@ -0,0 +1,36 @@ +// 2004-12-07 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_volatile<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; +} |