This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] tr1/type_traits remove_const, remove_volatile, remove_cv


Hi,

more simple work. Tested x86-linux.

Paolo.

/////////////
2004-12-10  Paolo Carlini  <pcarlini@suse.de>

	* 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.
diff -urN libstdc++-v3-orig/include/tr1/type_traits libstdc++-v3/include/tr1/type_traits
--- libstdc++-v3-orig/include/tr1/type_traits	2004-12-09 17:58:30.000000000 +0100
+++ libstdc++-v3/include/tr1/type_traits	2004-12-10 00:18:21.000000000 +0100
@@ -256,13 +256,35 @@
 
   /// @brief  const-volatile modifications [4.7.1].
   template<typename _Tp>
-    struct remove_const;
+    struct remove_const
+    {
+      typedef _Tp     type;
+    };
+
+  template<typename _Tp>
+    struct remove_const<_Tp const>
+    {
+      typedef _Tp     type;
+    };
   
   template<typename _Tp>
-    struct remove_volatile;
+    struct remove_volatile
+    {
+      typedef _Tp     type;
+    };
+
+  template<typename _Tp>
+    struct remove_volatile<_Tp volatile>
+    {
+      typedef _Tp     type;
+    };
   
   template<typename _Tp>
-    struct remove_cv;
+    struct remove_cv
+    {
+      typedef typename
+      remove_const<typename remove_volatile<_Tp>::type>::type     type;
+    };
   
   template<typename _Tp>
     struct add_const;
diff -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_const.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_const.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_const.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_const.cc	2004-12-10 12:06:26.000000000 +0100
@@ -0,0 +1,47 @@
+// 2004-12-10  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.7.1 Const-volatile modifications
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::tr1::remove_const;
+  using std::tr1::is_same;
+  using namespace __gnu_test;
+
+  VERIFY( (is_same<remove_const<const volatile int>::type,
+	   volatile int>::value) );
+  VERIFY( (is_same<remove_const<const int*>::type, const int*>::value) );
+  VERIFY( (is_same<remove_const<const volatile ClassType>::type,
+	   volatile ClassType>::value) );
+  VERIFY( (is_same<remove_const<const ClassType*>::type,
+	   const ClassType*>::value) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_cv.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_cv.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_cv.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_cv.cc	2004-12-10 12:18:17.000000000 +0100
@@ -0,0 +1,47 @@
+// 2004-12-10  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.7.1 Const-volatile modifications
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::tr1::remove_cv;
+  using std::tr1::is_same;
+  using namespace __gnu_test;
+
+  VERIFY( (is_same<remove_cv<const volatile int>::type, int>::value) );
+  VERIFY( (is_same<remove_cv<const volatile int*>::type,
+	   const volatile int*>::value) );
+  VERIFY( (is_same<remove_cv<const volatile ClassType>::type,
+	   ClassType>::value) );
+  VERIFY( (is_same<remove_cv<const volatile ClassType*>::type,
+	   const volatile ClassType*>::value) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_volatile.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_volatile.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_volatile.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/const_volatile_modifications/remove_volatile.cc	2004-12-10 12:15:39.000000000 +0100
@@ -0,0 +1,48 @@
+// 2004-12-10  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.7.1 Const-volatile modifications
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::tr1::remove_volatile;
+  using std::tr1::is_same;
+  using namespace __gnu_test;
+
+  VERIFY( (is_same<remove_volatile<const volatile int>::type,
+	   const int>::value) );
+  VERIFY( (is_same<remove_volatile<volatile int*>::type,
+	   volatile int*>::value) );
+  VERIFY( (is_same<remove_volatile<const volatile ClassType>::type,
+	   const ClassType>::value) );
+  VERIFY( (is_same<remove_volatile<volatile ClassType*>::type,
+	   volatile ClassType*>::value) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc	2004-12-07 13:45:25.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc	2004-12-09 23:54:29.000000000 +0100
@@ -30,19 +30,18 @@
   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<is_array, int_array, true>()) );
-  VERIFY( (test_category<is_array, empty_int_array, true>()) );
-  VERIFY( (test_category<is_array, pointer_array, true>()) );
-  VERIFY( (test_category<is_array, empty_pointer_array, true>()) );
-  VERIFY( (test_category<is_array, ClassType_array, true>()) );
-  VERIFY( (test_category<is_array, empty_ClassType_array, true>()) );
+  VERIFY( (test_category<is_array, int[2], true>()) );
+  VERIFY( (test_category<is_array, int[], true>()) );
+  VERIFY( (test_category<is_array, int[2][3], true>()) );
+  VERIFY( (test_category<is_array, int[][3], true>()) );
+  VERIFY( (test_category<is_array, float*[2], true>()) );
+  VERIFY( (test_category<is_array, float*[], true>()) );
+  VERIFY( (test_category<is_array, float*[2][3], true>()) );
+  VERIFY( (test_category<is_array, float*[][3], true>()) );
+  VERIFY( (test_category<is_array, ClassType[2], true>()) );
+  VERIFY( (test_category<is_array, ClassType[], true>()) );
+  VERIFY( (test_category<is_array, ClassType[2][3], true>()) );
+  VERIFY( (test_category<is_array, ClassType[][3], true>()) );
 
   // Sanity check.
   VERIFY( (test_category<is_array, ClassType, false>()) );

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]