diff mbox

Simplify std::tuple helpers and fix C++14 bug.

Message ID 20140515103807.GH10556@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely May 15, 2014, 10:38 a.m. UTC
On 15/05/14 07:36 +0200, Daniel Krügler wrote:
>Looking at the definition of the new alias
>
>__cv_tuple_size
>
>you might want to apply LWG 2313
>
>http://cplusplus.github.io/LWG/lwg-defects.html#2313
>
>and simplify its definition even further.

I forgot about that. With that resolution the __cv_tuple_size alias
doesn't seem worth using, it's simple enough anyway. Thanks!

Tested x86_64-linux, committed to trunk.
diff mbox

Patch

commit 420a40952d148f64e73517c75060e6ff17e7c93b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu May 15 11:02:30 2014 +0100

    	* include/std/tuple (tuple_size<cv _Tp>): Implement LWG 2313.
    	* include/std/array (tuple_size, tuple_element): Add Doxygen comments.
    	* include/std/utility (tuple_size, tuple_element): Likewise.
    	* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
    	Adjust dg-error line number.

diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 22947ce..cc2c864 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -306,6 +306,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp> 
     class tuple_size;
 
+  /// Partial specialization for std::array
   template<typename _Tp, std::size_t _Nm>
     struct tuple_size<_GLIBCXX_STD_C::array<_Tp, _Nm>>
     : public integral_constant<std::size_t, _Nm> { };
@@ -314,6 +315,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<std::size_t _Int, typename _Tp>
     class tuple_element;
 
+  /// Partial specialization for std::array
   template<std::size_t _Int, typename _Tp, std::size_t _Nm>
     struct tuple_element<_Int, _GLIBCXX_STD_C::array<_Tp, _Nm>>
     {
diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 95c197d..ef8aa5a 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -693,18 +693,19 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp>
     struct tuple_size;
 
-  template<typename _Tp, typename _Ts = tuple_size<_Tp>>
-    using __cv_tuple_size = integral_constant<
-             typename remove_cv<decltype(_Ts::value)>::type, _Ts::value>;
-
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2313. tuple_size should always derive from integral_constant<size_t, N>
   template<typename _Tp>
-    struct tuple_size<const _Tp> : __cv_tuple_size<_Tp> { };
+    struct tuple_size<const _Tp>
+    : integral_constant<size_t, tuple_size<_Tp>::value> { };
 
   template<typename _Tp>
-    struct tuple_size<volatile _Tp> : __cv_tuple_size<_Tp> { };
+    struct tuple_size<volatile _Tp>
+    : integral_constant<size_t, tuple_size<_Tp>::value> { };
 
   template<typename _Tp>
-    struct tuple_size<const volatile _Tp> : __cv_tuple_size<_Tp> { };
+    struct tuple_size<const volatile _Tp>
+    : integral_constant<size_t, tuple_size<_Tp>::value> { };
 
   /// class tuple_size
   template<typename... _Elements>
diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility
index 4da9209..6d12839e 100644
--- a/libstdc++-v3/include/std/utility
+++ b/libstdc++-v3/include/std/utility
@@ -84,14 +84,18 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     class tuple_element;
 
    // Various functions which give std::pair a tuple-like interface.
+
+  /// Partial specialization for std::pair
   template<class _Tp1, class _Tp2>
     struct tuple_size<std::pair<_Tp1, _Tp2>>
     : public integral_constant<std::size_t, 2> { };
 
+  /// Partial specialization for std::pair
   template<class _Tp1, class _Tp2>
     struct tuple_element<0, std::pair<_Tp1, _Tp2>>
     { typedef _Tp1 type; };
  
+  /// Partial specialization for std::pair
   template<class _Tp1, class _Tp2>
     struct tuple_element<1, std::pair<_Tp1, _Tp2>>
     { typedef _Tp2 type; };
diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc
index f80798c..4b1e5ae 100644
--- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc
@@ -23,4 +23,4 @@ 
 
 typedef std::tuple_element<1, std::array<int, 1>>::type type;
 
-// { dg-error "static assertion failed" "" { target *-*-* } 320 }
+// { dg-error "static assertion failed" "" { target *-*-* } 322 }