2011-05-19 Paolo Carlini <paolo.carlini@oracle.com>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 19 May 2011 20:48:39 +0000 (20:48 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 19 May 2011 20:48:39 +0000 (20:48 +0000)
* include/std/tuple (tuple_element<__i, const _Tp>,
tuple_element<__i, volatile _Tp>, tuple_element<__i,
const volatile _Tp>, tuple_size<const _Tp>, tuple_size<volatile _Tp>,
tuple_size<const volatile _Tp>): Add.
* include/std/utility (tuple_size<std::pair<_Tp1, _Tp2>>): Tweak.
* include/std/array (tuple_size<array<_Tp, _Nm>>): Likewise.
* testsuite/20_util/tuple/cv_tuple_size.cc: New.
* testsuite/20_util/tuple/cv_tuple_element.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Tweak dg-warning
line number.

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

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/array
libstdc++-v3/include/std/tuple
libstdc++-v3/include/std/utility
libstdc++-v3/testsuite/20_util/tuple/cv_tuple_element.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/tuple/cv_tuple_size.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc

index 6275373..f6b9159 100644 (file)
@@ -1,5 +1,18 @@
 2011-05-19  Paolo Carlini  <paolo.carlini@oracle.com>
 
+       * include/std/tuple (tuple_element<__i, const _Tp>,
+       tuple_element<__i, volatile _Tp>, tuple_element<__i,
+       const volatile _Tp>, tuple_size<const _Tp>, tuple_size<volatile _Tp>,
+       tuple_size<const volatile _Tp>): Add.
+       * include/std/utility (tuple_size<std::pair<_Tp1, _Tp2>>): Tweak.
+       * include/std/array (tuple_size<array<_Tp, _Nm>>): Likewise.
+       * testsuite/20_util/tuple/cv_tuple_size.cc: New.
+       * testsuite/20_util/tuple/cv_tuple_element.cc: Likewise.
+       * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Tweak dg-warning
+       line number.
+
+2011-05-19  Paolo Carlini  <paolo.carlini@oracle.com>
+
        * include/std/tuple (tuple<>::operator=(tuple&&)): Specify as
         noexcept.
        (__get_helper): Likewise.
index b0fc75b..474b884 100644 (file)
@@ -242,18 +242,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp> 
     class tuple_size;
 
+  template<typename _Tp, std::size_t _Nm>
+    struct tuple_size<array<_Tp, _Nm>>
+    : public integral_constant<std::size_t, _Nm> { };
+
   /// tuple_element
   template<std::size_t _Int, typename _Tp>
     class tuple_element;
 
-  template<typename _Tp, std::size_t _Nm>
-    struct tuple_size<array<_Tp, _Nm> >
-    { static const std::size_t value = _Nm; };
-
-  template<typename _Tp, std::size_t _Nm>
-    const std::size_t
-    tuple_size<array<_Tp, _Nm> >::value;  
-
   template<std::size_t _Int, typename _Tp, std::size_t _Nm>
     struct tuple_element<_Int, array<_Tp, _Nm> >
     { typedef _Tp type; };
index 682e3c9..dc9330d 100644 (file)
@@ -505,19 +505,53 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       typedef _Head type;
     };
 
+  template<std::size_t __i, typename _Tp>
+    struct tuple_element<__i, const _Tp>
+    {
+      typedef typename
+      add_const<typename tuple_element<__i, _Tp>::type>::type type;
+    };
+
+  template<std::size_t __i, typename _Tp>
+    struct tuple_element<__i, volatile _Tp>
+    {
+      typedef typename
+      add_volatile<typename tuple_element<__i, _Tp>::type>::type type;
+    };
+
+  template<std::size_t __i, typename _Tp>
+    struct tuple_element<__i, const volatile _Tp>
+    {
+      typedef typename
+      add_cv<typename tuple_element<__i, _Tp>::type>::type type;
+    };
+
   /// Finds the size of a given tuple type.
   template<typename _Tp>
     struct tuple_size;
 
-  /// class tuple_size
-  template<typename... _Elements>
-    struct tuple_size<tuple<_Elements...> >
-    {
-      static const std::size_t value = sizeof...(_Elements);
-    };
+  template<typename _Tp>
+    struct tuple_size<const _Tp>
+    : public integral_constant<
+             typename remove_cv<decltype(tuple_size<_Tp>::value)>::type,
+             tuple_size<_Tp>::value> { };
 
+  template<typename _Tp>
+    struct tuple_size<volatile _Tp>
+    : public integral_constant<
+             typename remove_cv<decltype(tuple_size<_Tp>::value)>::type,
+             tuple_size<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct tuple_size<const volatile _Tp>
+    : public integral_constant<
+             typename remove_cv<decltype(tuple_size<_Tp>::value)>::type,
+             tuple_size<_Tp>::value> { };
+
+  /// class tuple_size
   template<typename... _Elements>
-    const std::size_t tuple_size<tuple<_Elements...> >::value;
+    struct tuple_size<tuple<_Elements...>>
+    : public integral_constant<std::size_t, sizeof...(_Elements)> { };
 
   template<std::size_t __i, typename _Head, typename... _Tail>
     inline typename __add_ref<_Head>::type
index 5c6bd03..f433e46 100644 (file)
@@ -88,11 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    // Various functions which give std::pair a tuple-like interface.
   template<class _Tp1, class _Tp2>
     struct tuple_size<std::pair<_Tp1, _Tp2>>
-    { static const std::size_t value = 2; };
-
-  template<class _Tp1, class _Tp2>
-    const std::size_t
-    tuple_size<std::pair<_Tp1, _Tp2> >::value;
+    : public integral_constant<std::size_t, 2> { };
 
   template<class _Tp1, class _Tp2>
     struct tuple_element<0, std::pair<_Tp1, _Tp2>>
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cv_tuple_element.cc b/libstdc++-v3/testsuite/20_util/tuple/cv_tuple_element.cc
new file mode 100644 (file)
index 0000000..df4fb43
--- /dev/null
@@ -0,0 +1,34 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// 2011-05-19  Paolo Carlini  <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2011 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 3, 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// Tuple
+
+#include <tuple>
+
+using namespace std;
+
+static_assert(is_same<tuple_element<0, const tuple<double, void, int>>::type,
+             const double>::value, "Error");
+static_assert(is_same<tuple_element<1, volatile tuple<short, void>>::type,
+             volatile void>::value, "Error");
+static_assert(is_same<tuple_element<2, const volatile tuple<float,
+             char, int>>::type, const volatile int>::value, "Error");
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cv_tuple_size.cc b/libstdc++-v3/testsuite/20_util/tuple/cv_tuple_size.cc
new file mode 100644 (file)
index 0000000..8224528
--- /dev/null
@@ -0,0 +1,45 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 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 3, 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// Tuple
+
+#include <tuple>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+  using namespace std;
+
+  VERIFY( tuple_size<const tuple<> >::value == 0 );
+  VERIFY( tuple_size<volatile tuple<int> >::value == 1 );
+  VERIFY( tuple_size<const volatile tuple<void> >::value == 1 );
+
+  typedef tuple<int, const int&, void> test_tuple1;
+  VERIFY( tuple_size<const test_tuple1>::value == 3 );
+  VERIFY( tuple_size<const volatile test_tuple1>::value == 3 );
+  VERIFY( tuple_size<volatile tuple<tuple<void> > >::value == 1 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index 24168ce..d449be3 100644 (file)
@@ -51,7 +51,7 @@ main()
 // { dg-warning "note" "" { target *-*-* } 485 }
 // { dg-warning "note" "" { target *-*-* } 479 }
 // { dg-warning "note" "" { target *-*-* } 469 }
-// { dg-warning "note" "" { target *-*-* } 603 }
+// { dg-warning "note" "" { target *-*-* } 637 }
 // { dg-warning "note" "" { target *-*-* } 1056 }
 // { dg-warning "note" "" { target *-*-* } 1050 }
 // { dg-warning "note" "" { target *-*-* } 342 }