From patchwork Fri Jun 13 12:01:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 359540 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9D1C014007C for ; Fri, 13 Jun 2014 22:01:29 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :content-transfer-encoding:in-reply-to; q=dns; s=default; b=J2aL 8VT7JPnfIsTs2uH91w14yCKhEirlL7vJ66jiFslyZq/qJJtXaGj9imO4TDDNoaKw Z+Xh35U1yZGjIl2vZH9UbrT7+cDoSfrS5CCdJvDlMcXtAigTYzZOqOYGGyIO/YZ2 29CI3RlwOcRN6Lw+Kl2VsphtR8tll4EmHmqc8zQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :content-transfer-encoding:in-reply-to; s=default; bh=YANG4RyBAB pj4ZpZwxSiUFkymQA=; b=HBSF5qXWADQHmukvtjeRDDGDMjoqbrjTp1fntLSm0r RV81fKOHenHIrD6a6npDnO35jiBJGjGPcuG0Y3IiTQvU/8Y5wCrI/jRDJ+S1zh9R AbglanzZE6qOmsebvVTcgCxzkG8RYL8bOoChsUah0R08/tSplypdjZLXNnJrzOVb 0= Received: (qmail 2785 invoked by alias); 13 Jun 2014 12:01:23 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 2761 invoked by uid 89); 13 Jun 2014 12:01:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Jun 2014 12:01:21 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5DC1Ju8030974 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Jun 2014 08:01:19 -0400 Received: from localhost (vpn1-4-149.ams2.redhat.com [10.36.4.149]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5DC1ItK006601; Fri, 13 Jun 2014 08:01:18 -0400 Date: Fri, 13 Jun 2014 13:01:17 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [patch] Simplify std::tuple helpers and fix C++14 bug. Message-ID: <20140613120117.GF30729@redhat.com> References: <20140514222236.GG10556@redhat.com> <20140515103807.GH10556@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140515103807.GH10556@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) On 15/05/14 11:38 +0100, Jonathan Wakely wrote: >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. Here's a simpler patch for the 4.9 branch, just fixing the bug and implementing the DR, committed. commit b6ae8cc2cd135241ae2a3bd539f9c87b7ad6fe87 Author: Jonathan Wakely Date: Fri Jun 13 12:33:32 2014 +0100 * include/std/tuple (tuple_size): Implement LWG 2313. (get<_Tp>(tuple<_Types...>&&)): Use forward instead of move. * testsuite/20_util/tuple/element_access/get_by_type.cc: Test rvalues. diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 03d87d7..103c99e 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -719,23 +719,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct tuple_size; + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2313. tuple_size should always derive from integral_constant template struct tuple_size - : public integral_constant< - typename remove_cv::value)>::type, - tuple_size<_Tp>::value> { }; + : public integral_constant::value> { }; template struct tuple_size - : public integral_constant< - typename remove_cv::value)>::type, - tuple_size<_Tp>::value> { }; + : public integral_constant::value> { }; template struct tuple_size - : public integral_constant< - typename remove_cv::value)>::type, - tuple_size<_Tp>::value> { }; + : public integral_constant::value> { }; /// class tuple_size template @@ -752,9 +748,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); } - // Return a reference (const reference, rvalue reference) to the ith element - // of a tuple. Any const or non-const ref elements are returned with their - // original type. + /// Return a reference to the ith element of a tuple. template constexpr typename __add_ref< typename tuple_element<__i, tuple<_Elements...>>::type @@ -762,6 +756,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION get(tuple<_Elements...>& __t) noexcept { return std::__get_helper<__i>(__t); } + /// Return a const reference to the ith element of a const tuple. template constexpr typename __add_c_ref< typename tuple_element<__i, tuple<_Elements...>>::type @@ -769,6 +764,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION get(const tuple<_Elements...>& __t) noexcept { return std::__get_helper<__i>(__t); } + /// Return an rvalue reference to the ith element of a tuple rvalue. template constexpr typename __add_r_ref< typename tuple_element<__i, tuple<_Elements...>>::type @@ -788,22 +784,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); } + /// Return a reference to the unique element of type _Tp of a tuple. template constexpr _Tp& get(tuple<_Types...>& __t) noexcept { return std::__get_helper2<_Tp>(__t); } + /// Return a reference to the unique element of type _Tp of a tuple rvalue. template constexpr _Tp&& get(tuple<_Types...>&& __t) noexcept - { return std::move(std::__get_helper2<_Tp>(__t)); } + { return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); } + /// Return a const reference to the unique element of type _Tp of a tuple. template constexpr const _Tp& get(const tuple<_Types...>& __t) noexcept { return std::__get_helper2<_Tp>(__t); } #endif + // This class helps construct the various comparison operations on tuples template diff --git a/libstdc++-v3/testsuite/20_util/tuple/element_access/get_by_type.cc b/libstdc++-v3/testsuite/20_util/tuple/element_access/get_by_type.cc index 226e9e4..042f214 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/element_access/get_by_type.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/element_access/get_by_type.cc @@ -41,4 +41,8 @@ main() get<1>(b)=5; VERIFY(get(b)==1 && get(b)==5 && get(b)==2); VERIFY(j==5); + // test rvalue overload: + VERIFY(get(std::move(b))==1); + VERIFY(get(std::move(b))==5); + VERIFY(get(std::move(b))==2); }