aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2011-05-19 20:48:39 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2011-05-19 20:48:39 +0000
commit664e12c1265280786f83d8fd1ec1ebbf50c153c0 (patch)
treeaa4e6b793f8fc46762e5dce6559c2aacda23a1ed /libstdc++-v3
parent173f26ae56c9d4ac260db7a3d7b3ee44b7d07bf2 (diff)
downloadgcc-664e12c1265280786f83d8fd1ec1ebbf50c153c0.zip
gcc-664e12c1265280786f83d8fd1ec1ebbf50c153c0.tar.gz
gcc-664e12c1265280786f83d8fd1ec1ebbf50c153c0.tar.bz2
tuple (tuple_element<__i, [...]): Add.
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. From-SVN: r173919
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog13
-rw-r--r--libstdc++-v3/include/std/array12
-rw-r--r--libstdc++-v3/include/std/tuple48
-rw-r--r--libstdc++-v3/include/std/utility6
-rw-r--r--libstdc++-v3/testsuite/20_util/tuple/cv_tuple_element.cc34
-rw-r--r--libstdc++-v3/testsuite/20_util/tuple/cv_tuple_size.cc45
-rw-r--r--libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc2
7 files changed, 139 insertions, 21 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 6275373..f6b9159 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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.
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index b0fc75b..474b884 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -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; };
diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 682e3c9..dc9330d 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -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
diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility
index 5c6bd03..f433e46 100644
--- a/libstdc++-v3/include/std/utility
+++ b/libstdc++-v3/include/std/utility
@@ -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
index 0000000..df4fb43
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/cv_tuple_element.cc
@@ -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
index 0000000..8224528
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/cv_tuple_size.cc
@@ -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;
+}
diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc
index 24168ce..d449be3 100644
--- a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc
@@ -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 }