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] Add tr1/type_traits is_const/is_volatile bits


Hi,

more straightforward bits + minor tweaks to the testing
infrastructure.

Tested x86-linux.

Paolo.

//////////////
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.
diff -urN libstdc++-v3-orig/include/tr1/type_traits libstdc++-v3/include/tr1/type_traits
--- libstdc++-v3-orig/include/tr1/type_traits	2004-12-06 12:21:13.000000000 +0100
+++ libstdc++-v3/include/tr1/type_traits	2004-12-07 11:25:15.000000000 +0100
@@ -171,11 +171,21 @@
     : 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 -urN libstdc++-v3-orig/testsuite/testsuite_tr1.h libstdc++-v3/testsuite/testsuite_tr1.h
--- libstdc++-v3-orig/testsuite/testsuite_tr1.h	2004-12-04 10:08:40.000000000 +0100
+++ libstdc++-v3/testsuite/testsuite_tr1.h	2004-12-07 12:32:10.000000000 +0100
@@ -50,6 +50,23 @@
       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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/composite_type_traits/is_arithmetic/is_arithmetic.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_arithmetic/is_arithmetic.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/composite_type_traits/is_arithmetic/is_arithmetic.cc	2004-12-04 10:08:40.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_arithmetic/is_arithmetic.cc	2004-12-07 13:44:52.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/composite_type_traits/is_fundamental/is_fundamental.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_fundamental/is_fundamental.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/composite_type_traits/is_fundamental/is_fundamental.cc	2004-12-04 10:08:41.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_fundamental/is_fundamental.cc	2004-12-07 13:45:09.000000000 +0100
@@ -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 -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-04 10:08:41.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc	2004-12-07 13:45:25.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_floating_point/is_floating_point.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_floating_point/is_floating_point.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_floating_point/is_floating_point.cc	2004-12-04 10:08:42.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_floating_point/is_floating_point.cc	2004-12-07 13:45:39.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_integral/is_integral.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_integral/is_integral.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_integral/is_integral.cc	2004-12-04 10:08:42.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_integral/is_integral.cc	2004-12-07 13:45:52.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc	2004-12-06 16:39:51.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc	2004-12-07 13:46:04.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_void/is_void.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_void/is_void.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_void/is_void.cc	2004-12-04 10:08:42.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_void/is_void.cc	2004-12-07 13:46:16.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc	2004-12-07 13:46:32.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_const/typedefs.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/typedefs.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_const/typedefs.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/typedefs.cc	2004-12-07 11:42:07.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc	2004-12-07 13:46:47.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/typedefs.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/typedefs.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/typedefs.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/typedefs.cc	2004-12-07 11:48:58.000000000 +0100
@@ -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;
+}

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