From d5f60056f02a4f2bb7201f05224de907c9c234c4 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 10 Dec 2004 11:45:13 +0000 Subject: [PATCH] type_traits: Implement remove_const, remove_volatile, and remove_cv. 2004-12-10 Paolo Carlini * include/tr1/type_traits: Implement remove_const, remove_volatile, and remove_cv. * testsuite/tr1/4_metaprogramming/const_volatile_modifications/ remove_const.cc: New. * testsuite/tr1/4_metaprogramming/const_volatile_modifications/ remove_cv.cc: Likewise. * testsuite/tr1/4_metaprogramming/const_volatile_modifications/ remove_volatile.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_array/is_array.cc: Slightly tweak consistently, remove typedefs, add a few tests. From-SVN: r91990 --- libstdc++-v3/ChangeLog | 15 ++++++ libstdc++-v3/include/tr1/type_traits | 28 +++++++++-- .../remove_const.cc | 47 ++++++++++++++++++ .../const_volatile_modifications/remove_cv.cc | 47 ++++++++++++++++++ .../remove_volatile.cc | 48 +++++++++++++++++++ .../is_array/is_array.cc | 25 +++++----- 6 files changed, 194 insertions(+), 16 deletions(-) create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_const.cc create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_cv.cc create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_volatile.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4e510e99834..f4ddc1c1e50 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,18 @@ +2004-12-10 Paolo Carlini + + * include/tr1/type_traits: Implement remove_const, remove_volatile, + and remove_cv. + * testsuite/tr1/4_metaprogramming/const_volatile_modifications/ + remove_const.cc: New. + * testsuite/tr1/4_metaprogramming/const_volatile_modifications/ + remove_cv.cc: Likewise. + * testsuite/tr1/4_metaprogramming/const_volatile_modifications/ + remove_volatile.cc: Likewise. + + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_array/is_array.cc: Slightly tweak consistently, remove typedefs, + add a few tests. + 2004-12-09 Paolo Carlini * include/tr1/type_traits: Implement remove_extent and diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 6b698b0623a..13d7ebdf64d 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -256,13 +256,35 @@ namespace tr1 /// @brief const-volatile modifications [4.7.1]. template - struct remove_const; + struct remove_const + { + typedef _Tp type; + }; + + template + struct remove_const<_Tp const> + { + typedef _Tp type; + }; template - struct remove_volatile; + struct remove_volatile + { + typedef _Tp type; + }; + + template + struct remove_volatile<_Tp volatile> + { + typedef _Tp type; + }; template - struct remove_cv; + struct remove_cv + { + typedef typename + remove_const::type>::type type; + }; template struct add_const; diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_const.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_const.cc new file mode 100644 index 00000000000..1def556b4b1 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_const.cc @@ -0,0 +1,47 @@ +// 2004-12-10 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.1 Const-volatile modifications + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::remove_const; + using std::tr1::is_same; + using namespace __gnu_test; + + VERIFY( (is_same::type, + volatile int>::value) ); + VERIFY( (is_same::type, const int*>::value) ); + VERIFY( (is_same::type, + volatile ClassType>::value) ); + VERIFY( (is_same::type, + const ClassType*>::value) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_cv.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_cv.cc new file mode 100644 index 00000000000..775f6ef5f34 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_cv.cc @@ -0,0 +1,47 @@ +// 2004-12-10 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.1 Const-volatile modifications + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::remove_cv; + using std::tr1::is_same; + using namespace __gnu_test; + + VERIFY( (is_same::type, int>::value) ); + VERIFY( (is_same::type, + const volatile int*>::value) ); + VERIFY( (is_same::type, + ClassType>::value) ); + VERIFY( (is_same::type, + const volatile ClassType*>::value) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_volatile.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_volatile.cc new file mode 100644 index 00000000000..7cf9bf661fc --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_volatile.cc @@ -0,0 +1,48 @@ +// 2004-12-10 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.1 Const-volatile modifications + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::remove_volatile; + using std::tr1::is_same; + using namespace __gnu_test; + + VERIFY( (is_same::type, + const int>::value) ); + VERIFY( (is_same::type, + volatile int*>::value) ); + VERIFY( (is_same::type, + const ClassType>::value) ); + VERIFY( (is_same::type, + volatile ClassType*>::value) ); +} + +int main() +{ + test01(); + return 0; +} 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 69777209ba2..bb4e363f04f 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 @@ -30,19 +30,18 @@ void test01() using std::tr1::is_array; using namespace __gnu_test; - typedef int int_array[5]; - typedef int empty_int_array[]; - typedef float* pointer_array[5]; - typedef float* empty_pointer_array[]; - typedef ClassType ClassType_array[5]; - typedef ClassType empty_ClassType_array[]; - - VERIFY( (test_category()) ); - VERIFY( (test_category()) ); - VERIFY( (test_category()) ); - VERIFY( (test_category()) ); - VERIFY( (test_category()) ); - VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); + VERIFY( (test_category()) ); // Sanity check. VERIFY( (test_category()) ); -- 2.30.2