From patchwork Mon Apr 14 23:18:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 339121 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 DFEF2140093 for ; Tue, 15 Apr 2014 09:18:36 +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:mime-version:content-type; q=dns; s= default; b=SJOAI/pvZzjuoSZ6KLdIcp7TyqjvwBi+KbP65z4F/tBvTHc2/Qdua rUDKojm3RcIzWaf5gnw1aR0uSXGv4bqrzE7g+hAu01f8txgZkHW/2JEPK+WxjzRg rKTc8Kvyo24hplUyXnQgZ1cYa0LxBrKstO8U5s0mV4HKMD4WIJYIGM= 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:mime-version:content-type; s= default; bh=mR7j3DmCdNEs1++MaC2kHw0+EpE=; b=T9cf0iGFGcKckEBGTTpN F5RYMbUUGgfue9nhTTgka9c+HPRROKqV6TUQgTMdU9V++NAfh05xGh4iYjseMRXK 7Nrj3V/LtXyoL2hYJJVHd1OMuj7r9NOSx+KF/7Jfak8cnhlSjzGpB6JTWrfSywiQ 1xFzqnrIJEu1T5bO/PSef6Y= Received: (qmail 18002 invoked by alias); 14 Apr 2014 23:18:27 -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 17963 invoked by uid 89); 14 Apr 2014 23:18:25 -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; Mon, 14 Apr 2014 23:18:22 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3ENILDp020492 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Apr 2014 19:18:21 -0400 Received: from localhost (vpn1-4-60.ams2.redhat.com [10.36.4.60]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3ENIKPT030334; Mon, 14 Apr 2014 19:18:21 -0400 Date: Tue, 15 Apr 2014 00:18:19 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] Implement N3887: std::tuple_element_t Message-ID: <20140414231819.GH6807@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) This adds the std::tuple_element_t alias template for C++14. Tested x86_64-linux, committed to trunk. commit 8aed2fc56f7bbd765e79f6c88e50c19e195e32ac Author: Jonathan Wakely Date: Mon Apr 14 16:36:00 2014 +0100 N3887 Consistent Metafunction Aliases * include/std/tuple (tuple_element_t): Define. * testsuite/20_util/tuple/tuple_element.cc: Change to compile-only test. * testsuite/20_util/tuple/tuple_element_t.cc: New. diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 47a10ec..03d87d7 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -710,6 +710,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION add_cv::type>::type type; }; +#if __cplusplus > 201103L + template + using tuple_element_t = typename tuple_element<__i, _Tp>::type; +#endif + /// Finds the size of a given tuple type. template struct tuple_size; diff --git a/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc b/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc index 0dbdf10..3ff8e82 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc @@ -1,4 +1,5 @@ -// { dg-options "-std=gnu++0x" } +// { dg-options "-std=gnu++11" } +// { dg-do compile } // Copyright (C) 2007-2014 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/20_util/tuple/tuple_element_t.cc b/libstdc++-v3/testsuite/20_util/tuple/tuple_element_t.cc new file mode 100644 index 0000000..e46af5c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/tuple_element_t.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2014 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 +// . + +#include + +using namespace std; + +struct foo +{ }; + +int +main() +{ + // As foo isn't constructible from anything else, this + // lets us check if the alias is returning foo when it should + foo q1; + tuple_element_t<0,tuple > q2(q1); + tuple_element_t<2,tuple > q3(q1); +}