type_traits: Implement is_const and is_volatile.
authorPaolo Carlini <pcarlini@suse.de>
Tue, 7 Dec 2004 16:40:46 +0000 (16:40 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 7 Dec 2004 16:40:46 +0000 (16:40 +0000)
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:
libstdc++-v3/ChangeLog
libstdc++-v3/include/tr1/type_traits
libstdc++-v3/testsuite/testsuite_tr1.h
libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_arithmetic/is_arithmetic.cc
libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_fundamental/is_fundamental.cc
libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_array/is_array.cc
libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_floating_point/is_floating_point.cc
libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_integral/is_integral.cc
libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc
libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_void/is_void.cc
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/typedefs.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/typedefs.cc [new file with mode: 0644]

index f7867cb8c12b6510cf382fdbb68d1d856e638932..732bb4e1990efccc2ddff4d6999c16dee4639ff6 100644 (file)
@@ -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.
index 44d8a4e35839f09ed56dd377726a1bd39faa3fa9..928e2aa36e5dcc9311fda5718499ae2be3530cae 100644 (file)
@@ -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;
index 70695684024a73f95e269abe20bdf2bd294cbe95..18563f48e4cc243c2a9ae42247745b21b72eb7a2 100644 (file)
@@ -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
index f27ad75fe81c68ffeee635334d87b4c4edf86367..a507d8609790667fadd76f4172fbb29847170a4c 100644 (file)
 #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>()) );
 
index 2858de469acc4a5f22f84069ffef5d27e8a51bbc..9106ee504ffaafb857120bd7d520c51c3ab656bf 100644 (file)
 #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>()) );
index 66b1894a35395b583aeb59bdf9a4b9fdfb291c84..69777209ba2e5cb31a184018526a112ae7309b1b 100644 (file)
 #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[];
index deed15dbe6c412278a638491aaf019abc2341c7b..c24de1a5d5aaee83d096770c082fd129d63b0653 100644 (file)
 #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>()) );
index d746edb8992a7de43194e6ceab7ec5534abdeb8b..812ff080b8123e554aa2e7dd9c2da98ac9952789 100644 (file)
 #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>()) );
   
index 2442edb3b0505c3f37f0d40ab58c58f73f81d1f2..cd59f4d6ac1ef8fe4124ce621ae5ed06a63dc464 100644 (file)
 #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;
index 46b8629ade94746198c13b1bf3d6b582b4b57ca0..e65208c821e85c784c0f009fa0b6fac447f661c4 100644 (file)
 #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 (file)
index 0000000..5202161
--- /dev/null
@@ -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 (file)
index 0000000..9910698
--- /dev/null
@@ -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 (file)
index 0000000..4dc791f
--- /dev/null
@@ -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 (file)
index 0000000..5104163
--- /dev/null
@@ -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;
+}