OSDN Git Service

2004-12-08 Paolo Carlini <pcarlini@suse.de>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 8 Dec 2004 16:33:51 +0000 (16:33 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 8 Dec 2004 16:33:51 +0000 (16:33 +0000)
* include/tr1/type_traits: Implement is_same, add_reference and
remove_reference.
* testsuite/testsuite_tr1.h (test_relationship): New.
* testsuite/tr1/4_metaprogramming/reference_modifications/
add_reference.cc: New.
* testsuite/tr1/4_metaprogramming/reference_modifications/
remove_reference.cc: Likewise.
* testsuite/tr1/4_metaprogramming/relationships_between_types/
is_same/is_same.cc: Likewise.
* testsuite/tr1/4_metaprogramming/relationships_between_types/
is_same/typedefs.cc: Likewise.

* testsuite/tr1/4_metaprogramming/type_properties/is_const/
is_const.cc: Minor tweaks.
* testsuite/tr1/4_metaprogramming/type_properties/is_volatile/
is_volatile.cc: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@91907 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/tr1/type_traits
libstdc++-v3/testsuite/testsuite_tr1.h
libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/remove_reference.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/is_same.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc

index 10d7832..2c285e5 100644 (file)
@@ -1,3 +1,22 @@
+2004-12-08  Paolo Carlini  <pcarlini@suse.de>
+
+       * include/tr1/type_traits: Implement is_same, add_reference and
+       remove_reference.
+       * testsuite/testsuite_tr1.h (test_relationship): New.
+       * testsuite/tr1/4_metaprogramming/reference_modifications/
+       add_reference.cc: New.
+       * testsuite/tr1/4_metaprogramming/reference_modifications/
+       remove_reference.cc: Likewise.
+       * testsuite/tr1/4_metaprogramming/relationships_between_types/
+       is_same/is_same.cc: Likewise.
+       * testsuite/tr1/4_metaprogramming/relationships_between_types/
+       is_same/typedefs.cc: Likewise.
+
+       * testsuite/tr1/4_metaprogramming/type_properties/is_const/
+       is_const.cc: Minor tweaks.
+       * testsuite/tr1/4_metaprogramming/type_properties/is_volatile/
+       is_volatile.cc: Likewise.
+
 2004-12-08  David Edelsohn  <edelsohn@gnu.org>
 
        * Makefile.am (AM_MAKEFLAGS): Remove duplicate LIBCFLAGS and
index 928e2aa..742536c 100644 (file)
@@ -240,8 +240,13 @@ namespace tr1
     struct extent;
   
   /// @brief  relationships between types [4.6].
-  template<typename _Tp, typename _Up>
-    struct is_same;
+  template<typename, typename>
+    struct is_same
+    : public false_type { };
+
+  template<typename _Tp>
+    struct is_same<_Tp, _Tp>
+    : public true_type { };
 
   template<typename _From, typename _To>
     struct is_convertible;
@@ -270,10 +275,28 @@ namespace tr1
 
   /// @brief  reference modifications [4.7.2].
   template<typename _Tp>
-    struct remove_reference;
+    struct remove_reference
+    {
+      typedef _Tp     type;
+    };
+
+  template<typename _Tp>
+    struct remove_reference<_Tp&>
+    {
+      typedef _Tp     type;
+    };
   
   template<typename _Tp>
-    struct add_reference;
+    struct add_reference
+    {
+      typedef _Tp&    type;
+    };
+
+  template<typename _Tp>
+    struct add_reference<_Tp&>
+    {
+      typedef _Tp&    type;
+    };
 
   /// @brief  array modififications [4.7.3].
   template<typename _Tp>
index 18563f4..b3d4cf9 100644 (file)
@@ -41,13 +41,13 @@ namespace __gnu_test
     {
       bool ret = true;
       ret &= Category<Type>::value == Tv;
-      ret &= Category<Type const>::value == Tv;
-      ret &= Category<Type volatile>::value == Tv;
-      ret &= Category<Type const volatile>::value == Tv;
+      ret &= Category<const Type>::value == Tv;
+      ret &= Category<volatile Type>::value == Tv;
+      ret &= Category<const volatile Type>::value == Tv;
       ret &= Category<Type>::type::value == Tv;
-      ret &= Category<Type const>::type::value == Tv;
-      ret &= Category<Type volatile>::type::value == Tv;
-      ret &= Category<Type const volatile>::type::value == Tv;
+      ret &= Category<const Type>::type::value == Tv;
+      ret &= Category<volatile Type>::type::value == Tv;
+      ret &= Category<const volatile Type>::type::value == Tv;
       return ret;
     }
 
@@ -62,11 +62,22 @@ namespace __gnu_test
       return ret;
     }
 
+  template<template<typename, typename> class Relationship,
+          typename Type1, typename Type2, bool Tv>
+    bool
+    test_relationship()
+    {
+      bool ret = true;
+      ret &= Relationship<Type1, Type2>::value == Tv;
+      ret &= Relationship<Type1, Type2>::type::value == Tv;
+      return ret;
+    }
+
   // Test types.
   class ClassType { };
-  typedef ClassType const           cClassType;
-  typedef ClassType volatile        vClassType;
-  typedef ClassType const volatile  cvClassType;
+  typedef const ClassType           cClassType;
+  typedef volatile ClassType        vClassType;
+  typedef const volatile ClassType  cvClassType;
 }; // namespace __gnu_test
 
 #endif // _GLIBCXX_TESTSUITE_TR1_H
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc
new file mode 100644 (file)
index 0000000..7674689
--- /dev/null
@@ -0,0 +1,46 @@
+// 2004-12-08  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.2 Reference modifications
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::tr1::add_reference;
+  using std::tr1::is_same;
+  using namespace __gnu_test;
+
+  VERIFY( (is_same<add_reference<int>::type, int&>::value) );
+  VERIFY( (is_same<add_reference<int&>::type, int&>::value) );
+  VERIFY( (is_same<add_reference<const int>::type, const int&>::value) );
+  VERIFY( (is_same<add_reference<int*>::type, int*&>::value) );
+  VERIFY( (is_same<add_reference<ClassType&>::type, ClassType&>::value) );
+  VERIFY( (is_same<add_reference<ClassType>::type, ClassType&>::value) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/remove_reference.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/remove_reference.cc
new file mode 100644 (file)
index 0000000..f21d1a0
--- /dev/null
@@ -0,0 +1,46 @@
+// 2004-12-08  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.2 Reference modifications
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::tr1::remove_reference;
+  using std::tr1::is_same;
+  using namespace __gnu_test;
+
+  VERIFY( (is_same<remove_reference<int&>::type, int>::value) );
+  VERIFY( (is_same<remove_reference<int>::type, int>::value) );
+  VERIFY( (is_same<remove_reference<const int&>::type, const int>::value) );
+  VERIFY( (is_same<remove_reference<int*&>::type, int*>::value) );
+  VERIFY( (is_same<remove_reference<ClassType&>::type, ClassType>::value) );
+  VERIFY( (is_same<remove_reference<ClassType>::type, ClassType>::value) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/is_same.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/is_same.cc
new file mode 100644 (file)
index 0000000..32d65af
--- /dev/null
@@ -0,0 +1,50 @@
+// 2004-12-08  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.6 Relationships between types
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::tr1::is_same;
+  using namespace __gnu_test;
+
+  // Positive tests.
+  VERIFY( (test_relationship<is_same, int, int, true>()) );
+  VERIFY( (test_relationship<is_same, const int, const int, true>()) );
+  VERIFY( (test_relationship<is_same, int&, int&, true>()) );
+  VERIFY( (test_relationship<is_same, ClassType, ClassType, true>()) );
+
+  // Negative tests.
+  VERIFY( (test_relationship<is_same, void, int, false>()) );
+  VERIFY( (test_relationship<is_same, int, const int, false>()) );
+  VERIFY( (test_relationship<is_same, int, int&, false>()) );
+  VERIFY( (test_relationship<is_same, int, ClassType, false>()) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc
new file mode 100644 (file)
index 0000000..39c47e2
--- /dev/null
@@ -0,0 +1,36 @@
+// 2004-12-08  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_same<int, 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 5202161..82de428 100644 (file)
@@ -31,14 +31,14 @@ void test01()
   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, const int, true>()) );
+  VERIFY( (test_property<is_const, const volatile int, 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, volatile int, false>()) );
   VERIFY( (test_property<is_const, ClassType, false>()) );
   VERIFY( (test_property<is_const, vClassType, false>()) );
 }
index 4dc791f..c47ec78 100644 (file)
@@ -31,14 +31,14 @@ void test01()
   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, volatile int, true>()) );
+  VERIFY( (test_property<is_volatile, const volatile int, 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, const int, false>()) );
   VERIFY( (test_property<is_volatile, ClassType, false>()) );
   VERIFY( (test_property<is_volatile, cClassType, false>()) );
 }